--- /dev/null
+#!/usr/bin/python
+
+import subprocess as _subprocess
+import struct as _struct
+
+
+def _get_stdout(args, stdin=None):
+ stdin_pipe = None
+ if stdin is not None:
+ stdin_pipe = _subprocess.PIPE
+ p = _subprocess.Popen(args, stdin=stdin_pipe, stdout=_subprocess.PIPE)
+ stdout, stderr = p.communicate(stdin)
+ status = p.wait()
+ if status != 0:
+ raise RuntimeError(status)
+ return stdout
+
+
+class PGPPacket (dict):
+ # http://tools.ietf.org/search/rfc4880
+ def from_bytes(self, data):
+ pass
+
+ def to_bytes(self):
+ pass
+
+
+def migrate(old_key, new_key):
+ """Add the old key and sub-keys to the new key
+
+ For example, to upgrade your master key, while preserving old
+ signatures you'd made. You will lose signature *on* your old key
+ though, since sub-keys can't be signed (I don't think).
+ """
+ old_key_export = _get_stdout(
+ ['gpg', '--export', old_key])
+ old_key_packet = PGPPacket()
+ old_key_packet.from_bytes(data=old_key_export)
+ old_key_secret_export = _get_stdout(
+ ['gpg', '--export-secret-keys', old_key])
+ old_key_secret_packet = PGPPacket()
+ old_key_secret_packet.from_bytes(data=old_key_secret_export)
+
+ import pprint
+ pprint.pprint(old_key_packet)
+ pprint.pprint(old_key_secret_packet)
+
+
+if __name__ == '__main__':
+ import sys as _sys
+
+ old_key, new_key = _sys.argv[1:3]
+ migrate(old_key=old_key, new_key=new_key)