From 7b9a1eeeaaa25931963e2de49410d7cb0c7e6772 Mon Sep 17 00:00:00 2001 From: Hamish Downer Date: Mon, 8 Nov 2010 22:31:01 +0000 Subject: [PATCH 2/2] catch exception when no public key present --- lib/sup/crypto.rb | 16 ++++++++++++---- 1 files changed, 12 insertions(+), 4 deletions(-) diff --git a/lib/sup/crypto.rb b/lib/sup/crypto.rb index 9d21ea0..83176d9 100644 --- a/lib/sup/crypto.rb +++ b/lib/sup/crypto.rb @@ -247,19 +247,27 @@ private end def sig_output_lines signature + # It appears that the signature.to_s call can lead to a EOFError if + # the key is not found. So start by looking for the key. + ctx = GPGME::Ctx.new + begin + from_key = ctx.get_key(signature.fingerprint) + first_sig = signature.to_s.sub(/from [0-9A-F]{16} /, 'from "') + '"' + rescue EOFError => error + first_sig = "No public key available for #{signature.fingerprint}" + end + time_line = "Signature made " + signature.timestamp.strftime("%a %d %b %Y %H:%M:%S %Z") + " using key ID " + signature.fingerprint[-8..-1] - first_sig = signature.to_s.sub(/from [0-9A-F]{16} /, 'from "') + '"' output_lines = [time_line, first_sig] - ctx = GPGME::Ctx.new - if from_key = ctx.get_key(signature.fingerprint) + if from_key if from_key.uids.length > 1 aka_list = from_key.uids[1..-1] aka_list.each { |aka| output_lines << ' aka "' + aka.uid + '"' } end end - output_lines + output_lines.flatten! end # logic is: -- 1.7.1