From 4a532500e3a6130199a10622d17f10a247609f06 Mon Sep 17 00:00:00 2001 From: elijah Date: Mon, 18 Apr 2016 23:48:17 -0700 Subject: [bug] encryption keys can now be serialized to json using key.get_dict() --- src/leap/keymanager/keys.py | 14 ++++++++++++++ 1 file changed, 14 insertions(+) (limited to 'src/leap/keymanager') diff --git a/src/leap/keymanager/keys.py b/src/leap/keymanager/keys.py index 38d66b5..34d921c 100644 --- a/src/leap/keymanager/keys.py +++ b/src/leap/keymanager/keys.py @@ -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 -- cgit v1.2.3 From 0aecef293fd86507da3565219982ce31c5cfde06 Mon Sep 17 00:00:00 2001 From: Ruben Pollan Date: Mon, 25 Apr 2016 20:24:48 -0300 Subject: [feat] creat an iterator to build dicts Need pizza!!!!!! --- src/leap/keymanager/keys.py | 39 ++++++++++++++++++++++++++------------- 1 file changed, 26 insertions(+), 13 deletions(-) (limited to 'src/leap/keymanager') diff --git a/src/leap/keymanager/keys.py b/src/leap/keymanager/keys.py index 34d921c..1955d54 100644 --- a/src/leap/keymanager/keys.py +++ b/src/leap/keymanager/keys.py @@ -192,6 +192,11 @@ class EncryptionKey(object): __metaclass__ = ABCMeta + __slots__ = ('address', 'uids', 'fingerprint', 'key_data', + 'private', 'length', 'expiry_date', 'validation', + 'last_audited_at', 'refreshed_at', + 'encr_used', 'sign_used', '_index') + def __init__(self, address=None, uids=[], fingerprint="", key_data="", private=False, length=0, expiry_date=None, validation=ValidationLevels.Weak_Chain, last_audited_at=None, @@ -212,6 +217,7 @@ class EncryptionKey(object): self.refreshed_at = refreshed_at self.encr_used = encr_used self.sign_used = sign_used + self._index = len(self.__slots__) def get_json(self): """ @@ -258,19 +264,26 @@ 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 next(self): + if self._index == 0: + self._index = len(self.__slots__) + raise StopIteration + + self._index -= 1 + key = self.__slots__[self._index] + + if key.startswith('_'): + return self.next() + + value = getattr(self, key) + if key == "validation": + value = str(value) + elif key in ["expiry_date", "last_audited_at", "refreshed_at"]: + value = str(value) + return key, value + + def __iter__(self): + return self def __repr__(self): """ -- cgit v1.2.3