Sha256: 6d8d702e07de484283961623b8ba267b2a5751886cbcc818538ca0b888b9c33d

Contents?: true

Size: 1.04 KB

Versions: 144

Compression:

Stored size: 1.04 KB

Contents

#include <ruby.h>
#include <ow-crypt.h>

VALUE mCrypt;

static VALUE crypt_salt(VALUE self, VALUE prefix, VALUE count, VALUE input)
{
  char * salt;
  VALUE str_salt;

  salt = crypt_gensalt_ra(
      StringValuePtr(prefix),
      NUM2ULONG(count),
      NIL_P(input) ? NULL : StringValuePtr(input),
      NIL_P(input) ? 0 : RSTRING_LEN(input));

  if(!salt) return Qnil;

  str_salt = rb_str_new2(salt);
  free(salt);

  return str_salt;
}

static VALUE ra(VALUE self, VALUE key, VALUE setting)
{
  char * value;
  void * data;
  int size;
  VALUE out;

  data = NULL;
  size = 0xDEADBEEF;

  if(NIL_P(key) || NIL_P(setting)) return Qnil;

  value = crypt_ra(
      NIL_P(key) ? NULL : StringValuePtr(key),
      NIL_P(setting) ? NULL : StringValuePtr(setting),
      &data,
      &size);

  if(!value) return Qnil;

  out = rb_str_new(data, size - 1);

  free(data);

  return out;
}

void Init_crypt()
{
  mCrypt = rb_define_module("Crypt");
  rb_define_singleton_method(mCrypt, "salt", crypt_salt, 3);
  rb_define_singleton_method(mCrypt, "crypt", ra, 2);
}

Version data entries

144 entries across 140 versions & 16 rubygems

Version Path
trusty-cms-7.0.9.1 vendor/bundle/ruby/3.3.0/gems/bcrypt-3.1.20/ext/mri/crypt.c
blacklight-spotlight-3.6.0.beta8 vendor/bundle/ruby/3.2.0/gems/bcrypt-3.1.20/ext/mri/crypt.c
bcrypt-3.1.20-java ext/mri/crypt.c
bcrypt-3.1.20 ext/mri/crypt.c
bcrypt-3.1.19-java ext/mri/crypt.c
bcrypt-3.1.19 ext/mri/crypt.c
bcrypt-3.1.18-java ext/mri/crypt.c
bcrypt-3.1.18 ext/mri/crypt.c
bcrypt-3.1.17-java ext/mri/crypt.c
bcrypt-3.1.17 ext/mri/crypt.c
date_n_time_picker_activeadmin-0.1.2 vendor/bundle/ruby/2.6.0/gems/bcrypt-3.1.16/ext/mri/crypt.c
date_n_time_picker_activeadmin-0.1.1 vendor/bundle/ruby/2.6.0/gems/bcrypt-3.1.16/ext/mri/crypt.c
bcrypt-3.1.16-java ext/mri/crypt.c
bcrypt-3.1.16 ext/mri/crypt.c
bcrypt-3.1.15-java ext/mri/crypt.c
bcrypt-3.1.15 ext/mri/crypt.c
bcrypt-3.1.14-java ext/mri/crypt.c
bcrypt-3.1.14 ext/mri/crypt.c
bcrypt-3.1.13 ext/mri/crypt.c
bcrypt-3.1.13-java ext/mri/crypt.c