lib/aead/cipher/aes_hmac.rb in aead-1.8.0 vs lib/aead/cipher/aes_hmac.rb in aead-1.8.1
- old
+ new
@@ -8,11 +8,11 @@
#
# Initializes the cipher with a given secret encryption key.
#
# @param [String] key a secret encryption key
#
- def initialize(key)
+ def initialize(key, options = {})
super(self.class.cipher_mode, key)
end
protected
@@ -27,10 +27,13 @@
def _encrypt(nonce, aad, plaintext)
self.cipher(:encrypt) do |cipher|
cipher.key = self.encryption_key
cipher.iv = nonce
- ciphertext = cipher.update(plaintext) + cipher.final
+ unless plaintext.nil? || plaintext.empty?
+ ciphertext = cipher.update(plaintext)
+ end
+ ciphertext = (ciphertext || "") + cipher.final
mac = hmac_generate(nonce, aad.to_s, ciphertext)
ciphertext << mac
end
end