Skip to content

Commit d2dceb8

Browse files
committed
Merge pull request #51 from pda/bcrypt_error
BCrypt::Errors::* descend from new BCrypt::Error.
2 parents 8f30bb8 + 007857a commit d2dceb8

2 files changed

Lines changed: 43 additions & 4 deletions

File tree

lib/bcrypt.rb

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,13 @@
1111
# A Ruby library implementing OpenBSD's bcrypt()/crypt_blowfish algorithm for
1212
# hashing passwords.
1313
module BCrypt
14+
15+
class Error < StandardError; end
1416
module Errors
15-
class InvalidSalt < StandardError; end # The salt parameter provided to bcrypt() is invalid.
16-
class InvalidHash < StandardError; end # The hash parameter provided to bcrypt() is invalid.
17-
class InvalidCost < StandardError; end # The cost parameter provided to bcrypt() is invalid.
18-
class InvalidSecret < StandardError; end # The secret parameter provided to bcrypt() is invalid.
17+
class InvalidSalt < BCrypt::Error; end # The salt parameter provided to bcrypt() is invalid.
18+
class InvalidHash < BCrypt::Error; end # The hash parameter provided to bcrypt() is invalid.
19+
class InvalidCost < BCrypt::Error; end # The cost parameter provided to bcrypt() is invalid.
20+
class InvalidSecret < BCrypt::Error; end # The secret parameter provided to bcrypt() is invalid.
1921
end
2022

2123
# A Ruby wrapper for the bcrypt() C extension calls and the Java calls.

spec/bcrypt/error_spec.rb

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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 commit comments

Comments
 (0)