From 0a242c50f93319a47217dd577089732f4fbf0664 Mon Sep 17 00:00:00 2001
From: Gaudenz Steinlin <gaudenz@soziologie.ch>
Date: Thu, 17 Feb 2011 15:26:41 +0100
Subject: [PATCH 3/3] Check for valid signature before signature.to_s

In some circumstances with broken signatures signature.to_s returns nil.
Check for a valid signature before relying on this string. This avoids
an uncaught exception.
---
 lib/sup/crypto.rb |    8 +++++++-
 1 files changed, 7 insertions(+), 1 deletions(-)

diff --git a/lib/sup/crypto.rb b/lib/sup/crypto.rb
index cbd0751..9ab8607 100644
--- a/lib/sup/crypto.rb
+++ b/lib/sup/crypto.rb
@@ -292,7 +292,13 @@ private
     ctx = GPGME::Ctx.new
     begin
       from_key = ctx.get_key(signature.fingerprint)
-      first_sig = signature.to_s.sub(/from [0-9A-F]{16} /, 'from "') + '"'
+      if GPGME::gpgme_err_code(signature.status) == GPGME::GPG_ERR_GENERAL
+        first_sig = "General error on signature verification for #{signature.fingerprint}"
+      elsif signature.to_s
+        first_sig = signature.to_s.sub(/from [0-9A-F]{16} /, 'from "') + '"'
+      else
+        first_sig = "Unknown error or empty signature"
+      end
     rescue EOFError
       from_key = nil
       first_sig = "No public key available for #{signature.fingerprint}"
-- 
1.7.2.3

