Method: BCrypt::Engine.__bc_crypt
- Defined in:
- ext/mri/bcrypt_ext.c
.__bc_crypt(key, setting) ⇒ Object
Given a secret and a salt, generates a salted hash (which you can then store safely).
75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 |
# File 'ext/mri/bcrypt_ext.c', line 75
static VALUE bc_crypt(VALUE self, VALUE key, VALUE setting) {
char * value;
VALUE out;
struct bc_crypt_args args;
if(NIL_P(key) || NIL_P(setting)) return Qnil;
/* duplicate the parameters for thread safety. If another thread has a
* reference to the parameters and mutates them while we are working,
* that would be very bad. Duping the strings means that the reference
* isn't shared. */
key = rb_str_new_frozen(key);
setting = rb_str_new_frozen(setting);
args.data = NULL;
args.size = 0xDEADBEEF;
args.key = NIL_P(key) ? NULL : StringValueCStr(key);
args.setting = NIL_P(setting) ? NULL : StringValueCStr(setting);
#ifdef HAVE_RUBY_THREAD_H
value = rb_thread_call_without_gvl(bc_crypt_nogvl, &args, NULL, NULL);
#else
value = bc_crypt_nogvl((void *)&args);
#endif
if(!value || !args.data) return Qnil;
out = rb_str_new2(value);
RB_GC_GUARD(key);
RB_GC_GUARD(setting);
free(args.data);
return out;
}
|