Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 6 additions & 4 deletions lib/bcrypt.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,13 @@
# A Ruby library implementing OpenBSD's bcrypt()/crypt_blowfish algorithm for
# hashing passwords.
module BCrypt

class Error < StandardError; end
module Errors
class InvalidSalt < StandardError; end # The salt parameter provided to bcrypt() is invalid.
class InvalidHash < StandardError; end # The hash parameter provided to bcrypt() is invalid.
class InvalidCost < StandardError; end # The cost parameter provided to bcrypt() is invalid.
class InvalidSecret < StandardError; end # The secret parameter provided to bcrypt() is invalid.
class InvalidSalt < BCrypt::Error; end # The salt parameter provided to bcrypt() is invalid.
class InvalidHash < BCrypt::Error; end # The hash parameter provided to bcrypt() is invalid.
class InvalidCost < BCrypt::Error; end # The cost parameter provided to bcrypt() is invalid.
class InvalidSecret < BCrypt::Error; end # The secret parameter provided to bcrypt() is invalid.
end

# A Ruby wrapper for the bcrypt() C extension calls and the Java calls.
Expand Down
37 changes: 37 additions & 0 deletions spec/bcrypt/error_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
require File.expand_path(File.join(File.dirname(__FILE__), "..", "spec_helper"))

describe "Errors" do

shared_examples "descends from StandardError" do
it "can be rescued as a StandardError" do
described_class.should < StandardError
end
end

shared_examples "descends from BCrypt::Error" do
it "can be rescued as a BCrypt::Error" do
described_class.should < BCrypt::Error
end
end

describe BCrypt::Error do
include_examples "descends from StandardError"
end

describe BCrypt::Errors::InvalidCost do
include_examples "descends from BCrypt::Error"
end

describe BCrypt::Errors::InvalidHash do
include_examples "descends from BCrypt::Error"
end

describe BCrypt::Errors::InvalidSalt do
include_examples "descends from BCrypt::Error"
end

describe BCrypt::Errors::InvalidSecret do
include_examples "descends from BCrypt::Error"
end

end