scrypt 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,62 @@
1
+ require File.expand_path(File.join(File.dirname(__FILE__), "..", "spec_helper"))
2
+
3
+ describe "Creating a hashed password" do
4
+ before :each do
5
+ @password = SCrypt::Password.create("s3cr3t", :max_time => 0.25)
6
+ end
7
+
8
+ it "should return a SCrypt::Password" do
9
+ @password.should be_an_instance_of(SCrypt::Password)
10
+ end
11
+
12
+ it "should return a valid bcrypt password" do
13
+ lambda { SCrypt::Password.new(@password) }.should_not raise_error
14
+ end
15
+
16
+ it "should behave normally if the secret is not a string" do
17
+ lambda { SCrypt::Password.create(nil) }.should_not raise_error(SCrypt::Errors::InvalidSecret)
18
+ lambda { SCrypt::Password.create({:woo => "yeah"}) }.should_not raise_error(SCrypt::Errors::InvalidSecret)
19
+ lambda { SCrypt::Password.create(false) }.should_not raise_error(SCrypt::Errors::InvalidSecret)
20
+ end
21
+
22
+ it "should tolerate empty string secrets" do
23
+ lambda { SCrypt::Password.create( "\n".chop ) }.should_not raise_error
24
+ lambda { SCrypt::Password.create( "" ) }.should_not raise_error
25
+ lambda { SCrypt::Password.create( String.new ) }.should_not raise_error
26
+ end
27
+ end
28
+
29
+
30
+ describe "Reading a hashed password" do
31
+ before :each do
32
+ @secret = "my secret"
33
+ @hash = "400$8$d$173a8189751c095a29b933789560b73bf17b2e01$9bf66d74bd6f3ebcf99da3b379b689b89db1cb07"
34
+ end
35
+
36
+ it "should read the cost, salt, and hash" do
37
+ password = SCrypt::Password.new(@hash)
38
+ password.cost.should == "400$8$d$"
39
+ password.salt.should == "173a8189751c095a29b933789560b73bf17b2e01"
40
+ password.to_s.should == @hash
41
+ end
42
+
43
+ it "should raise an InvalidHashError when given an invalid hash" do
44
+ lambda { SCrypt::Password.new('not a valid hash') }.should raise_error(SCrypt::Errors::InvalidHash)
45
+ end
46
+ end
47
+
48
+
49
+ describe "Comparing a hashed password with a secret" do
50
+ before :each do
51
+ @secret = "s3cr3t"
52
+ @password = SCrypt::Password.create(@secret)
53
+ end
54
+
55
+ it "should compare successfully to the original secret" do
56
+ (@password == @secret).should be(true)
57
+ end
58
+
59
+ it "should compare unsuccessfully to anything besides original secret" do
60
+ (@password == "@secret").should be(false)
61
+ end
62
+ end
@@ -0,0 +1,4 @@
1
+ $LOAD_PATH.unshift(File.expand_path(File.dirname(__FILE__) + '/../lib'))
2
+ require "rubygems"
3
+ require "rspec"
4
+ require "scrypt"
metadata ADDED
@@ -0,0 +1,101 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: scrypt
3
+ version: !ruby/object:Gem::Version
4
+ hash: 23
5
+ prerelease: false
6
+ segments:
7
+ - 1
8
+ - 0
9
+ - 0
10
+ version: 1.0.0
11
+ platform: ruby
12
+ authors:
13
+ - Patrick Hogan
14
+ autorequire:
15
+ bindir: bin
16
+ cert_chain: []
17
+
18
+ date: 2010-12-16 00:00:00 -06:00
19
+ default_executable:
20
+ dependencies: []
21
+
22
+ description: " The scrypt key derivation function is designed to be far \n more secure against hardware brute-force attacks than \n alternative functions such as PBKDF2 or bcrypt.\n"
23
+ email:
24
+ - pbhogan@gmail.com
25
+ executables: []
26
+
27
+ extensions:
28
+ - ext/mri/extconf.rb
29
+ extra_rdoc_files: []
30
+
31
+ files:
32
+ - .gitignore
33
+ - .rspec
34
+ - CHANGELOG
35
+ - COPYING
36
+ - Gemfile
37
+ - Gemfile.lock
38
+ - README
39
+ - Rakefile
40
+ - Rakefile.old
41
+ - autotest/discover.rb
42
+ - ext/mri/Makefile
43
+ - ext/mri/crypto_scrypt-ref.c
44
+ - ext/mri/crypto_scrypt.h
45
+ - ext/mri/extconf.rb
46
+ - ext/mri/memlimit.c
47
+ - ext/mri/memlimit.h
48
+ - ext/mri/scrypt_calibrate.c
49
+ - ext/mri/scrypt_calibrate.h
50
+ - ext/mri/scrypt_ext.bundle
51
+ - ext/mri/scrypt_ext.c
52
+ - ext/mri/scrypt_platform.h
53
+ - ext/mri/scryptenc_cpuperf.c
54
+ - ext/mri/scryptenc_cpuperf.h
55
+ - ext/mri/sha256.c
56
+ - ext/mri/sha256.h
57
+ - ext/mri/sysendian.h
58
+ - lib/scrypt.rb
59
+ - lib/scrypt/version.rb
60
+ - scrypt.gemspec
61
+ - spec/scrypt/engine_spec.rb
62
+ - spec/scrypt/password_spec.rb
63
+ - spec/spec_helper.rb
64
+ has_rdoc: true
65
+ homepage: ""
66
+ licenses: []
67
+
68
+ post_install_message:
69
+ rdoc_options: []
70
+
71
+ require_paths:
72
+ - lib
73
+ required_ruby_version: !ruby/object:Gem::Requirement
74
+ none: false
75
+ requirements:
76
+ - - ">="
77
+ - !ruby/object:Gem::Version
78
+ hash: 3
79
+ segments:
80
+ - 0
81
+ version: "0"
82
+ required_rubygems_version: !ruby/object:Gem::Requirement
83
+ none: false
84
+ requirements:
85
+ - - ">="
86
+ - !ruby/object:Gem::Version
87
+ hash: 3
88
+ segments:
89
+ - 0
90
+ version: "0"
91
+ requirements: []
92
+
93
+ rubyforge_project: scrypt
94
+ rubygems_version: 1.3.7
95
+ signing_key:
96
+ specification_version: 3
97
+ summary: scrypt password hashing algorithm.
98
+ test_files:
99
+ - spec/scrypt/engine_spec.rb
100
+ - spec/scrypt/password_spec.rb
101
+ - spec/spec_helper.rb