git ssb

0+

dangerousbeans / %aPBe2k3ugtjBr4rrsU1…



Tree: a548e49bf23003f0da89137eecb2a2d0779da38a

Files: a548e49bf23003f0da89137eecb2a2d0779da38a / ext / bcrypt_ext.c

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

Built with git-ssb-web