Files: ae87ba58f416c1874af79af3b07e26073441c010 / ext / mri / crypt.c
1064 bytesRaw
1 | |
2 | |
3 | |
4 | VALUE mCrypt; |
5 | |
6 | static VALUE crypt_salt(VALUE self, VALUE prefix, VALUE count, VALUE input) |
7 | { |
8 | char * salt; |
9 | VALUE str_salt; |
10 | |
11 | salt = crypt_gensalt_ra( |
12 | StringValuePtr(prefix), |
13 | NUM2ULONG(count), |
14 | NIL_P(input) ? NULL : StringValuePtr(input), |
15 | NIL_P(input) ? 0 : rb_str_strlen(input)); |
16 | |
17 | if(!salt) return Qnil; |
18 | |
19 | str_salt = rb_str_new2(salt); |
20 | free(salt); |
21 | |
22 | return str_salt; |
23 | } |
24 | |
25 | static VALUE ra(VALUE self, VALUE key, VALUE setting) |
26 | { |
27 | char * value; |
28 | void * data; |
29 | int size; |
30 | VALUE out; |
31 | |
32 | data = NULL; |
33 | size = 0xDEADBEEF; |
34 | |
35 | if(NIL_P(key) || NIL_P(setting)) return Qnil; |
36 | |
37 | value = crypt_ra( |
38 | NIL_P(key) ? NULL : StringValuePtr(key), |
39 | NIL_P(setting) ? NULL : StringValuePtr(setting), |
40 | &data, |
41 | &size); |
42 | |
43 | if(!value) return Qnil; |
44 | |
45 | out = rb_str_new(data, size - 1); |
46 | |
47 | free(data); |
48 | |
49 | return out; |
50 | } |
51 | |
52 | void Init_crypt() |
53 | { |
54 | mCrypt = rb_define_module("Crypt"); |
55 | rb_define_singleton_method(mCrypt, "salt", crypt_salt, 3); |
56 | rb_define_singleton_method(mCrypt, "crypt", ra, 2); |
57 | } |
58 |
Built with git-ssb-web