test/test_aes.rb in aes-0.3.0 vs test/test_aes.rb in aes-0.4.0
- old
+ new
@@ -3,17 +3,26 @@
class TestAES < Test::Unit::TestCase
should "encrypt and decrypt a string" do
key = "01234567890123456789012345678901"
msg = "This is a message that nobody should ever see"
- enc = AES.encrypt(key, msg)
- assert_equal msg, AES.decrypt(key, enc)
- enc = AES.encrypt(key, msg, {:format => :plain})
- assert_equal msg, AES.decrypt(key, enc, {:format => :plain})
+ enc = AES.encrypt(msg, key)
+ assert_equal msg, AES.decrypt(enc, key)
+ enc = AES.encrypt(msg, key, {:format => :plain})
+ assert_equal msg, AES.decrypt(enc, key, {:format => :plain})
end
+ should "produce the same encrypted string when provided an identical key and iv" do
+ key = "01234567890123456789012345678901"
+ msg = "This is a message that nobody should ever see"
+ iv = AES.iv(:base_64)
+ enc1 = AES.encrypt(msg, key, {:iv => iv})
+ enc2 = AES.encrypt(msg, key, {:iv => iv})
+ assert_equal enc1, enc2
+ end
+
should "generate a new key when AES#key" do
assert_equal 32, AES.key.length
- assert_equal 45, AES.key(256, :base_64).length
+ assert_equal 44, AES.key(256, :base_64).length
end
end