lookout-bcrypt 3.2.0-java
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/.gitignore +9 -0
- data/.rspec +3 -0
- data/.travis.yml +14 -0
- data/CHANGELOG +81 -0
- data/COPYING +28 -0
- data/Gemfile +2 -0
- data/Gemfile.lock +40 -0
- data/README.md +203 -0
- data/Rakefile +93 -0
- data/bcrypt.gemspec +29 -0
- data/ext/jruby/bcrypt_jruby/BCrypt.java +782 -0
- data/ext/mri/bcrypt_ext.c +64 -0
- data/ext/mri/crypt.c +57 -0
- data/ext/mri/crypt.h +13 -0
- data/ext/mri/crypt_blowfish.c +786 -0
- data/ext/mri/crypt_gensalt.c +111 -0
- data/ext/mri/extconf.rb +16 -0
- data/ext/mri/ow-crypt.h +35 -0
- data/ext/mri/wrapper.c +262 -0
- data/lib/bcrypt/engine.rb +123 -0
- data/lib/bcrypt/error.rb +22 -0
- data/lib/bcrypt/password.rb +87 -0
- data/lib/bcrypt.rb +21 -0
- data/lib/bcrypt_ext.jar +0 -0
- data/spec/TestBCrypt.java +347 -0
- data/spec/bcrypt/engine_spec.rb +108 -0
- data/spec/bcrypt/error_spec.rb +37 -0
- data/spec/bcrypt/password_spec.rb +123 -0
- data/spec/spec_helper.rb +2 -0
- metadata +131 -0
@@ -0,0 +1,64 @@
|
|
1
|
+
#include <ruby.h>
|
2
|
+
#include <ow-crypt.h>
|
3
|
+
|
4
|
+
static VALUE mBCrypt;
|
5
|
+
static VALUE cBCryptEngine;
|
6
|
+
|
7
|
+
/* Given a logarithmic cost parameter, generates a salt for use with +bc_crypt+.
|
8
|
+
*/
|
9
|
+
static VALUE bc_salt(VALUE self, VALUE prefix, VALUE count, VALUE input) {
|
10
|
+
char * salt;
|
11
|
+
VALUE str_salt;
|
12
|
+
|
13
|
+
salt = crypt_gensalt_ra(
|
14
|
+
StringValuePtr(prefix),
|
15
|
+
NUM2ULONG(count),
|
16
|
+
NIL_P(input) ? NULL : StringValuePtr(input),
|
17
|
+
NIL_P(input) ? 0 : RSTRING_LEN(input));
|
18
|
+
|
19
|
+
if(!salt) return Qnil;
|
20
|
+
|
21
|
+
str_salt = rb_str_new2(salt);
|
22
|
+
xfree(salt);
|
23
|
+
|
24
|
+
return str_salt;
|
25
|
+
}
|
26
|
+
|
27
|
+
/* Given a secret and a salt, generates a salted hash (which you can then store safely).
|
28
|
+
*/
|
29
|
+
static VALUE bc_crypt(VALUE self, VALUE key, VALUE setting) {
|
30
|
+
char * value;
|
31
|
+
void * data;
|
32
|
+
int size;
|
33
|
+
VALUE out;
|
34
|
+
|
35
|
+
data = NULL;
|
36
|
+
size = 0xDEADBEEF;
|
37
|
+
|
38
|
+
if(NIL_P(key) || NIL_P(setting)) return Qnil;
|
39
|
+
|
40
|
+
value = crypt_ra(
|
41
|
+
NIL_P(key) ? NULL : StringValuePtr(key),
|
42
|
+
NIL_P(setting) ? NULL : StringValuePtr(setting),
|
43
|
+
&data,
|
44
|
+
&size);
|
45
|
+
|
46
|
+
if(!value) return Qnil;
|
47
|
+
|
48
|
+
out = rb_str_new(data, size - 1);
|
49
|
+
|
50
|
+
xfree(data);
|
51
|
+
|
52
|
+
return out;
|
53
|
+
}
|
54
|
+
|
55
|
+
/* Create the BCrypt and BCrypt::Engine modules, and populate them with methods. */
|
56
|
+
void Init_bcrypt_ext(){
|
57
|
+
mBCrypt = rb_define_module("BCrypt");
|
58
|
+
cBCryptEngine = rb_define_class_under(mBCrypt, "Engine", rb_cObject);
|
59
|
+
|
60
|
+
rb_define_singleton_method(cBCryptEngine, "__bc_salt", bc_salt, 3);
|
61
|
+
rb_define_singleton_method(cBCryptEngine, "__bc_crypt", bc_crypt, 2);
|
62
|
+
}
|
63
|
+
|
64
|
+
/* vim: set noet sws=4 sw=4: */
|
data/ext/mri/crypt.c
ADDED
@@ -0,0 +1,57 @@
|
|
1
|
+
#include <ruby.h>
|
2
|
+
#include <ow-crypt.h>
|
3
|
+
|
4
|
+
VALUE mCrypt;
|
5
|
+
|
6
|
+
static VALUE crypt_salt(VALUE self, VALUE prefix, VALUE count, VALUE input)
|
7
|
+
{
|
8
|
+
char * salt;
|
9
|
+
VALUE str_salt;
|
10
|
+
|
11
|
+
salt = crypt_gensalt_ra(
|
12
|
+
StringValuePtr(prefix),
|
13
|
+
NUM2ULONG(count),
|
14
|
+
NIL_P(input) ? NULL : StringValuePtr(input),
|
15
|
+
NIL_P(input) ? 0 : RSTRING_LEN(input));
|
16
|
+
|
17
|
+
if(!salt) return Qnil;
|
18
|
+
|
19
|
+
str_salt = rb_str_new2(salt);
|
20
|
+
free(salt);
|
21
|
+
|
22
|
+
return str_salt;
|
23
|
+
}
|
24
|
+
|
25
|
+
static VALUE ra(VALUE self, VALUE key, VALUE setting)
|
26
|
+
{
|
27
|
+
char * value;
|
28
|
+
void * data;
|
29
|
+
int size;
|
30
|
+
VALUE out;
|
31
|
+
|
32
|
+
data = NULL;
|
33
|
+
size = 0xDEADBEEF;
|
34
|
+
|
35
|
+
if(NIL_P(key) || NIL_P(setting)) return Qnil;
|
36
|
+
|
37
|
+
value = crypt_ra(
|
38
|
+
NIL_P(key) ? NULL : StringValuePtr(key),
|
39
|
+
NIL_P(setting) ? NULL : StringValuePtr(setting),
|
40
|
+
&data,
|
41
|
+
&size);
|
42
|
+
|
43
|
+
if(!value) return Qnil;
|
44
|
+
|
45
|
+
out = rb_str_new(data, size - 1);
|
46
|
+
|
47
|
+
free(data);
|
48
|
+
|
49
|
+
return out;
|
50
|
+
}
|
51
|
+
|
52
|
+
void Init_crypt()
|
53
|
+
{
|
54
|
+
mCrypt = rb_define_module("Crypt");
|
55
|
+
rb_define_singleton_method(mCrypt, "salt", crypt_salt, 3);
|
56
|
+
rb_define_singleton_method(mCrypt, "crypt", ra, 2);
|
57
|
+
}
|
data/ext/mri/crypt.h
ADDED
@@ -0,0 +1,13 @@
|
|
1
|
+
/*
|
2
|
+
* Written by Solar Designer and placed in the public domain.
|
3
|
+
* See crypt_blowfish.c for more information.
|
4
|
+
*/
|
5
|
+
|
6
|
+
#include <gnu-crypt.h>
|
7
|
+
|
8
|
+
#if defined(_OW_SOURCE) || defined(__USE_OW)
|
9
|
+
#define __SKIP_GNU
|
10
|
+
#undef __SKIP_OW
|
11
|
+
#include <ow-crypt.h>
|
12
|
+
#undef __SKIP_GNU
|
13
|
+
#endif
|