lib/symmetric_encryption/cipher.rb in symmetric-encryption-2.0.0 vs lib/symmetric_encryption/cipher.rb in symmetric-encryption-2.0.1
- old
+ new
@@ -213,12 +213,12 @@
# of the cipher to use
#
# default_compressed
# If no header is present, this is the default value for the compression
def self.parse_magic_header!(buffer, default_version=nil, default_compressed=false)
- buffer.force_encoding(SymmetricEncryption::BINARY_ENCODING)
- return [default_compressed, nil, nil, nil, SymmetricEncryption.cipher(default_version)] unless buffer.start_with?(MAGIC_HEADER)
+ buffer.force_encoding(SymmetricEncryption::BINARY_ENCODING) if buffer
+ return [default_compressed, nil, nil, nil, nil, SymmetricEncryption.cipher(default_version)] unless buffer && buffer.start_with?(MAGIC_HEADER)
# Header includes magic header and version byte
# Remove header and extract flags
_, flags = buffer.slice!(0..MAGIC_HEADER_SIZE+1).unpack(MAGIC_HEADER_UNPACK)
compressed = (flags & 0b1000_0000_0000_0000) != 0
@@ -243,10 +243,10 @@
if include_cipher
len = buffer.slice!(0..1).unpack('v').first
cipher_name = buffer.slice!(0..len-1)
end
- [compressed, iv, key, cipher_name, decryption_cipher]
+ [compressed, iv, key, cipher_name, version, decryption_cipher]
end
# Returns a magic header for this cipher instance that can be placed at
# the beginning of a file or stream to indicate how the data was encrypted
#
\ No newline at end of file