lib/symmetric_encryption/cipher.rb in symmetric-encryption-3.6.0 vs lib/symmetric_encryption/cipher.rb in symmetric-encryption-3.7.0
- old
+ new
@@ -83,22 +83,22 @@
# migration to a new key trivial
# Default: false
# Recommended: true
#
def initialize(params={})
- parms = params.dup
- @key = parms.delete(:key)
- @iv = parms.delete(:iv)
- @cipher_name = parms.delete(:cipher_name) || parms.delete(:cipher) || 'aes-256-cbc'
- @version = parms.delete(:version)
- @always_add_header = parms.delete(:always_add_header) || false
- @encoding = (parms.delete(:encoding) || :base64).to_sym
+ params = params.dup
+ @key = params.delete(:key)
+ @iv = params.delete(:iv)
+ @cipher_name = params.delete(:cipher_name) || params.delete(:cipher) || 'aes-256-cbc'
+ @version = params.delete(:version)
+ @always_add_header = params.delete(:always_add_header) || false
+ @encoding = (params.delete(:encoding) || :base64).to_sym
- raise "Missing mandatory parameter :key" unless @key
- raise "Invalid Encoding: #{@encoding}" unless ENCODINGS.include?(@encoding)
- raise "Cipher version has a valid rage of 0 to 255. #{@version} is too high, or negative" if (@version.to_i > 255) || (@version.to_i < 0)
- parms.each_pair {|k,v| warn "SymmetricEncryption::Cipher Ignoring unknown option #{k.inspect} = #{v.inspect}"}
+ raise(ArgumentError, "Missing mandatory parameter :key") unless @key
+ raise(ArgumentError, "Invalid Encoding: #{@encoding}") unless ENCODINGS.include?(@encoding)
+ raise(ArgumentError, "Cipher version has a valid range of 0 to 255. #{@version} is too high, or negative") if (@version.to_i > 255) || (@version.to_i < 0)
+ raise(ArgumentError, "SymmetricEncryption::Cipher Invalid options #{params.inspect}") if params.size > 0
end
# Encrypt and then encode a string
#
# Returns data encrypted and then encoded according to the encoding setting
@@ -284,10 +284,10 @@
include_cipher= (flags & 0b0001_0000_0000_0000) != 0
# Version of the key to use to decrypt the key if present,
# otherwise to decrypt the data following the header
version = flags & 0b0000_0000_1111_1111
decryption_cipher = SymmetricEncryption.cipher(version)
- raise "Cipher with version:#{version.inspect} not found in any of the configured SymmetricEncryption ciphers" unless decryption_cipher
+ raise(SymmetricEncryption::CipherError, "Cipher with version:#{version.inspect} not found in any of the configured SymmetricEncryption ciphers") unless decryption_cipher
iv, key, cipher_name = nil
if include_iv
len = buffer.slice!(0..1).unpack('v').first
iv = buffer.slice!(0..len-1)