aboutsummaryrefslogtreecommitdiffstats
path: root/lang/python/src
diff options
context:
space:
mode:
authorBen McGinnes <[email protected]>2018-09-30 06:28:54 +0000
committerBen McGinnes <[email protected]>2018-09-30 06:28:54 +0000
commit11403a46358f9b6e98776974f3c70f211d9adf85 (patch)
tree966e108fc0a044a93f5fb64c8631e209f4d47474 /lang/python/src
parentexample: local signatures (diff)
downloadgpgme-11403a46358f9b6e98776974f3c70f211d9adf85.tar.gz
gpgme-11403a46358f9b6e98776974f3c70f211d9adf85.zip
python bindings: ctx.decrypt
* lang/python/src/core.py: Fixed methods of detecting whether verify is a boolean variable or a list. * Added methods of catching the missing keys exceptions. * Still retained PEP8 compliance (which might have been where one or two problems crept in). * Though this is essentially the correct behaviour, it still does not quite fit the otiginal test; so that will also require some adjustment. Tested-by: Ben McGinnes <[email protected]> Signed-off-by: Ben McGinnes <[email protected]>
Diffstat (limited to 'lang/python/src')
-rw-r--r--lang/python/src/core.py62
1 files changed, 53 insertions, 9 deletions
diff --git a/lang/python/src/core.py b/lang/python/src/core.py
index f440d92d..17ec0ef1 100644
--- a/lang/python/src/core.py
+++ b/lang/python/src/core.py
@@ -366,6 +366,8 @@ class Context(GpgmeWrapper):
GPGMEError -- as signaled by the underlying library
"""
+ sink_result = None
+ verify_sigs = None
plaintext = sink if sink else Data()
if passphrase is not None:
@@ -379,13 +381,29 @@ class Context(GpgmeWrapper):
self.set_passphrase_cb(passphrase_cb)
try:
- if verify:
+ if verify is not None:
+ if isinstance(verify, bool) is True:
+ if verify is False:
+ verify = True
+ sink_result = True
+ else:
+ pass
+ elif isinstance(verify, list) is True:
+ if len(verify) > 0:
+ verify_sigs = True
+ else:
+ pass
+ else:
+ verify = True
self.op_decrypt_verify(ciphertext, plaintext)
else:
self.op_decrypt(ciphertext, plaintext)
except errors.GPGMEError as e:
result = self.op_decrypt_result()
- verify_result = self.op_verify_result() if verify else None
+ if verify is not None and sink_result is None:
+ verify_result = self.op_verify_result()
+ else:
+ verify_result = None
# Just raise the error, but attach the results first.
e.results = (self.__read__(sink, plaintext), result, verify_result)
raise e
@@ -396,19 +414,25 @@ class Context(GpgmeWrapper):
self.set_passphrase_cb(*old_passphrase_cb[1:])
result = self.op_decrypt_result()
- verify_result = self.op_verify_result() if verify else None
+
+ if verify is not None and sink_result is None:
+ verify_result = self.op_verify_result()
+ else:
+ verify_result = None
+
results = (self.__read__(sink, plaintext), result, verify_result)
+
if result.unsupported_algorithm:
- raise errors.UnsupportedAlgorithm(
- result.unsupported_algorithm, results=results)
+ raise errors.UnsupportedAlgorithm(result.unsupported_algorithm,
+ results=results)
if verify:
if any(s.status != errors.NO_ERROR
for s in verify_result.signatures):
raise errors.BadSignatures(verify_result, results=results)
- if not verify: # was: if verify and verify != True:
- missing = list()
+ if verify_sigs is not None:
+ missing = []
for key in verify:
ok = False
for subkey in key.subkeys:
@@ -423,8 +447,28 @@ class Context(GpgmeWrapper):
if not ok:
missing.append(key)
if missing:
- raise errors.MissingSignatures(
- verify_result, missing, results=results)
+ try:
+ raise errors.MissingSignatures(verify_result, missing,
+ results=results)
+ except errors.MissingSignatures as miss_e:
+ mse = miss_e
+ mserr = "gpg.errors.MissingSignatures:"
+ print(mserr, miss_e, "\n")
+ # # The full details can then be found in mse.results,
+ # # mse.result, mse.missing if necessary.
+ # mse_list = []
+ # msp = "Missing signatures from: \n".format()
+ # print(msp)
+ # for key in mse.missing:
+ # mse_list.append(key.fpr)
+ # msl = []
+ # msl.append(key.fpr)
+ # for user in key.uids:
+ # msl.append(user.name)
+ # msl.append(user.email)
+ # # msl.append(user.uid)
+ # print(" ".join(msl))
+ return mse
return results