Permalink
Browse files

raise an exception if the cost is greater than 31. fixes #27

  • Loading branch information...
1 parent 045a495 commit 8445c8f85076cf66f2507962a35e0f5af49ab4a9 @tenderlove tenderlove committed Sep 12, 2011
Showing with 11 additions and 1 deletion.
  1. +3 −0 CHANGELOG
  2. +1 −1 Gemfile.lock
  3. +1 −0 lib/bcrypt.rb
  4. +6 −0 spec/bcrypt/password_spec.rb
View
@@ -42,3 +42,6 @@
3.0.0 Aug 24, 2011
- Bcrypt C implementation replaced with a public domain implementation.
- License changed to MIT
+
+3.0.1
+ - create raises an exception if the cost is higher than 31. GH #27
View
@@ -1,7 +1,7 @@
PATH
remote: .
specs:
- bcrypt-ruby (2.1.4)
+ bcrypt-ruby (3.0.0)
GEM
remote: http://rubygems.org/
View
@@ -157,6 +157,7 @@ class << self
#
# @password = BCrypt::Password.create("my secret", :cost => 13)
def create(secret, options = { :cost => BCrypt::Engine::DEFAULT_COST })
+ raise ArgumentError if options[:cost] > 31
Password.new(BCrypt::Engine.hash_secret(secret, BCrypt::Engine.generate_salt(options[:cost]), options[:cost]))
end
end
@@ -34,6 +34,12 @@
@hash = "$2a$05$CCCCCCCCCCCCCCCCCCCCC.E5YPO9kmyuRGyh0XouQYb4YMJKvyOeW"
end
+ specify "the cost is too damn high" do
+ lambda {
+ BCrypt::Password.create("hello", :cost => 32)
+ }.should raise_error(ArgumentError)
+ end
+
specify "should read the version, cost, salt, and hash" do
password = BCrypt::Password.new(@hash)
password.version.should eql("2a")

0 comments on commit 8445c8f

Please sign in to comment.