lib/io_streams/pgp.rb in iostreams-1.6.2 vs lib/io_streams/pgp.rb in iostreams-1.7.0

- old
+ new

@@ -46,12 +46,12 @@ # `SecureRandom.urlsafe_base64(128)` # # See `man gpg` for the remaining options def self.generate_key(name:, email:, - comment: nil, passphrase:, + comment: nil, key_type: "RSA", key_length: 4096, subkey_type: "RSA", subkey_length: key_length, expire_date: nil) @@ -289,14 +289,12 @@ # DEPRECATED - Use key_ids instead of fingerprints def self.fingerprint(email:) version_check Open3.popen2e("#{executable} --list-keys --fingerprint --with-colons #{email}") do |_stdin, out, waith_thr| output = out.read.chomp - unless waith_thr.value.success? - unless output =~ /(public key not found|No public key)/i - raise(Pgp::Failure, "GPG Failed calling #{executable} to list keys for #{email}: #{output}") - end + if !waith_thr.value.success? && !(output !~ /(public key not found|No public key)/i) + raise(Pgp::Failure, "GPG Failed calling #{executable} to list keys for #{email}: #{output}") end output.each_line do |line| if (match = line.match(/\Afpr.*::([^\:]*):\Z/)) return match[1] @@ -334,13 +332,15 @@ # Compression: Uncompressed, ZIP, ZLIB, BZIP2 if (match = out.lines.first.match(/(\d+\.\d+.\d+)/)) match[1] end else - return [] if err =~ /(key not found|No (public|secret) key)/i + if err !~ /(key not found|No (public|secret) key)/i + raise(Pgp::Failure, "GPG Failed calling #{executable} to list keys for #{email || key_id}: #{err}#{out}") + end - raise(Pgp::Failure, "GPG Failed calling #{executable} to list keys for #{email || key_id}: #{err}#{out}") + [] end end end @logger = nil @@ -380,27 +380,27 @@ hash = { private: match[1] == "sec", key_length: match[3].to_s.to_i, key_type: match[2], date: (begin - Date.parse(match[4].to_s) - rescue StandardError - match[4] - end) + Date.parse(match[4].to_s) + rescue StandardError + match[4] + end) } elsif (match = line.match(%r{(pub|sec)\s+(\d+)(.*)/(\w+)\s+(\d+-\d+-\d+)(\s+(.+)<(.+)>)?})) # Matches: pub 2048R/C7F9D9CB 2016-10-26 # Or: pub 2048R/C7F9D9CB 2016-10-26 Receiver <receiver@example.org> hash = { private: match[1] == "sec", key_length: match[2].to_s.to_i, key_type: match[3], key_id: match[4], date: (begin - Date.parse(match[5].to_s) - rescue StandardError - match[5] - end) + Date.parse(match[5].to_s) + rescue StandardError + match[5] + end) } # Prior to gpg v2.0.30 if match[7] hash[:name] = match[7].strip hash[:email] = match[8].strip