[bug] encryption keys can now be serialized to json using key.get_dict()
authorelijah <elijah@riseup.net>
Tue, 19 Apr 2016 06:48:17 +0000 (23:48 -0700)
committerKali Kaneko (leap communications) <kali@leap.se>
Tue, 19 Apr 2016 16:16:23 +0000 (12:16 -0400)
changes/bug-serializable-keys [new file with mode: 0644]
src/leap/keymanager/keys.py

diff --git a/changes/bug-serializable-keys b/changes/bug-serializable-keys
new file mode 100644 (file)
index 0000000..0885fd2
--- /dev/null
@@ -0,0 +1 @@
+- encryption keys can now be serialized to json using key.get_dict()
index 38d66b5..34d921c 100644 (file)
@@ -258,6 +258,20 @@ class EncryptionKey(object):
             KEY_TAGS_KEY: [KEYMANAGER_ACTIVE_TAG],
         })
 
+    def get_dict(self):
+        """
+        :return: a serializable dict representation of this key.
+        :rtype: dict
+        """
+        return {
+          KEY_ADDRESS_KEY: self.address,
+          KEY_UIDS_KEY: self.uids,
+          KEY_FINGERPRINT_KEY: self.fingerprint,
+          KEY_LENGTH_KEY: self.length,
+          KEY_EXPIRY_DATE_KEY: str(self.expiry_date),
+          KEY_DATA_KEY: self.key_data
+        }
+
     def __repr__(self):
         """
         Representation of this class