Skip to content

Commit

Permalink
OpenPGP signatures: added test dir with example.
Browse files Browse the repository at this point in the history
  • Loading branch information
bernhardreiter committed May 31, 2016
1 parent 299e76c commit c69f478
Showing 1 changed file with 38 additions and 0 deletions.
38 changes: 38 additions & 0 deletions tests/test_sign.py
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()

0 comments on commit c69f478

Please sign in to comment.