docs: python bindings howto DITA

* Updated the decryption example code to include the changes needed to
  gracefully handle a decryption failure due to MDC-less ciphertext
  and/or deprecated algorithms.
* See also: https://dev.gnupg.org/T3981
This commit is contained in:
Ben McGinnes 2018-05-23 15:08:03 +10:00
parent 27ae87c7cf
commit dea1ccbc02

View File

@ -17,10 +17,17 @@ ciphertext = input("Enter path and filename of encrypted file: ")
newfile = input("Enter path and filename of file to save decrypted data to: ") newfile = input("Enter path and filename of file to save decrypted data to: ")
with open(ciphertext, "rb") as cfile: 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: if plaintext is not None:
nfile.write(plaintext) with open(newfile, "wb") as nfile:
nfile.write(plaintext)
else:
pass
</codeblock> </codeblock>
</p> </p>
<p>The data available in <codeph>plaintext</codeph> in this example is the decrypted content <p>The data available in <codeph>plaintext</codeph> in this example is the decrypted content