diff options
author | Justus Winter <[email protected]> | 2016-10-13 10:05:59 +0000 |
---|---|---|
committer | Justus Winter <[email protected]> | 2016-10-13 11:19:47 +0000 |
commit | 1e6073ffa98db2c265adbcf0dbbe70c067a910f0 (patch) | |
tree | ab90784e5c11048d11188cde73377f541e8d22a8 | |
parent | python: Fix example. (diff) | |
download | gpgme-1e6073ffa98db2c265adbcf0dbbe70c067a910f0.tar.gz gpgme-1e6073ffa98db2c265adbcf0dbbe70c067a910f0.zip |
python: Return public keys by default.
* lang/python/pyme/core.py (Core.get_key): Return public keys by
default, improve docstring.
* lang/python/examples/testCMSgetkey.py: Update example.
* lang/python/examples/verifydetails.py: Likewise.
GnuPG-bug-id: 2751
Signed-off-by: Justus Winter <[email protected]>
-rw-r--r-- | lang/python/examples/testCMSgetkey.py | 2 | ||||
-rwxr-xr-x | lang/python/examples/verifydetails.py | 2 | ||||
-rw-r--r-- | lang/python/pyme/core.py | 21 |
3 files changed, 18 insertions, 7 deletions
diff --git a/lang/python/examples/testCMSgetkey.py b/lang/python/examples/testCMSgetkey.py index 4467b6cc..62c35d26 100644 --- a/lang/python/examples/testCMSgetkey.py +++ b/lang/python/examples/testCMSgetkey.py @@ -28,7 +28,7 @@ if len(sys.argv) != 2: sys.exit("fingerprint or unique key ID for gpgme_get_key()") with pyme.Context(protocol=pyme.constants.PROTOCOL_CMS) as c: - key = c.get_key(sys.argv[1], False) + key = c.get_key(sys.argv[1]) print("got key: ", key.subkeys[0].fpr) for uid in key.uids: diff --git a/lang/python/examples/verifydetails.py b/lang/python/examples/verifydetails.py index fa349269..81f82e99 100755 --- a/lang/python/examples/verifydetails.py +++ b/lang/python/examples/verifydetails.py @@ -52,7 +52,7 @@ def verifyprintdetails(filename, detached_sig_filename=None): print(" status: %#0x" % (sign.status)) print(" timestamp: ", sign.timestamp) print(" fingerprint:", sign.fpr) - print(" uid: ", c.get_key(sign.fpr, 0).uids[0].uid) + print(" uid: ", c.get_key(sign.fpr).uids[0].uid) # Print "unsigned" text if inline signature if data: diff --git a/lang/python/pyme/core.py b/lang/python/pyme/core.py index 88a086b1..cd5217f3 100644 --- a/lang/python/pyme/core.py +++ b/lang/python/pyme/core.py @@ -670,15 +670,26 @@ class Context(GpgmeWrapper): key.__del__ = lambda self: gpgme.gpgme_key_unref(self) return key - def get_key(self, fpr, secret): - """Return the key corresponding to the fingerprint 'fpr'""" + def get_key(self, fpr, secret=False): + """Get a key given a fingerprint + + Keyword arguments: + secret -- to request a secret key + + Returns: + -- the matching key + + Raises: + GPGMEError -- as signaled by the underlying library + + """ ptr = gpgme.new_gpgme_key_t_p() errorcheck(gpgme.gpgme_get_key(self.wrapped, fpr, ptr, secret)) key = gpgme.gpgme_key_t_p_value(ptr) gpgme.delete_gpgme_key_t_p(ptr) - if key: - key.__del__ = lambda self: gpgme.gpgme_key_unref(self) - return key + assert key + key.__del__ = lambda self: gpgme.gpgme_key_unref(self) + return key def op_trustlist_all(self, *args, **kwargs): self.op_trustlist_start(*args, **kwargs) |