lib/lockbox/utils.rb in lockbox-0.4.2 vs lib/lockbox/utils.rb in lockbox-0.4.3
- old
+ new
@@ -29,16 +29,16 @@
def self.encrypted_options(record, name)
record.class.respond_to?(:lockbox_attachments) ? record.class.lockbox_attachments[name.to_sym] : nil
end
- def self.decode_key(key, size: 32)
+ def self.decode_key(key, size: 32, name: "Key")
if key.encoding != Encoding::BINARY && key =~ /\A[0-9a-f]{#{size * 2}}\z/i
key = [key].pack("H*")
end
- raise Lockbox::Error, "Key must use binary encoding" if key.encoding != Encoding::BINARY
- raise Lockbox::Error, "Key must be 32 bytes" if key.bytesize != size
+ raise Lockbox::Error, "#{name} must be 32 bytes (64 hex digits)" if key.bytesize != size
+ raise Lockbox::Error, "#{name} must use binary encoding" if key.encoding != Encoding::BINARY
key
end
def self.encrypted?(record, name)