summaryrefslogtreecommitdiff
path: root/src/mailman_pgp/utils/pgp.py
diff options
context:
space:
mode:
Diffstat (limited to 'src/mailman_pgp/utils/pgp.py')
-rw-r--r--src/mailman_pgp/utils/pgp.py29
1 files changed, 29 insertions, 0 deletions
diff --git a/src/mailman_pgp/utils/pgp.py b/src/mailman_pgp/utils/pgp.py
index 7b2f958..0e1e75c 100644
--- a/src/mailman_pgp/utils/pgp.py
+++ b/src/mailman_pgp/utils/pgp.py
@@ -16,6 +16,7 @@
# this program. If not, see <http://www.gnu.org/licenses/>.
"""Miscellaneous PGP utilities."""
+from pgpy import PGPKey
from public import public
@@ -47,3 +48,31 @@ def hashes(verifications):
hasher = sigsubj.signature.hash_algorithm.hasher
hasher.update(data)
yield hasher.digest()
+
+
+@public
+def key_from_blob(blob):
+ """
+
+ :param blob:
+ :return:
+ """
+ keys = PGPKey.from_blob(blob)
+ if isinstance(keys, tuple):
+ return keys[0]
+ else:
+ return keys
+
+
+@public
+def key_from_file(file):
+ """
+
+ :param file:
+ :return:
+ """
+ keys = PGPKey.from_file(file)
+ if isinstance(keys, tuple):
+ return keys[0]
+ else:
+ return keys