aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBen McGinnes <[email protected]>2018-06-27 08:51:09 +0000
committerBen McGinnes <[email protected]>2018-06-27 08:51:09 +0000
commit870c317120e08d3f606c6c5675d559e1d457290d (patch)
tree97f48ea4bae2aa1d8cf2db2d769655e971828804
parentjson: Add file handling for debug output (diff)
downloadgpgme-870c317120e08d3f606c6c5675d559e1d457290d.tar.gz
gpgme-870c317120e08d3f606c6c5675d559e1d457290d.zip
python bindings: export public keys
* Added functions for exporting public keys to gpg.core in both complete form and in minimised form. * Rather than letting people need to worry about the export modes we are simply separating the functions as people would be more familiar with from the command line usage anyway. * Functions added for Context are: ctx.key_export_minimal and ctx.key_export as the default or full export. Signed-off-by: Ben McGinnes <[email protected]>
-rw-r--r--lang/python/src/core.py59
1 files changed, 58 insertions, 1 deletions
diff --git a/lang/python/src/core.py b/lang/python/src/core.py
index 8f2e9d8d..86a62b51 100644
--- a/lang/python/src/core.py
+++ b/lang/python/src/core.py
@@ -537,7 +537,7 @@ class Context(GpgmeWrapper):
managed to run the function without any
arguments, while an argument of None triggers
the first NODATA of errors.GPGME in the
- exception.
+ exception.
"""
try:
self.op_import(data)
@@ -566,6 +566,63 @@ class Context(GpgmeWrapper):
return import_result
+ def key_export(self, pattern=None):
+ """Export keys.
+
+ Exports public keys matching the pattern specified. If no
+ pattern is specified then exports all available keys.
+
+ Keyword arguments:
+ pattern -- return keys matching pattern (default: all keys)
+
+ Returns:
+ -- A key block containing one or more OpenPGP keys in
+ either ASCII armoured or binary format as determined
+ by the Context().
+
+ Raises:
+ GPGMEError -- as signaled by the underlying library.
+ """
+ data = Data()
+ mode = 0
+ try:
+ self.op_export(pattern, mode, data)
+ data.seek(0, os.SEEK_SET)
+ result = data.read()
+ except GPGMEError as e:
+ result = e
+
+ return result
+
+ def key_export_minimal(self, pattern=None):
+ """Export keys.
+
+ Exports public keys matching the pattern specified in a
+ minimised format. If no pattern is specified then exports all
+ available keys.
+
+ Keyword arguments:
+ pattern -- return keys matching pattern (default: all keys)
+
+ Returns:
+ -- A key block containing one or more minimised OpenPGP
+ keys in either ASCII armoured or binary format as
+ determined by the Context().
+
+ Raises:
+ GPGMEError -- as signaled by the underlying library.
+"""
+ data = Data()
+ mode = gpgme.GPGME_EXPORT_MODE_MINIMAL
+ try:
+ self.op_export(pattern, mode, data)
+ data.seek(0, os.SEEK_SET)
+ result = data.read()
+ except GPGMEError as e:
+ result = e
+
+ return result
+
def keylist(self, pattern=None, secret=False,
mode=constants.keylist.mode.LOCAL,
source=None):