test/cipher_test.rb in symmetric-encryption-1.1.1 vs test/cipher_test.rb in symmetric-encryption-2.0.0
- old
+ new
@@ -12,18 +12,18 @@
# Unit Test for SymmetricEncryption::Cipher
#
class CipherTest < Test::Unit::TestCase
context 'standalone' do
- should "allow setting the cipher" do
+ should "allow setting the cipher_name" do
cipher = SymmetricEncryption::Cipher.new(
- :cipher => 'aes-128-cbc',
+ :cipher_name => 'aes-128-cbc',
:key => '1234567890ABCDEF1234567890ABCDEF',
:iv => '1234567890ABCDEF',
:encoding => :none
)
- assert_equal 'aes-128-cbc', cipher.cipher
+ assert_equal 'aes-128-cbc', cipher.cipher_name
end
should "not require an iv" do
cipher = SymmetricEncryption::Cipher.new(
:key => '1234567890ABCDEF1234567890ABCDEF',
@@ -38,11 +38,11 @@
assert_equal result, cipher.encrypt('Hello World')
end
should "throw an exception on bad data" do
cipher = SymmetricEncryption::Cipher.new(
- :cipher => 'aes-128-cbc',
+ :cipher_name => 'aes-128-cbc',
:key => '1234567890ABCDEF1234567890ABCDEF',
:iv => '1234567890ABCDEF',
:encoding => :none
)
assert_raise OpenSSL::Cipher::CipherError do
@@ -68,11 +68,11 @@
{ :text => '555052345', :encrypted => ''}
]
end
should "default to 'aes-256-cbc'" do
- assert_equal 'aes-256-cbc', @cipher.cipher
+ assert_equal 'aes-256-cbc', @cipher.cipher_name
end
should "encrypt simple string" do
assert_equal @social_security_number_encrypted, @cipher.encrypt(@social_security_number)
end
@@ -94,20 +94,21 @@
end
context "magic header" do
should "create and parse magic header" do
- random_cipher = SymmetricEncryption::Cipher.random_cipher
- header = random_cipher.magic_header(compressed=true, include_iv=true, include_key=true, include_cipher=true)
- cipher, compressed = SymmetricEncryption::Cipher.parse_magic_header!(header)
+ random_cipher = SymmetricEncryption::Cipher.new(SymmetricEncryption::Cipher.random_key_pair)
+ header = SymmetricEncryption::Cipher.magic_header(1, compressed=true, random_cipher.send(:iv), random_cipher.send(:key), random_cipher.cipher_name)
+ compressed, iv, key, cipher_name, decryption_cipher = SymmetricEncryption::Cipher.parse_magic_header!(header)
assert_equal true, compressed
- assert_equal random_cipher.cipher, cipher.cipher, "Ciphers differ"
- assert_equal random_cipher.send(:key), cipher.send(:key), "Keys differ"
- assert_equal random_cipher.send(:iv), cipher.send(:iv), "IVs differ"
+ assert_equal random_cipher.cipher_name, cipher_name, "Ciphers differ"
+ assert_equal random_cipher.send(:key), key, "Keys differ"
+ assert_equal random_cipher.send(:iv), iv, "IVs differ"
- string = "Hellow World"
+ string = "Hello World"
+ cipher = SymmetricEncryption::Cipher.new(:key => key, :iv => iv, :cipher_name => cipher_name)
# Test Encryption
- assert_equal random_cipher.encrypt(string, false), cipher.encrypt(string, false), "Encrypted values differ"
+ assert_equal random_cipher.encrypt(string, false, false), cipher.encrypt(string, false, false), "Encrypted values differ"
end
end
end
end
\ No newline at end of file