diff options
author | Justus Winter <4winter@informatik.uni-hamburg.de> | 2013-05-24 17:50:24 +0200 |
---|---|---|
committer | Patrick Totzke <patricktotzke@gmail.com> | 2013-06-16 21:16:57 +0100 |
commit | 5be498b1b22ba567fe6e62eb4a7d5a116f543952 (patch) | |
tree | a6fd15b02971673f1b8a1fb2560dfa876bcd16c4 /alot/crypto.py | |
parent | c39e7684769fa31ddd7d0200d5baa7e25476275d (diff) |
Verify OpenPGP signatures and display the result
Verify OpenPGP signatures as specified in RFC 3156. Display the result
in the header list above the message.
Signed-off-by: Justus Winter <4winter@informatik.uni-hamburg.de>
Diffstat (limited to 'alot/crypto.py')
-rw-r--r-- | alot/crypto.py | 18 |
1 files changed, 18 insertions, 0 deletions
diff --git a/alot/crypto.py b/alot/crypto.py index 6281ecfd..74f1f5c5 100644 --- a/alot/crypto.py +++ b/alot/crypto.py @@ -191,6 +191,24 @@ def encrypt(plaintext_str, keys=None): return encrypted +def verify_detached(message, signature): + '''Verifies whether the message is authentic by checking the + signature. + + :param message: the message as `str` + :param signature: a `str` containing an OpenPGP signature + :returns: a list of :class:`gpgme.Signature` + :raises: :class:`~alot.errors.GPGProblem` if the verification fails + ''' + message_data = StringIO(message) + signature_data = StringIO(signature) + ctx = gpgme.Context() + try: + return ctx.verify(signature_data, message_data, None) + except gpgme.GpgmeError as e: + raise GPGProblem(e.message, code=e.code) + + def hash_key(key): """ Returns a hash of the given key. This is a workaround for |