lib/symmetric_encryption/reader.rb in symmetric-encryption-1.1.1 vs lib/symmetric_encryption/reader.rb in symmetric-encryption-2.0.0
- old
+ new
@@ -1,5 +1,7 @@
+require 'openssl'
+
module SymmetricEncryption
# Read from encrypted files and other IO streams
#
# Features:
# * Decryption on the fly whilst reading files
@@ -291,15 +293,15 @@
# Read first block and check for the header
buf = @ios.read(@buffer_size)
# Use cipher specified in header, or global cipher if it has no header
- @cipher, @compressed = SymmetricEncryption::Cipher.parse_magic_header!(buf, @version)
+ @compressed, iv, key, cipher_name, decryption_cipher = SymmetricEncryption::Cipher.parse_magic_header!(buf, @version)
- # Use supplied version if cipher could not be detected due to missing header
- @cipher ||= SymmetricEncryption.cipher(@version)
-
- @stream_cipher = @cipher.send(:openssl_cipher, :decrypt)
+ @stream_cipher = ::OpenSSL::Cipher.new(cipher_name || decryption_cipher.cipher_name)
+ @stream_cipher.decrypt
+ @stream_cipher.key = key || decryption_cipher.send(:key)
+ @stream_cipher.iv = iv || decryption_cipher.send(:iv)
# First call to #update should return an empty string anyway
@read_buffer = @stream_cipher.update(buf)
@read_buffer << @stream_cipher.final if @ios.eof?
end