test/cipher_test.rb in symmetric-encryption-0.9.1 vs test/cipher_test.rb in symmetric-encryption-1.0.0
- old
+ new
@@ -11,20 +11,22 @@
class CipherTest < Test::Unit::TestCase
context 'standalone' do
should "allow setting the cipher" do
cipher = SymmetricEncryption::Cipher.new(
- :cipher => 'aes-128-cbc',
- :key => '1234567890ABCDEF1234567890ABCDEF',
- :iv => '1234567890ABCDEF'
+ :cipher => 'aes-128-cbc',
+ :key => '1234567890ABCDEF1234567890ABCDEF',
+ :iv => '1234567890ABCDEF',
+ :encoding => :none
)
assert_equal 'aes-128-cbc', cipher.cipher
end
should "not require an iv" do
cipher = SymmetricEncryption::Cipher.new(
- :key => '1234567890ABCDEF1234567890ABCDEF'
+ :key => '1234567890ABCDEF1234567890ABCDEF',
+ :encoding => :none
)
result = "\302<\351\227oj\372\3331\310\260V\001\v'\346"
# Note: This test fails on JRuby 1.7 RC1 since it's OpenSSL
# behaves differently when no IV is supplied.
# It instead encrypts to the following value:
@@ -33,13 +35,14 @@
assert_equal result, cipher.encrypt('Hello World')
end
should "throw an exception on bad data" do
cipher = SymmetricEncryption::Cipher.new(
- :cipher => 'aes-128-cbc',
- :key => '1234567890ABCDEF1234567890ABCDEF',
- :iv => '1234567890ABCDEF'
+ :cipher => 'aes-128-cbc',
+ :key => '1234567890ABCDEF1234567890ABCDEF',
+ :iv => '1234567890ABCDEF',
+ :encoding => :none
)
assert_raise OpenSSL::Cipher::CipherError do
cipher.decrypt('bad data')
end
end
@@ -47,11 +50,12 @@
end
context 'with configuration' do
setup do
@cipher = SymmetricEncryption::Cipher.new(
- :key => '1234567890ABCDEF1234567890ABCDEF',
- :iv => '1234567890ABCDEF'
+ :key => '1234567890ABCDEF1234567890ABCDEF',
+ :iv => '1234567890ABCDEF',
+ :encoding => :none
)
@social_security_number = "987654321"
@social_security_number_encrypted = "A\335*\314\336\250V\340\023%\000S\177\305\372\266"
@social_security_number_encrypted.force_encoding('binary') if defined?(Encoding)
\ No newline at end of file