[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]
[tor-commits] [bridgedb/master] Add crypto.gpgSignMessage() utility function.
commit b2c7a2a20ca07dec8dd7c9a812f8173127c45b3a
Author: Isis Lovecruft <isis@xxxxxxxxxxxxxx>
Date: Wed Apr 16 22:41:48 2014 +0000
Add crypto.gpgSignMessage() utility function.
---
lib/bridgedb/EmailServer.py | 1 +
lib/bridgedb/crypto.py | 26 ++++++++++++++++++++++++++
2 files changed, 27 insertions(+)
diff --git a/lib/bridgedb/EmailServer.py b/lib/bridgedb/EmailServer.py
index eed96bf..65a3ccd 100644
--- a/lib/bridgedb/EmailServer.py
+++ b/lib/bridgedb/EmailServer.py
@@ -29,6 +29,7 @@ from bridgedb import Dist
from bridgedb import I18n
from bridgedb import safelog
from bridgedb.crypto import getGPGContext
+from bridgedb.crypto import gpgSignMessage
from bridgedb.Filters import filterBridgesByIP6
from bridgedb.Filters import filterBridgesByIP4
from bridgedb.Filters import filterBridgesByTransport
diff --git a/lib/bridgedb/crypto.py b/lib/bridgedb/crypto.py
index 5c68794..ebab733 100644
--- a/lib/bridgedb/crypto.py
+++ b/lib/bridgedb/crypto.py
@@ -347,6 +347,32 @@ def getGPGContext(cfg):
return ctx
+def gpgSignMessage(gpgmeCtx, messageString, mode=None):
+ """Sign a **messageString** with a GPGME context.
+
+ :param gpgmeCtx: A ``gpgme.Context`` initialised with the appropriate
+ settings.
+ :param str messageString: The message to sign.
+ :param mode: The signing mode. (default: ``gpgme.SIG_MODE_CLEAR``)
+ :rtype: tuple
+ :returns: A 2-tuple of ``(signature, list)``, where:
+ * ``signature`` is the ascii-armored signature text.
+ * ``list`` is a list of ``gpgme.NewSignature``s.
+
+ .. warning:: The returned signature text and list *may* be empty, if no
+ signature was created.
+ """
+ if not mode:
+ mode = gpgme.SIG_MODE_CLEAR
+
+ msgFile = io.StringIO(unicode(messageString))
+ sigFile = io.StringIO()
+ sigList = gpgmeCtx.sign(msgFile, sigFile, mode)
+ sigFile.seek(0)
+ signature = sigFile.read()
+
+ return (signature, sigList)
+
class SSLVerifyingContextFactory(ssl.CertificateOptions):
"""``OpenSSL.SSL.Context`` factory which does full certificate-chain and
_______________________________________________
tor-commits mailing list
tor-commits@xxxxxxxxxxxxxxxxxxxx
https://lists.torproject.org/cgi-bin/mailman/listinfo/tor-commits