-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
OpenPGP signatures: added test dir with example.
- Loading branch information
1 parent
299e76c
commit c69f478
Showing
1 changed file
with
38 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
#!/usr/bin/env python3 | ||
# -*- coding: utf-8 -*- | ||
"""Test how to OpenPGP sign data for emails. | ||
First revision without test framework to be directly run. | ||
Dependencies: | ||
* pygpgme build for python3 | ||
Authors: | ||
* Bernhard E. Reiter <bernhard@intevation.de> | ||
""" | ||
|
||
import gpgme | ||
from io import BytesIO | ||
|
||
def test_sign_nomime(): | ||
#TODO setup a separate GNUPGHOME | ||
email_body = """Hello, | ||
this is my email body, | ||
which shall be signed.""" | ||
|
||
ctx = gpgme.Context() | ||
|
||
#TODO create or find test-key | ||
key = ctx.get_key('2E17923D761D9154B2C1A1763C43F4C8EFF5D42A') | ||
ctx.signers = [key] | ||
|
||
#plaintext = BytesIO(b"Hello World!") | ||
plaintext = BytesIO(email_body.encode()) | ||
signature = BytesIO() | ||
sig = ctx.sign(plaintext, signature, gpgme.SIG_MODE_CLEAR) | ||
|
||
signature.seek(0) | ||
print(signature.read().decode(), sig[0]) | ||
|
||
if __name__ == "__main__": | ||
test_sign_nomime() |