Files: e61acd33cc691daece9560ddd9e2367cfc31fab9 / ext / bcrypt_ext.c
974 bytesRaw
1 | |
2 | |
3 | char *bcrypt_gensalt(u_int8_t, u_int8_t *); |
4 | char *bcrypt(const char *, const char *); |
5 | |
6 | VALUE mBCrypt; |
7 | VALUE mBCryptInternals; |
8 | |
9 | /* Given a logarithmic cost parameter, generates a salt for use with +bc_crypt+. |
10 | */ |
11 | static VALUE bc_salt(VALUE self, VALUE cost, VALUE seed) { |
12 | return rb_str_new2((char *)bcrypt_gensalt(NUM2INT(cost), (u_int8_t *)RSTRING(seed)->ptr)); |
13 | } |
14 | |
15 | /* Given a secret and a salt, generates a salted hash (which you can then store safely). |
16 | */ |
17 | static VALUE bc_crypt(VALUE self, VALUE key, VALUE salt) { |
18 | return rb_str_new2((char *)bcrypt(RSTRING(key)->ptr, (char *)RSTRING(salt)->ptr)); |
19 | } |
20 | |
21 | /* Create the BCrypt and BCrypt::Internals modules, and populate them with methods. */ |
22 | void Init_bcrypt_ext(){ |
23 | mBCrypt = rb_define_module("BCrypt"); |
24 | mBCryptInternals = rb_define_module_under(mBCrypt, "Internals"); |
25 | |
26 | rb_define_method(mBCryptInternals, "__bc_salt", bc_salt, 2); |
27 | rb_define_method(mBCryptInternals, "__bc_crypt", bc_crypt, 2); |
28 | } |
29 |
Built with git-ssb-web