summaryrefslogtreecommitdiff
path: root/util.py
diff options
context:
space:
mode:
authordrebs <drebs@leap.se>2013-02-19 20:31:45 -0300
committerdrebs <drebs@leap.se>2013-02-19 20:31:59 -0300
commit7f69a12085ed5958dd48b764a52203d23b66e669 (patch)
tree9207c18adf8ae9c0dc2a419c85515be98ab6d89d /util.py
parent0a85b99d444fbdcfb221e266ee3ce081c1f3675c (diff)
Fix encrypted_to method's key lookup.
Diffstat (limited to 'util.py')
-rw-r--r--util.py13
1 files changed, 11 insertions, 2 deletions
diff --git a/util.py b/util.py
index 64c03daa..c64d4c5f 100644
--- a/util.py
+++ b/util.py
@@ -73,12 +73,18 @@ class GPGWrapper(gnupg.GPG):
def find_key_by_subkey(self, subkey):
for key in self.list_keys():
for sub in key['subkeys']:
- #print sub[0]
if sub[0] == subkey:
return key
raise LookupError(
"GnuPG public key for subkey %s not found!" % subkey)
+ def find_key_by_keyid(self, keyid):
+ for key in self.list_keys():
+ if keyid == key['keyid']:
+ return key
+ raise LookupError(
+ "GnuPG public key for subkey %s not found!" % subkey)
+
def encrypt(self, data, recipient, sign=None, always_trust=True,
passphrase=None, symmetric=False):
"""
@@ -164,7 +170,10 @@ class GPGWrapper(gnupg.GPG):
if not result.key:
raise LookupError(
"Content is not encrypted to a GnuPG key!")
- return self.find_key_by_subkey(result.key)
+ try:
+ return self.find_key_by_keyid(result.key)
+ except:
+ return self.find_key_by_subkey(result.key)
def is_encrypted_sym(self, raw_data):
result = self.list_packets(raw_data)