Permalink
Browse files

correct issue with empty string error raising logic being reversed

  • Loading branch information...
1 parent 6e00a99 commit 85ba362af42d5d866263e547d115774c94aeef89 @Capncavedan Capncavedan committed Mar 21, 2013
Showing with 8 additions and 6 deletions.
  1. +4 −2 lib/crypt_keeper/provider/aes.rb
  2. +4 −4 spec/provider/aes_spec.rb
@@ -37,11 +37,12 @@ def initialize(options = {})
# Returns a string
def encrypt(value)
if encryptable?(value)
+ return '' if value == ''
aes.encrypt
aes.key = key
Base64::encode64("#{aes.random_iv}#{SEPARATOR}#{aes.update(value.to_s) + aes.final}")
else
- value
+ raise ArgumentError, "empty string not allowed in strict mode"
end
end
@@ -50,13 +51,14 @@ def encrypt(value)
# Returns a string
def decrypt(value)
if encryptable?(value)
+ return '' if value == ''
iv, value = Base64::decode64(value.to_s).split(SEPARATOR)
aes.decrypt
aes.key = key
aes.iv = iv
aes.update(value) + aes.final
else
- value
+ raise ArgumentError, "empty string not allowed in strict mode"
end
end
@@ -23,7 +23,7 @@ module Provider
specify { encrypted.should_not == 'string' }
specify { encrypted.should_not be_blank }
- specify { expect { subject.encrypt('') }.not_to raise_error(ArgumentError) }
+ specify { expect { subject.encrypt('') }.to raise_error(ArgumentError, "empty string not allowed in strict mode") }
end
describe "#decrypt" do
@@ -33,7 +33,7 @@ module Provider
specify { decrypted.should == 'string' }
- specify { expect { subject.decrypt('') }.not_to raise_error(TypeError) }
+ specify { expect { subject.decrypt('') }.to raise_error(ArgumentError, "empty string not allowed in strict mode") }
end
describe "#encryptable?" do
@@ -48,11 +48,11 @@ module Provider
its(:strict_mode) { should be_false }
describe "#encrypt" do
- specify { expect { subject.encrypt('') }.to raise_error(ArgumentError) }
+ specify { expect { subject.encrypt('') }.not_to raise_error(ArgumentError) }
end
describe "#decrypt" do
- specify { expect { subject.decrypt('') }.to raise_error(TypeError) }
+ specify { expect { subject.decrypt('') }.not_to raise_error(ArgumentError) }
end
describe "#encryptable?" do

0 comments on commit 85ba362

Please sign in to comment.