[gnome-keysign: 1/6] Added split UIDs programme
- From: Tobias Mueller <tobiasmue src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-keysign: 1/6] Added split UIDs programme
- Date: Mon, 3 Feb 2020 13:22:38 +0000 (UTC)
commit a1d0de14d5f21fadf8d05898c64202a24ea2ca51
Author: Tobias Mueller <muelli cryptobitch de>
Date: Thu Dec 12 13:53:04 2019 +0100
Added split UIDs programme
You may want to split a key up into various files each containing a UID
of yours. This small tool helps you to achieve that. It's quite rough,
e.g. it does not yet have a nice --help output and the minimise option
cannot be given during invocation. That might change in the future,
though.
data/gnome-keysign-split-uids.man.rst | 47 +++++++++++++++++++++++++++++++++++
keysign/export_uids.py | 42 +++++++++++++++++++++++++++++++
keysign/gpgmeh.py | 6 ++++-
setup.py | 3 ++-
4 files changed, 96 insertions(+), 2 deletions(-)
---
diff --git a/data/gnome-keysign-split-uids.man.rst b/data/gnome-keysign-split-uids.man.rst
new file mode 100644
index 0000000..adc524f
--- /dev/null
+++ b/data/gnome-keysign-split-uids.man.rst
@@ -0,0 +1,47 @@
+
+==============
+GNOME-Keysign
+==============
+
+----------------------------------------------------
+Split an OpenPGP key up into various files each having one UID
+----------------------------------------------------
+
+:Date: 2019-12-12
+:Manual group: GNOME Keysign Manual
+:Manual section: 1
+:Version: 1
+
+SYNOPSIS
+========
+**gnome-keysign-split-uids**
+
+DESCRIPTION
+===========
+**gnome-keysign-split-uids** is a tool for splitting an OpenPGP into separate
+files such that each file contains one UID.
+
+
+OPTIONS
+=======
+
+You have to provide the name of the files which contains
+the key you want to have split up
+
+ENVIRONMENT
+===========
+
+See **gnome-keysign**
+
+FILES
+=====
+
+See **gnome-keysign**
+
+
+
+SEE ALSO
+========
+gpg(1)
+gnome-keysign(1)
+
diff --git a/keysign/export_uids.py b/keysign/export_uids.py
new file mode 100644
index 0000000..31b85a4
--- /dev/null
+++ b/keysign/export_uids.py
@@ -0,0 +1,42 @@
+#!/usr/bin/env python3
+
+import logging
+from pathlib import Path
+import os
+import sys
+
+if __name__ == "__main__" and __package__ is None:
+ logging.getLogger().error("You seem to be trying to execute " +
+ "this script directly which is discouraged. " +
+ "Try python -m instead.")
+ parent_dir = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
+ os.sys.path.insert(0, parent_dir)
+ import keysign
+ #mod = __import__('keysign')
+ #sys.modules["keysign"] = mod
+ __package__ = str('keysign')
+
+
+from .gpgmeh import export_uids, minimise_key
+
+def escape_filename(fname):
+ escaped = ''.join(c if c.isalnum() else "_" for c in fname)
+ return escaped
+
+def main():
+ fname = sys.argv[1]
+ keydata = open(fname, 'rb').read()
+
+ minimise = True
+ if minimise:
+ keydata = minimise_key(keydata)
+
+ for i, (uid, uid_bytes) in enumerate(export_uids(keydata), start=1):
+ uid_file = Path('.') / ("{:02d}-".format(i) + escape_filename(uid) + ".pgp.asc")
+ print (f"Writing {uid_file}...")
+ uid_file.write_bytes(uid_bytes)
+
+ print (f"Done!")
+
+if __name__ == "__main__":
+ main()
diff --git a/keysign/gpgmeh.py b/keysign/gpgmeh.py
index 2eb9de1..88262e7 100755
--- a/keysign/gpgmeh.py
+++ b/keysign/gpgmeh.py
@@ -206,7 +206,11 @@ def UIDExport(keydata, uid_i):
return uid_bytes
def export_uids(keydata):
- """Export each valid and non-revoked UID of a key"""
+ """Export each valid and non-revoked UID of a key
+
+ Returns: An iterator over a tuple of the UID, i.e. the string and
+ the bytes making the OpenPGP with that UID only.
+ """
ctx = TempContext()
ctx.op_import(keydata)
result = ctx.op_import_result()
diff --git a/setup.py b/setup.py
index 456f967..abaeaa2 100644
--- a/setup.py
+++ b/setup.py
@@ -150,7 +150,8 @@ setup(
entry_points = {
'console_scripts': [
- 'gnome-keysign-sign-key = keysign.SignKey:main'
+ 'gnome-keysign-sign-key = keysign.SignKey:main',
+ 'gnome-keysign-split-uids = keysign.export_uids:main',
],
'gui_scripts': [
'gnome-keysign = keysign:main',
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]