[git] GPGME - branch, ben/export-keys, created. gpgme-1.11.1-65-g14cbbb3

by Ben McGinnes cvs at cvs.gnupg.org
Wed Jun 27 11:22:00 CEST 2018


This is an automated email from the git hooks/post-receive script. It was
generated because a ref change was pushed to the repository containing
the project "GnuPG Made Easy".

The branch, ben/export-keys has been created
        at  14cbbb3d702ba6d2dabd0a5cf4025e9101c5c2bd (commit)

- Log -----------------------------------------------------------------
commit 14cbbb3d702ba6d2dabd0a5cf4025e9101c5c2bd
Author: Ben McGinnes <ben at adversary.org>
Date:   Wed Jun 27 19:16:29 2018 +1000

    python bindings: export secret keys
    
    * The holy grail: a function to export secret keys.
    * GPGME will still invoke pinentry and gpg-agent as usual to authorise
      the export.
    * Mostly similar to the two previous export functions for public keys
      except that it will return None if the result had a length of zero
      bytes.  Meaning that the difference between the specified pattern
      (if any) not matching available keys and an incorrect passphrase is
      not able to be determined from this function (or the underlying one
      for that matter).
    
    Signed-off-by: Ben McGinnes <ben at adversary.org>

diff --git a/lang/python/src/core.py b/lang/python/src/core.py
index 86a62b5..d1376da 100644
--- a/lang/python/src/core.py
+++ b/lang/python/src/core.py
@@ -611,7 +611,7 @@ class Context(GpgmeWrapper):
 
         Raises:
         GPGMEError     -- as signaled by the underlying library.
-"""
+        """
         data = Data()
         mode = gpgme.GPGME_EXPORT_MODE_MINIMAL
         try:
@@ -623,6 +623,47 @@ class Context(GpgmeWrapper):
 
         return result
 
+    def key_export_secret(self, pattern=None):
+        """Export secret keys.
+
+        Exports secret keys matching the pattern specified.  If no
+        pattern is specified then exports or attempts to export all
+        available secret keys.
+
+        IMPORTANT: Each secret key to be exported will prompt for its
+        passphrase via an invocation of pinentry and gpg-agent.  If the
+        passphrase is not entered or does not match then no data will be
+        exported.  This is the same result as when specifying a pattern
+        that is not matched by the available keys.
+
+        Keyword arguments:
+        pattern	-- return keys matching pattern (default: all keys)
+
+        Returns:
+                -- On success a key block containing one or more OpenPGP
+                   secret keys in either ASCII armoured or binary format
+                   as determined by the Context().
+                -- On failure while not raising an exception, returns None.
+
+        Raises:
+        GPGMEError     -- as signaled by the underlying library.
+        """
+        data = Data()
+        mode = gpgme.GPGME_EXPORT_MODE_SECRET
+        try:
+            self.op_export(pattern, mode, data)
+            data.seek(0, os.SEEK_SET)
+            sk_result = data.read()
+        except GPGMEError as e:
+            sk_result = e
+
+        if len(sk_result) > 0:
+            result = sk_result
+        else:
+            result = None
+
+        return result
+
     def keylist(self, pattern=None, secret=False,
                 mode=constants.keylist.mode.LOCAL,
                 source=None):

commit 870c317120e08d3f606c6c5675d559e1d457290d
Author: Ben McGinnes <ben at adversary.org>
Date:   Wed Jun 27 18:51:09 2018 +1000

    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 at adversary.org>

diff --git a/lang/python/src/core.py b/lang/python/src/core.py
index 8f2e9d8..86a62b5 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):

-----------------------------------------------------------------------


hooks/post-receive
-- 
GnuPG Made Easy
http://git.gnupg.org




More information about the Gnupg-commits mailing list