[git] GPGME - branch, ben/howto-update-02, updated. gpgme-1.10.0-170-g2f507b0

by Ben McGinnes cvs at cvs.gnupg.org
Wed Mar 28 22:28:08 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/howto-update-02 has been updated
       via  2f507b045909d32bf29d23da04db02b078e5fb9d (commit)
       via  5cd419341807d8ae23fec7bd9bb7025a8a2dcb3c (commit)
      from  a2eedef630891397f8eccb5bb426a0728588bf41 (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 2f507b045909d32bf29d23da04db02b078e5fb9d
Author: Ben McGinnes <ben at adversary.org>
Date:   Thu Mar 29 07:22:37 2018 +1100

    docs python bindings howto
    
    * PEP8 compliance: a collection of minor edits across multiple example
      code snippets.

diff --git a/lang/python/docs/GPGMEpythonHOWTOen.org b/lang/python/docs/GPGMEpythonHOWTOen.org
index 5e1e0ab..1be9369 100644
--- a/lang/python/docs/GPGMEpythonHOWTOen.org
+++ b/lang/python/docs/GPGMEpythonHOWTOen.org
@@ -165,7 +165,7 @@
     This package is the origin of these bindings, though they are
     somewhat different now.  For details of when and how the PyME
     package was folded back into GPGME itself see the /Short History/
-    document[fn:1] in this Python bindings =docs= directory.[fn:2]
+    document[fn:1] in the Python bindings =docs= directory.[fn:2]
 
     The PyME package was first released in 2002 and was also the first
     attempt to implement a low level binding to GPGME.  In doing so it
@@ -537,8 +537,7 @@
       c = gpg.Context(armor=True)
       rkey = list(c.keylist(pattern=a_key, secret=False))
       ciphertext, result, sign_result = c.encrypt(text, recipients=rkey,
-						  sign=True, always_trust=True,
-                                                  add_encrypt_to=True)
+			      sign=True, always_trust=True, add_encrypt_to=True)
 
       with open("secret_plans.txt.asc", "wb") as afile:
 	  afile.write(ciphertext)
@@ -589,10 +588,10 @@
 	      logrus.append(rpattern[i])
 
       ciphertext, result, sign_result = c.encrypt(text, recipients=logrus, sign=False,
-                                                  always_trust=True)
+						  always_trust=True)
 
       with open("secret_plans.txt.asc", "wb") as afile:
-          afile.write(ciphertext)
+	  afile.write(ciphertext)
     #+end_src
 
     All it would take to change the above example to sign the message
@@ -601,7 +600,7 @@
 
     #+begin_src python
       ciphertext, result, sign_result = c.encrypt(text, recipients=logrus,
-			                          always_trust=True,
+						  always_trust=True,
 						  add_encrypt_to=True)
     #+end_src
 
@@ -619,7 +618,7 @@
       import gpg
 
       with open("secret_plans.txt.asc", "rb") as afile:
-          text = afile.read()
+	  text = afile.read()
 
       c = gpg.Context(armor=True)
       rpattern = list(c.keylist(pattern="@gnupg.org", secret=False))
@@ -630,21 +629,23 @@
 	      logrus.append(rpattern[i])
 
       try:
-	  ciphertext, result, sign_result = c.encrypt(text, recipients=logrus, add_encrypt_to=True)
+	  ciphertext, result, sign_result = c.encrypt(text, recipients=logrus,
+						      add_encrypt_to=True)
       except gpg.errors.InvalidRecipients as e:
 	  for i in range(len(e.recipients)):
 	      for n in range(len(logrus)):
 		  if logrus[n].fpr == e.recipients[i].fpr:
 		      logrus.remove(logrus[n])
-                  else:
-                      pass
+		  else:
+		      pass
 	  try:
