From 167847f1bcfb1b573bd40fe897f39d4ee4167176 Mon Sep 17 00:00:00 2001 From: Ben McGinnes Date: Thu, 7 Jun 2018 09:46:56 +1000 Subject: python bindings: import keys * 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). --- lang/python/src/core.py | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) (limited to 'lang/python/src') 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): -- cgit v1.2.3