aboutsummaryrefslogtreecommitdiffstats
path: root/lang/python/examples/howto/decrypt-file.py
diff options
context:
space:
mode:
authorBen McGinnes <[email protected]>2018-05-23 04:43:06 +0000
committerBen McGinnes <[email protected]>2018-05-23 04:43:06 +0000
commit3a9e6a8e088e233097866bb0560a36cfbbc4470e (patch)
tree720fc6352caf415c4ad6ad830a660cb75f6f33f3 /lang/python/examples/howto/decrypt-file.py
parentcpp: Expose sessionKey and symkeyAlgo (diff)
downloadgpgme-3a9e6a8e088e233097866bb0560a36cfbbc4470e.tar.gz
gpgme-3a9e6a8e088e233097866bb0560a36cfbbc4470e.zip
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.
Diffstat (limited to 'lang/python/examples/howto/decrypt-file.py')
-rwxr-xr-xlang/python/examples/howto/decrypt-file.py13
1 files changed, 10 insertions, 3 deletions
diff --git a/lang/python/examples/howto/decrypt-file.py b/lang/python/examples/howto/decrypt-file.py
index 60a050bd..b38acc79 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