-	      ciphertext, result, sign_result = c.encrypt(text, recipients=logrus, add_encrypt_to=True)
+	      ciphertext, result, sign_result = c.encrypt(text, recipients=logrus,
+							  add_encrypt_to=True)
 	  except:
 	      pass
 
       with open("secret_plans.txt.asc", "wb") as afile:
-          afile.write(ciphertext)
+	  afile.write(ciphertext)
     #+end_src
 
     This will attempt to encrypt to all the keys searched for, then
@@ -670,10 +671,12 @@
 
      ciphertext = input("Enter path and filename of encrypted file: ")
      newfile = input("Enter path and filename of file to save decrypted data to: ")
+
      with open(ciphertext, "rb") as cfile:
-         plaintext, result, verify_result = gpg.Context().decrypt(cfile)
+	 plaintext, result, verify_result = gpg.Context().decrypt(cfile)
+
      with open(newfile, "wb") as nfile:
-         nfile.write(plaintext)
+	 nfile.write(plaintext)
    #+end_src
 
    The data available in =plaintext= in this example is the decrypted
@@ -1172,7 +1175,7 @@
      c = gpg.Context()
      c.home_dir = "~/.gnupg-dm"
 
-     key = c.get_key(dmkey.fpr, secret = True)
+     key = c.get_key(dmkey.fpr, secret=True)
      dmsub = c.create_subkey(key, algorithm="rsa3072", expires_in=15768000,
 			     encrypt=True)
    #+end_src
@@ -1223,7 +1226,7 @@
      c.home_dir = "~/.gnupg-dm"
 
      dmfpr = "177B7C25DB99745EE2EE13ED026D2F19E99E63AA"
-     key = c.get_key(dmfpr, secret = True)
+     key = c.get_key(dmfpr, secret=True)
      uid = "Danger Mouse <danger.mouse at secret.example.net>"
 
      c.key_add_uid(key, uid)

commit 5cd419341807d8ae23fec7bd9bb7025a8a2dcb3c
Author: Ben McGinnes <ben at adversary.org>
Date:   Thu Mar 29 06:36:14 2018 +1100

    example: add user ID
    
    * Added script to add a UID to an existing key.

diff --git a/lang/python/examples/howto/add-userid.py b/lang/python/examples/howto/add-userid.py
new file mode 100755
index 0000000..b868979
--- /dev/null
+++ b/lang/python/examples/howto/add-userid.py
@@ -0,0 +1,62 @@
+#!/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 os.path
+
+print("""
+This script adds a new user ID to an existing key.
+
+The gpg-agent and pinentry are invoked to enter the passphrase.
+""")
+
+c = gpg.Context()
+
+homedir = input("Enter the GPG configuration directory path (optional): ")
+fpr0 = input("Enter the fingerprint of the key to modify: ")
+uid_name = input("Enter the name of the user ID: ")
+uid_email = input("Enter the email address of the user ID: ")
+uid_cmnt = input("Enter a comment to include (optional): ")
+
+if homedir.startswith("~"):
+    if os.path.exists(os.path.expanduser(homedir)) is True:
+        c.home_dir = os.path.expanduser(homedir)
+    else:
+        pass
+elif os.path.exists(homedir) is True:
+    c.home_dir = homedir
+else:
+    pass
+
+fpr = "".join(fpr0.split())
+
+if len(uid_cmnt) > 0:
+    userid = "{0} ({1}) <{2}>".format(uid_name, uid_cmnt, uid_email)
+else:
+    userid = "{0} <{2}>".format(uid_name, uid_email)
+
+key = c.get_key(fpr, secret=True)
+c.key_add_uid(key, userid)

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

Summary of changes:
 lang/python/docs/GPGMEpythonHOWTOen.org            | 35 ++++++++--------
 .../howto/{create-key.py => add-userid.py}         | 47 ++++------------------
 2 files changed, 26 insertions(+), 56 deletions(-)
 copy lang/python/examples/howto/{create-key.py => add-userid.py} (61%)


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




More information about the Gnupg-commits mailing list