[git] GPGME - branch, master, updated. gpgme-1.11.1-11-g3a9e6a8

by Ben McGinnes cvs at cvs.gnupg.org
Wed May 23 07:03:52 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, master has been updated
       via  3a9e6a8e088e233097866bb0560a36cfbbc4470e (commit)
      from  28e3778ce21069006153bc156a414de6d9347962 (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 3a9e6a8e088e233097866bb0560a36cfbbc4470e
Author: Ben McGinnes <ben at adversary.org>
Date:   Wed May 23 14:43:06 2018 +1000

    docs and examples: python howto
    
    * Updated the decryption example code in the HOWTO and the
      corresponding decrypt-file.py script to gracefully handle a
      decryption failure.  This error will always be triggered when GPGME
      is used to try to decrypt an old, MDC-less encrypted message or
      file.

diff --git a/lang/python/docs/GPGMEpythonHOWTOen.org b/lang/python/docs/GPGMEpythonHOWTOen.org
index cb85b61..ef66eff 100644
--- a/lang/python/docs/GPGMEpythonHOWTOen.org
+++ b/lang/python/docs/GPGMEpythonHOWTOen.org
@@ -14,7 +14,7 @@
   :CUSTOM_ID: intro
   :END:
 
-  | Version:        | 0.1.0                                    |
+  | Version:        | 0.1.1                                    |
   | Author:         | Ben McGinnes <ben at gnupg.org>             |
   | Author GPG Key: | DB4724E6FA4286C92B4E55C4321E4E2373590E5D |
   | Language:       | Australian English, British English      |
@@ -673,10 +673,17 @@
      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)
-
-     with open(newfile, "wb") as nfile:
-	 nfile.write(plaintext)
+	 try:
+	     plaintext, result, verify_result = gpg.Context().decrypt(cfile)
+	 except gpg.errors.GPGMEError as e:
+	     plaintext = None
+	     print(e)
+
+     if plaintext is not None:
+	 with open(newfile, "wb") as nfile:
+	     nfile.write(plaintext)
+     else:
+	 pass
    #+end_src
 
    The data available in =plaintext= in this example is the decrypted
diff --git a/lang/python/examples/howto/decrypt-file.py b/lang/python/examples/howto/decrypt-file.py
index 60a050b..b38acc7 100755
--- a/lang/python/examples/howto/decrypt-file.py
+++ b/lang/python/examples/howto/decrypt-file.py
@@ -38,7 +38,14 @@ else:
     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)
+    try:
+        plaintext, result, verify_result = gpg.Context().decrypt(cfile)
+    except gpg.errors.GPGMEError as e:
+        plaintext = None
+        print(e)
 
-with open(newfile, "wb") as nfile:
-    nfile.write(plaintext)
+if plaintext is not None:
+    with open(newfile, "wb") as nfile:
+        nfile.write(plaintext)
+else:
+    pass

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

Summary of changes:
 lang/python/docs/GPGMEpythonHOWTOen.org    | 17 ++++++++++++-----
 lang/python/examples/howto/decrypt-file.py | 13 ++++++++++---
 2 files changed, 22 insertions(+), 8 deletions(-)


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




More information about the Gnupg-commits mailing list