commit f532be4340dcdaadb55476375dd8cf3d2d393e04
parent 487659af4fd667c7da34af9f4a4516305a07e2cd
Author: Hamish Downer <dmishd@gmail.com>
Date: Sun, 30 Jan 2011 23:37:45 +0000
Catch case where gpg-agent not running or key not available
GPGME does not raise an Error when the key is not available (say
gpg-agent is not running, or the key is on removable media and has
been removed). In these cases GPGME returns a zero length string.
This patch checks the returned string and raises an error if it has
zero length.
Diffstat:
1 file changed, 14 insertions(+), 0 deletions(-)
diff --git a/lib/sup/crypto.rb b/lib/sup/crypto.rb
@@ -79,6 +79,13 @@ EOS
raise Error, "GPG command failed. See log for details."
end
+ # if the key (or gpg-agent) is not available GPGME does not complain
+ # but just returns a zero length string. Let's catch that
+ if sig.length == 0
+ info "GPG failed to generate signature: check that gpg-agent is running and your key is available."
+ raise Error, "GPG command failed. See log for details."
+ end
+
envelope = RMail::Message.new
envelope.header["Content-Type"] = 'multipart/signed; protocol=application/pgp-signature'
@@ -107,6 +114,13 @@ EOS
raise Error, "GPG command failed. See log for details."
end
+ # if the key (or gpg-agent) is not available GPGME does not complain
+ # but just returns a zero length string. Let's catch that
+ if cipher.length == 0
+ info "GPG failed to generate cipher text: check that gpg-agent is running and your key is available."
+ raise Error, "GPG command failed. See log for details."
+ end
+
encrypted_payload = RMail::Message.new
encrypted_payload.header["Content-Type"] = "application/octet-stream"
encrypted_payload.header["Content-Disposition"] = 'inline; filename="msg.asc"'