Permalink
Browse files

Do not attempt to encrypt or decrypt nil

  • Loading branch information...
1 parent 901831d commit ffd0dab480a377d829b91441e59cec4d8f47f653 @jmazzi committed Aug 30, 2012
@@ -1,7 +1,7 @@
PATH
remote: /home/justin/work/ruby/crypt_keeper_providers
specs:
- crypt_keeper_providers (0.5.0)
+ crypt_keeper_providers (0.5.1)
GEM
remote: https://rubygems.org/
@@ -1,7 +1,7 @@
PATH
remote: /home/justin/work/ruby/crypt_keeper_providers
specs:
- crypt_keeper_providers (0.5.0)
+ crypt_keeper_providers (0.5.1)
GEM
remote: https://rubygems.org/
@@ -1,7 +1,7 @@
PATH
remote: /home/justin/work/ruby/crypt_keeper_providers
specs:
- crypt_keeper_providers (0.5.0)
+ crypt_keeper_providers (0.5.1)
GEM
remote: https://rubygems.org/
@@ -30,6 +30,7 @@ def initialize(options = {})
#
# Returns a string
def encrypt(value)
+ return if value.nil?
aes.encrypt
aes.key = key
iv = rand.to_s
@@ -41,6 +42,7 @@ def encrypt(value)
#
# Returns a string
def decrypt(value)
+ return if value.nil?
iv, value = Base64::decode64(value.to_s).split(SEPARATOR)
aes.decrypt
aes.key = key
@@ -18,6 +18,7 @@ def initialize(options = {})
#
# Returns an encrypted string
def encrypt(value)
+ return if value.nil?
Base64.encode64 escape_and_execute_sql(
["SELECT AES_ENCRYPT(?, ?)", value, key]).first
end
@@ -26,6 +27,7 @@ def encrypt(value)
#
# Returns a plaintext string
def decrypt(value)
+ return if value.nil?
escape_and_execute_sql(
["SELECT AES_DECRYPT(?, ?)", Base64.decode64(value), key]).first
end
@@ -1,3 +1,3 @@
module CryptKeeperProviders
- VERSION = "0.5.0"
+ VERSION = "0.5.1"
end
View
@@ -28,6 +28,10 @@ module CryptKeeperProviders
encrypted.should_not be_nil
encrypted.should_not be_empty
end
+
+ it "should not encrypt nil" do
+ subject.encrypt(nil).should be_nil
+ end
end
describe "#decrypt" do
@@ -38,6 +42,10 @@ module CryptKeeperProviders
it "should decrypt the string" do
decrypted.should == 'string'
end
+
+ it "should not decrypt nil" do
+ subject.decrypt(nil).should be_nil
+ end
end
end
end
View
@@ -22,12 +22,20 @@ module CryptKeeperProviders
subject.encrypt(plain_text).should_not == plain_text
subject.encrypt(plain_text).should_not be_empty
end
+
+ it "should not encrypt nil" do
+ subject.encrypt(nil).should be_nil
+ end
end
describe "#decrypt" do
it "should decrypt the string" do
subject.decrypt(cipher_text).should == plain_text
end
+
+ it "should not decrypt nil" do
+ subject.decrypt(nil).should be_nil
+ end
end
end
end

0 comments on commit ffd0dab

Please sign in to comment.