Skip to content

Commit

Permalink
OpenPGP signatures: added speed test.
Browse files Browse the repository at this point in the history
  • Loading branch information
bernhardreiter committed Jun 2, 2016
1 parent e9afbe5 commit 4ae9b3e
Showing 1 changed file with 32 additions and 0 deletions.
32 changes: 32 additions & 0 deletions tests/test_sign.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
* Bernhard E. Reiter <bernhard@intevation.de>
"""

from timeit import default_timer as timer
import unittest
from io import BytesIO

Expand Down Expand Up @@ -53,3 +54,34 @@ def test_sign_nomime(self):
self.assertEqual(len(sigs), 1)
vsig = vsigs[0]
self.assertEqual(vsig.fpr, '5F503EFAC8C89323D54C252591B8CD7E15925678')

def test_speed(self):
email_body = """Hello,
this is my email body,
which shall be signed."""

ctx = gpgme.Context()
key = ctx.get_key('5F50 3EFA C8C8 9323 D54C 2525 91B8 CD7E 1592 5678')
ctx.signers = [key]

plaintext = BytesIO(email_body.encode())
signature = BytesIO()

start = timer()
n = 100
for i in range(n):
plaintext.seek(0)
signature.seek(0)

sigs = ctx.sign(plaintext, signature, gpgme.SIG_MODE_CLEAR)
self.assertEqual(len(sigs), 1)
sig = sigs[0]
self.assertEqual(sig.type, gpgme.SIG_MODE_CLEAR)
self.assertIsInstance(sig, gpgme.NewSignature)
end = timer()
time_spent = end - start # in fractions of seconds
#print("\nTime elapsed for {:d} iterations: {:.3f}".format(n, time_spent))
#print("That is {:.1f} signatures per second.".format(n/time_spent))
#we want to process at least 12 per second
self.assertTrue(n/time_spent > 12)

0 comments on commit 4ae9b3e

Please sign in to comment.