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 <ben@adversary.org>
This commit is contained in:
parent
d8beab30c4
commit
89c548efdf
@ -566,6 +566,63 @@ class Context(GpgmeWrapper):
|
|||||||
|
|
||||||
return import_result
|
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,
|
def keylist(self, pattern=None, secret=False,
|
||||||
mode=constants.keylist.mode.LOCAL,
|
mode=constants.keylist.mode.LOCAL,
|
||||||
source=None):
|
source=None):
|
||||||
|
Loading…
Reference in New Issue
Block a user