bcrypt-ruby 3.1.2.rc1-x64-mingw32
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +10 -0
- data/.rspec +3 -0
- data/.travis.yml +11 -0
- data/CHANGELOG +59 -0
- data/COPYING +28 -0
- data/Gemfile +2 -0
- data/Gemfile.lock +35 -0
- data/README.md +204 -0
- data/Rakefile +74 -0
- data/bcrypt-ruby.gemspec +30 -0
- data/ext/jruby/bcrypt_jruby/BCrypt.java +752 -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 +17 -0
- data/ext/mri/ow-crypt.h +35 -0
- data/ext/mri/wrapper.c +262 -0
- data/lib/bcrypt.rb +21 -0
- data/lib/bcrypt/engine.rb +120 -0
- data/lib/bcrypt/error.rb +22 -0
- data/lib/bcrypt/password.rb +87 -0
- data/spec/TestBCrypt.java +194 -0
- data/spec/bcrypt/engine_spec.rb +82 -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 +151 -0
@@ -0,0 +1,37 @@
|
|
1
|
+
require File.expand_path(File.join(File.dirname(__FILE__), "..", "spec_helper"))
|
2
|
+
|
3
|
+
describe "Errors" do
|
4
|
+
|
5
|
+
shared_examples "descends from StandardError" do
|
6
|
+
it "can be rescued as a StandardError" do
|
7
|
+
described_class.should < StandardError
|
8
|
+
end
|
9
|
+
end
|
10
|
+
|
11
|
+
shared_examples "descends from BCrypt::Error" do
|
12
|
+
it "can be rescued as a BCrypt::Error" do
|
13
|
+
described_class.should < BCrypt::Error
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
describe BCrypt::Error do
|
18
|
+
include_examples "descends from StandardError"
|
19
|
+
end
|
20
|
+
|
21
|
+
describe BCrypt::Errors::InvalidCost do
|
22
|
+
include_examples "descends from BCrypt::Error"
|
23
|
+
end
|
24
|
+
|
25
|
+
describe BCrypt::Errors::InvalidHash do
|
26
|
+
include_examples "descends from BCrypt::Error"
|
27
|
+
end
|
28
|
+
|
29
|
+
describe BCrypt::Errors::InvalidSalt do
|
30
|
+
include_examples "descends from BCrypt::Error"
|
31
|
+
end
|
32
|
+
|
33
|
+
describe BCrypt::Errors::InvalidSecret do
|
34
|
+
include_examples "descends from BCrypt::Error"
|
35
|
+
end
|
36
|
+
|
37
|
+
end
|
@@ -0,0 +1,123 @@
|
|
1
|
+
require File.expand_path(File.join(File.dirname(__FILE__), "..", "spec_helper"))
|
2
|
+
|
3
|
+
describe "Creating a hashed password" do
|
4
|
+
|
5
|
+
before :each do
|
6
|
+
@secret = "wheedle"
|
7
|
+
@password = BCrypt::Password.create(@secret, :cost => 4)
|
8
|
+
end
|
9
|
+
|
10
|
+
specify "should return a BCrypt::Password" do
|
11
|
+
@password.should be_an_instance_of(BCrypt::Password)
|
12
|
+
end
|
13
|
+
|
14
|
+
specify "should return a valid bcrypt password" do
|
15
|
+
lambda { BCrypt::Password.new(@password) }.should_not raise_error
|
16
|
+
end
|
17
|
+
|
18
|
+
specify "should behave normally if the secret is not a string" do
|
19
|
+
lambda { BCrypt::Password.create(nil) }.should_not raise_error(BCrypt::Errors::InvalidSecret)
|
20
|
+
lambda { BCrypt::Password.create({:woo => "yeah"}) }.should_not raise_error(BCrypt::Errors::InvalidSecret)
|
21
|
+
lambda { BCrypt::Password.create(false) }.should_not raise_error(BCrypt::Errors::InvalidSecret)
|
22
|
+
end
|
23
|
+
|
24
|
+
specify "should tolerate empty string secrets" do
|
25
|
+
lambda { BCrypt::Password.create( "\n".chop ) }.should_not raise_error
|
26
|
+
lambda { BCrypt::Password.create( "" ) }.should_not raise_error
|
27
|
+
lambda { BCrypt::Password.create( String.new ) }.should_not raise_error
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
describe "Reading a hashed password" do
|
32
|
+
before :each do
|
33
|
+
@secret = "U*U"
|
34
|
+
@hash = "$2a$05$CCCCCCCCCCCCCCCCCCCCC.E5YPO9kmyuRGyh0XouQYb4YMJKvyOeW"
|
35
|
+
end
|
36
|
+
|
37
|
+
specify "the cost is too damn high" do
|
38
|
+
lambda {
|
39
|
+
BCrypt::Password.create("hello", :cost => 32)
|
40
|
+
}.should raise_error(ArgumentError)
|
41
|
+
end
|
42
|
+
|
43
|
+
specify "the cost should be set to the default if nil" do
|
44
|
+
BCrypt::Password.create("hello", :cost => nil).cost.should equal(BCrypt::Engine::DEFAULT_COST)
|
45
|
+
end
|
46
|
+
|
47
|
+
specify "the cost should be set to the default if empty hash" do
|
48
|
+
BCrypt::Password.create("hello", {}).cost.should equal(BCrypt::Engine::DEFAULT_COST)
|
49
|
+
end
|
50
|
+
|
51
|
+
specify "the cost should be set to the passed value if provided" do
|
52
|
+
BCrypt::Password.create("hello", :cost => 5).cost.should equal(5)
|
53
|
+
end
|
54
|
+
|
55
|
+
specify "the cost should be set to the global value if set" do
|
56
|
+
BCrypt::Engine.cost = 5
|
57
|
+
BCrypt::Password.create("hello").cost.should equal(5)
|
58
|
+
# unset the global value to not affect other tests
|
59
|
+
BCrypt::Engine.cost = nil
|
60
|
+
end
|
61
|
+
|
62
|
+
specify "the cost should be set to an overridden constant for backwards compatibility" do
|
63
|
+
# suppress "already initialized constant" warning
|
64
|
+
old_verbose, $VERBOSE = $VERBOSE, nil
|
65
|
+
old_default_cost = BCrypt::Engine::DEFAULT_COST
|
66
|
+
|
67
|
+
BCrypt::Engine::DEFAULT_COST = 5
|
68
|
+
BCrypt::Password.create("hello").cost.should equal(5)
|
69
|
+
|
70
|
+
# reset default to not affect other tests
|
71
|
+
BCrypt::Engine::DEFAULT_COST = old_default_cost
|
72
|
+
$VERBOSE = old_verbose
|
73
|
+
end
|
74
|
+
|
75
|
+
specify "should read the version, cost, salt, and hash" do
|
76
|
+
password = BCrypt::Password.new(@hash)
|
77
|
+
password.version.should eql("2a")
|
78
|
+
password.cost.should equal(5)
|
79
|
+
password.salt.should eql("$2a$05$CCCCCCCCCCCCCCCCCCCCC.")
|
80
|
+
password.salt.class.should eq String
|
81
|
+
password.checksum.should eq("E5YPO9kmyuRGyh0XouQYb4YMJKvyOeW")
|
82
|
+
password.checksum.class.should eq String
|
83
|
+
password.to_s.should eql(@hash)
|
84
|
+
end
|
85
|
+
|
86
|
+
specify "should raise an InvalidHashError when given an invalid hash" do
|
87
|
+
lambda { BCrypt::Password.new('weedle') }.should raise_error(BCrypt::Errors::InvalidHash)
|
88
|
+
end
|
89
|
+
end
|
90
|
+
|
91
|
+
describe "Comparing a hashed password with a secret" do
|
92
|
+
before :each do
|
93
|
+
@secret = "U*U"
|
94
|
+
@hash = "$2a$05$CCCCCCCCCCCCCCCCCCCCC.E5YPO9kmyuRGyh0XouQYb4YMJKvyOeW"
|
95
|
+
@password = BCrypt::Password.create(@secret)
|
96
|
+
end
|
97
|
+
|
98
|
+
specify "should compare successfully to the original secret" do
|
99
|
+
(@password == @secret).should be(true)
|
100
|
+
end
|
101
|
+
|
102
|
+
specify "should compare unsuccessfully to anything besides original secret" do
|
103
|
+
(@password == "@secret").should be(false)
|
104
|
+
end
|
105
|
+
end
|
106
|
+
|
107
|
+
describe "Validating a generated salt" do
|
108
|
+
specify "should not accept an invalid salt" do
|
109
|
+
BCrypt::Engine.valid_salt?("invalid").should eq(false)
|
110
|
+
end
|
111
|
+
specify "should accept a valid salt" do
|
112
|
+
BCrypt::Engine.valid_salt?(BCrypt::Engine.generate_salt).should eq(true)
|
113
|
+
end
|
114
|
+
end
|
115
|
+
|
116
|
+
describe "Validating a password hash" do
|
117
|
+
specify "should not accept an invalid password" do
|
118
|
+
BCrypt::Password.valid_hash?("i_am_so_not_valid").should be_false
|
119
|
+
end
|
120
|
+
specify "should accept a valid password" do
|
121
|
+
BCrypt::Password.valid_hash?(BCrypt::Password.create "i_am_so_valid").should be_true
|
122
|
+
end
|
123
|
+
end
|
data/spec/spec_helper.rb
ADDED
metadata
ADDED
@@ -0,0 +1,151 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: bcrypt-ruby
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
hash: 2560206937
|
5
|
+
prerelease: 6
|
6
|
+
segments:
|
7
|
+
- 3
|
8
|
+
- 1
|
9
|
+
- 2
|
10
|
+
- rc
|
11
|
+
- 1
|
12
|
+
version: 3.1.2.rc1
|
13
|
+
platform: x64-mingw32
|
14
|
+
authors:
|
15
|
+
- Coda Hale
|
16
|
+
autorequire:
|
17
|
+
bindir: bin
|
18
|
+
cert_chain: []
|
19
|
+
|
20
|
+
date: 2013-08-23 00:00:00 Z
|
21
|
+
dependencies:
|
22
|
+
- !ruby/object:Gem::Dependency
|
23
|
+
version_requirements: &id001 !ruby/object:Gem::Requirement
|
24
|
+
none: false
|
25
|
+
requirements:
|
26
|
+
- - ~>
|
27
|
+
- !ruby/object:Gem::Version
|
28
|
+
hash: 59
|
29
|
+
segments:
|
30
|
+
- 0
|
31
|
+
- 9
|
32
|
+
- 0
|
33
|
+
version: 0.9.0
|
34
|
+
name: rake-compiler
|
35
|
+
prerelease: false
|
36
|
+
type: :development
|
37
|
+
requirement: *id001
|
38
|
+
- !ruby/object:Gem::Dependency
|
39
|
+
version_requirements: &id002 !ruby/object:Gem::Requirement
|
40
|
+
none: false
|
41
|
+
requirements:
|
42
|
+
- - ">="
|
43
|
+
- !ruby/object:Gem::Version
|
44
|
+
hash: 3
|
45
|
+
segments:
|
46
|
+
- 0
|
47
|
+
version: "0"
|
48
|
+
name: rspec
|
49
|
+
prerelease: false
|
50
|
+
type: :development
|
51
|
+
requirement: *id002
|
52
|
+
- !ruby/object:Gem::Dependency
|
53
|
+
version_requirements: &id003 !ruby/object:Gem::Requirement
|
54
|
+
none: false
|
55
|
+
requirements:
|
56
|
+
- - ">="
|
57
|
+
- !ruby/object:Gem::Version
|
58
|
+
hash: 3
|
59
|
+
segments:
|
60
|
+
- 0
|
61
|
+
version: "0"
|
62
|
+
name: rdoc
|
63
|
+
prerelease: false
|
64
|
+
type: :development
|
65
|
+
requirement: *id003
|
66
|
+
description: " bcrypt() is a sophisticated and secure hash algorithm designed by The OpenBSD project\n for hashing passwords. bcrypt-ruby provides a simple, humane wrapper for safely handling\n passwords.\n"
|
67
|
+
email: coda.hale@gmail.com
|
68
|
+
executables: []
|
69
|
+
|
70
|
+
extensions: []
|
71
|
+
|
72
|
+
extra_rdoc_files:
|
73
|
+
- README.md
|
74
|
+
- COPYING
|
75
|
+
- CHANGELOG
|
76
|
+
- lib/bcrypt/engine.rb
|
77
|
+
- lib/bcrypt/error.rb
|
78
|
+
- lib/bcrypt/password.rb
|
79
|
+
- lib/bcrypt.rb
|
80
|
+
files:
|
81
|
+
- .gitignore
|
82
|
+
- .rspec
|
83
|
+
- .travis.yml
|
84
|
+
- CHANGELOG
|
85
|
+
- COPYING
|
86
|
+
- Gemfile
|
87
|
+
- Gemfile.lock
|
88
|
+
- README.md
|
89
|
+
- Rakefile
|
90
|
+
- bcrypt-ruby.gemspec
|
91
|
+
- ext/jruby/bcrypt_jruby/BCrypt.java
|
92
|
+
- ext/mri/bcrypt_ext.c
|
93
|
+
- ext/mri/crypt.c
|
94
|
+
- ext/mri/crypt.h
|
95
|
+
- ext/mri/crypt_blowfish.c
|
96
|
+
- ext/mri/crypt_gensalt.c
|
97
|
+
- ext/mri/extconf.rb
|
98
|
+
- ext/mri/ow-crypt.h
|
99
|
+
- ext/mri/wrapper.c
|
100
|
+
- lib/bcrypt.rb
|
101
|
+
- lib/bcrypt/engine.rb
|
102
|
+
- lib/bcrypt/error.rb
|
103
|
+
- lib/bcrypt/password.rb
|
104
|
+
- spec/TestBCrypt.java
|
105
|
+
- spec/bcrypt/engine_spec.rb
|
106
|
+
- spec/bcrypt/error_spec.rb
|
107
|
+
- spec/bcrypt/password_spec.rb
|
108
|
+
- spec/spec_helper.rb
|
109
|
+
- lib/2.0/bcrypt_ext.so
|
110
|
+
homepage: http://bcrypt-ruby.rubyforge.org
|
111
|
+
licenses:
|
112
|
+
- MIT
|
113
|
+
post_install_message:
|
114
|
+
rdoc_options:
|
115
|
+
- --title
|
116
|
+
- bcrypt-ruby
|
117
|
+
- --line-numbers
|
118
|
+
- --inline-source
|
119
|
+
- --main
|
120
|
+
- README.md
|
121
|
+
require_paths:
|
122
|
+
- lib
|
123
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
124
|
+
none: false
|
125
|
+
requirements:
|
126
|
+
- - ">="
|
127
|
+
- !ruby/object:Gem::Version
|
128
|
+
hash: 3
|
129
|
+
segments:
|
130
|
+
- 0
|
131
|
+
version: "0"
|
132
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
133
|
+
none: false
|
134
|
+
requirements:
|
135
|
+
- - ">"
|
136
|
+
- !ruby/object:Gem::Version
|
137
|
+
hash: 25
|
138
|
+
segments:
|
139
|
+
- 1
|
140
|
+
- 3
|
141
|
+
- 1
|
142
|
+
version: 1.3.1
|
143
|
+
requirements: []
|
144
|
+
|
145
|
+
rubyforge_project: bcrypt-ruby
|
146
|
+
rubygems_version: 1.8.25
|
147
|
+
signing_key:
|
148
|
+
specification_version: 3
|
149
|
+
summary: OpenBSD's bcrypt() password hashing algorithm.
|
150
|
+
test_files: []
|
151
|
+
|