[git] GPGME - branch, ben/docs/2018-03, updated. gpgme-1.10.0-125-g1fdd1f3

by Ben McGinnes cvs at cvs.gnupg.org
Wed Mar 21 15:20:08 CET 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/docs/2018-03 has been updated
       via  1fdd1f306d45f6aeee91c7f016f7c37286ee3b3b (commit)
       via  1d2746433c9632fc0c7bc10b59280fca15895545 (commit)
      from  0390ede18696520be9cc1a42f628e23159b7c2eb (commit)

Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.

- Log -----------------------------------------------------------------
commit 1fdd1f306d45f6aeee91c7f016f7c37286ee3b3b
Author: Ben McGinnes <ben at adversary.org>
Date:   Thu Mar 22 01:18:37 2018 +1100

    example: clear signing
    
    * Added example to clear sign a file with signing key selection.

diff --git a/lang/python/examples/howto/clear-sign-file.py b/lang/python/examples/howto/clear-sign-file.py
new file mode 100755
index 0000000..597bbc5
--- /dev/null
+++ b/lang/python/examples/howto/clear-sign-file.py
@@ -0,0 +1,56 @@
+#!/usr/bin/env python3
+# -*- coding: utf-8 -*-
+
+from __future__ import absolute_import, division, unicode_literals
+
+# Copyright (C) 2018 Ben McGinnes <ben at gnupg.org>
+#
+# This program is free software; you can redistribute it and/or modify it under
+# the terms of the GNU General Public License as published by the Free Software
+# Foundation; either version 2 of the License, or (at your option) any later
+# version.
+#
+# This program is free software; you can redistribute it and/or modify it under
+# the terms of the GNU Lesser General Public License as published by the Free
+# Software Foundation; either version 2.1 of the License, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful, but WITHOUT
+# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
+# FOR A PARTICULAR PURPOSE.  See the GNU General Public License and the GNU
+# Lesser General Public Licensefor more details.
+#
+# You should have received a copy of the GNU General Public License and the GNU
+# Lesser General Public along with this program; if not, see
+# <http://www.gnu.org/licenses/>.
+
+import gpg
+import sys
+
+"""
+Clear-signs a file with a specified key.  If entering both the key and the
+filename on the command line, the key must be entered first.
+"""
+
+if len(sys.argv) > 3:
+    logrus = sys.argv[1]
+    filename = " ".join(sys.argv[2:])
+elif len(sys.argv) == 3:
+    logrus = sys.argv[1]
+    filename = sys.argv[2]
+elif len(sys.argv) == 2:
+    logrus = sys.argv[1]
+    filename = input("Enter the path and filename to sign: ")
+else:
+    logrus = input("Enter the fingerprint or key ID to sign with: ")
+    filename = input("Enter the path and filename to sign: ")
+
+with open(filename, "rb") as f:
+    text = f.read()
+
+key = list(gpg.Context().keylist(pattern=logrus))
+
+with gpg.Context(armor=True, signers=key) as c:
+    signed_data, result = c.sign(text, mode=gpg.constants.sig.mode.CLEAR)
+    with open("{0}.asc".format(filename), "wb") as f:
+        f.write(signed_data)

commit 1d2746433c9632fc0c7bc10b59280fca15895545
Author: Ben McGinnes <ben at adversary.org>
Date:   Thu Mar 22 01:12:36 2018 +1100

    doc: python bindings howto
    
    * deconstructed and fixed all three signing methods.

diff --git a/lang/python/docs/GPGMEpythonHOWTOen.org b/lang/python/docs/GPGMEpythonHOWTOen.org
index 2a200bb..0c15149 100644
--- a/lang/python/docs/GPGMEpythonHOWTOen.org
+++ b/lang/python/docs/GPGMEpythonHOWTOen.org
@@ -750,11 +750,10 @@
      text = text0.encode()
 
      c = gpg.Context(armor=True, signers=sig_src)
-     signed = c.sign(text, mode=gpg.constants.sig.mode.NORMAL)
+     signed_data, result = c.sign(text, mode=gpg.constants.sig.mode.NORMAL)
 
      with open("/path/to/statement.txt.asc", "w") as afile:
-         for line in signed[0]:
-	     afile.write("{0}\n".format(line.decode()))
+	 afile.write(signed_data.decode())
    #+end_src
 
    Though everything in this example is accurate, it is more likely
@@ -769,10 +768,10 @@
          text = tfile.read()
 
      c = gpg.Context()
-     signed = c.sign(text, mode=gpg.constants.sig.mode.NORMAL)
+     signed_data, result = c.sign(text, mode=gpg.constants.sig.mode.NORMAL)
 
      with open("/path/to/statement.txt.sig", "wb") as afile:
-         afile.write(signed[0])
+         afile.write(signed_data)
    #+end_src
 
 
@@ -795,11 +794,10 @@
       text = text0.encode()
 
       c = gpg.Context(armor=True)
-      signed = c.sign(text, mode=gpg.constants.sig.mode.DETACH)
+      signed_data, result = c.sign(text, mode=gpg.constants.sig.mode.DETACH)
 
       with open("/path/to/statement.txt.asc", "w") as afile:
-          for line in signed[0].splitlines():
-	      afile.write("{0}\n".format(line.decode()))
+          afile.write(signed_data.decode())
     #+end_src
 
     As with normal signatures, detached signatures are best handled as
@@ -812,10 +810,10 @@
           text = tfile.read()
 
       c = gpg.Context(signers=sig_src)
-      signed = c.sign(text, mode=gpg.constants.sig.mode.DETACH)
+      signed_data, result = c.sign(text, mode=gpg.constants.sig.mode.DETACH)
 
       with open("/path/to/statement.txt.sig", "wb") as afile:
-          afile.write(signed[0])
+          afile.write(signed_data)
     #+end_src
 
 
@@ -838,11 +836,10 @@
       text = text0.encode()
 
       c = gpg.Context()
-      signed = c.sign(text, mode=gpg.constants.sig.mode.CLEAR)
+      signed_data, result = c.sign(text, mode=gpg.constants.sig.mode.CLEAR)
 
       with open("/path/to/statement.txt.asc", "w") as afile:
-          for line in signed[0].splitlines():
-	      afile.write("{0}\n".format(line.decode()))
+	  afile.write(signed_data.decode())
     #+end_src
 
     In spite of the appearance of a clear-signed message, the data
@@ -855,10 +852,10 @@
           text = tfile.read()
 
       c = gpg.Context()
-      signed = c.sign(text, mode=gpg.constants.sig.mode.CLEAR)
+      signed_data, result = c.sign(text, mode=gpg.constants.sig.mode.CLEAR)
 
       with open("/path/to/statement.txt.asc", "wb") as afile:
-          afile.write(signed[0])
+          afile.write(signed_data)
     #+end_src
 
 

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

Summary of changes:
 lang/python/docs/GPGMEpythonHOWTOen.org            | 27 ++++++++++------------
 .../howto/{sign-file.py => clear-sign-file.py}     | 19 +++++----------
 2 files changed, 18 insertions(+), 28 deletions(-)
 copy lang/python/examples/howto/{sign-file.py => clear-sign-file.py} (72%)


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




More information about the Gnupg-commits mailing list