summaryrefslogtreecommitdiffstats
path: root/test
diff options
context:
space:
mode:
authorJeremy Evans <code@jeremyevans.net>2019-07-18 13:48:55 -0700
committerJeremy Evans <code@jeremyevans.net>2019-07-18 13:52:20 -0700
commitb4bf269f08802af01b400702a920eb67fbf4f0a4 (patch)
treede0ebfcf2bade2b62ef4622fcdeaf3f771fba8aa /test
parent5953035e91c3e11ea71e73cc996be7f7fc9d4c33 (diff)
downloadruby-openssl-b4bf269f08802af01b400702a920eb67fbf4f0a4.tar.gz
Set key_set ivar to false if encrypt/decrypt called without key
This makes it obvious you have made a mistake if you call key= and then encrypt or decrypt. Calling encrypt or decrypt without an argument automatically sets the key to NULL, in which case the key_set ivar should be changed from false to true given if had been set before calling encrypt or decrypt. Fixes Ruby Bug 8720.
Diffstat (limited to 'test')
-rw-r--r--test/test_cipher.rb15
1 files changed, 15 insertions, 0 deletions
diff --git a/test/test_cipher.rb b/test/test_cipher.rb
index d83fa4ec..6a41af1c 100644
--- a/test/test_cipher.rb
+++ b/test/test_cipher.rb
@@ -305,6 +305,21 @@ class OpenSSL::TestCipher < OpenSSL::TestCase
}
end
+ def test_crypt_after_key
+ key = ["2b7e151628aed2a6abf7158809cf4f3c"].pack("H*")
+ %w'ecb cbc cfb ctr gcm'.each do |c|
+ cipher = OpenSSL::Cipher.new("aes-128-#{c}")
+ cipher.key = key
+ cipher.encrypt
+ assert_raise(OpenSSL::Cipher::CipherError) { cipher.update("") }
+
+ cipher = OpenSSL::Cipher.new("aes-128-#{c}")
+ cipher.key = key
+ cipher.decrypt
+ assert_raise(OpenSSL::Cipher::CipherError) { cipher.update("") }
+ end
+ end
+
private
def new_encryptor(algo, **kwargs)