Module: Crypt

Defined in:
ext/mri/crypt.c

Class Method Summary (collapse)

Class Method Details

+ (Object) crypt



25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
# File 'ext/mri/crypt.c', line 25

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;
}

+ (Object) salt



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'ext/mri/crypt.c', line 6

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;
}