lib/lockbox/encryptor.rb in lockbox-0.4.4 vs lib/lockbox/encryptor.rb in lockbox-0.4.5

- old
+ new

@@ -11,19 +11,19 @@ [Box.new(**options)] + Array(previous_versions).map { |v| Box.new(key: options[:key], **v) } end def encrypt(message, **options) - message = check_string(message, "message") + message = check_string(message) ciphertext = @boxes.first.encrypt(message, **options) ciphertext = Base64.strict_encode64(ciphertext) if @encode ciphertext end def decrypt(ciphertext, **options) ciphertext = Base64.decode64(ciphertext) if @encode - ciphertext = check_string(ciphertext, "ciphertext") + ciphertext = check_string(ciphertext) # ensure binary if ciphertext.encoding != Encoding::BINARY # dup to prevent mutation ciphertext = ciphertext.dup.force_encoding(Encoding::BINARY) @@ -64,12 +64,13 @@ message.force_encoding(Encoding::UTF_8) end private - def check_string(str, name) + def check_string(str) str = str.read if str.respond_to?(:read) - raise TypeError, "can't convert #{name} to string" unless str.respond_to?(:to_str) + # Ruby uses "no implicit conversion of Object into String" + raise TypeError, "can't convert #{str.class.name} to String" unless str.respond_to?(:to_str) str.to_str end def copy_metadata(source, target) target.original_filename =