lib/io_streams/pgp/reader.rb in iostreams-1.1.0 vs lib/io_streams/pgp/reader.rb in iostreams-1.1.1
- old
+ new
@@ -1,6 +1,6 @@
-require 'open3'
+require "open3"
module IOStreams
module Pgp
class Reader < IOStreams::Reader
# Passphrase to use to open the private key to decrypt the received file
@@ -22,13 +22,13 @@
# passphrase: [String]
# Pass phrase for private key to decrypt the file with
def self.file(file_name, passphrase: nil)
# Cannot use `passphrase: self.default_passphrase` since it is considered private
passphrase ||= default_passphrase
- raise(ArgumentError, 'Missing both passphrase and IOStreams::Pgp::Reader.default_passphrase') unless passphrase
+ raise(ArgumentError, "Missing both passphrase and IOStreams::Pgp::Reader.default_passphrase") unless passphrase
- loopback = IOStreams::Pgp.pgp_version.to_f >= 2.1 ? '--pinentry-mode loopback' : ''
+ loopback = IOStreams::Pgp.pgp_version.to_f >= 2.1 ? "--pinentry-mode loopback" : ""
command = "#{IOStreams::Pgp.executable} #{loopback} --batch --no-tty --yes --decrypt --passphrase-fd 0 #{file_name}"
IOStreams::Pgp.logger&.debug { "IOStreams::Pgp::Reader.open: #{command}" }
# Read decrypted contents from stdout
Open3.popen3(command) do |stdin, stdout, stderr, waith_thr|
@@ -40,12 +40,10 @@
yield(stdout)
rescue Errno::EPIPE
# Ignore broken pipe because gpg terminates early due to an error
raise(Pgp::Failure, "GPG Failed reading from encrypted file: #{file_name}: #{stderr.read.chomp}")
end
- unless waith_thr.value.success?
- raise(Pgp::Failure, "GPG Failed to decrypt file: #{file_name}: #{stderr.read.chomp}")
- end
+ raise(Pgp::Failure, "GPG Failed to decrypt file: #{file_name}: #{stderr.read.chomp}") unless waith_thr.value.success?
result
end
end
end