aboutsummaryrefslogtreecommitdiffstats
path: root/lang/python/src/core.py
diff options
context:
space:
mode:
authorBen McGinnes <[email protected]>2018-06-06 23:46:56 +0000
committerBen McGinnes <[email protected]>2018-06-06 23:46:56 +0000
commit167847f1bcfb1b573bd40fe897f39d4ee4167176 (patch)
treef9b8ef6c5ef3db191c5183a4806041f32e52de57 /lang/python/src/core.py
parentcore: Return a better error code on certain decryption failures. (diff)
downloadgpgme-ben/key-import.tar.gz
gpgme-ben/key-import.zip
python bindings: import keysben/key-import
* Adapted from prior submissions by Tobias Mueller and Jacob Adams. * key_import function added to gpg.core.Context(). * Two example scripts added to to examples/howto: import-key-file.py imports keys from a local file and import-keys.py accesses the SKS keyserver pool using the requests module to search for keys (includes check for key IDs which may not include the leading 0x). * Added documentation demonstrating the use of the key_import() function with a large number of keys matching one domain (eff.org; the example shows how EFF staff are following their own advice issued last month).
Diffstat (limited to 'lang/python/src/core.py')
-rw-r--r--lang/python/src/core.py22
1 files changed, 22 insertions, 0 deletions
diff --git a/lang/python/src/core.py b/lang/python/src/core.py
index bd95d231..10db3d69 100644
--- a/lang/python/src/core.py
+++ b/lang/python/src/core.py
@@ -509,6 +509,28 @@ class Context(GpgmeWrapper):
return results
+ def key_import(self, keydata):
+ """Importing keys
+
+ Arguments:
+ keydata -- Binary or ASCII armored key(s) to be imported
+
+ Returns
+ -- an object describing the results of keys imported or
+ updated
+
+ Raises:
+ GPGMEError -- as signaled by the underlying library
+ """
+ if keydata is not None:
+ try:
+ self.op_import(keydata)
+ result = self.op_import_result()
+ except GPGMEError as e:
+ result = e
+ else:
+ result = "No keys found."
+
def keylist(self, pattern=None, secret=False,
mode=constants.keylist.mode.LOCAL,
source=None):