MCPcopy Create free account
hub / github.com/SecurityInnovation/PGPy / unload

Method unload

pgpy/pgp.py:2857–2886  ·  view source on GitHub ↗

Unload a loaded key and its subkeys. :param key: The key to unload. :type key: :py:obj:`PGPKey` The easiest way to do this is to select a key using :py:meth:`PGPKeyring.key` first:: with keyring.key("DSA von TestKey") as key: keyring.un

(self, key)

Source from the content-addressed store, hash-verified

2855 False if keyhalf in ['private', 'any'] else None]}
2856
2857 def unload(self, key):
2858 """
2859 Unload a loaded key and its subkeys.
2860
2861 :param key: The key to unload.
2862 :type key: :py:obj:`PGPKey`
2863
2864 The easiest way to do this is to select a key using :py:meth:`PGPKeyring.key` first::
2865
2866 with keyring.key("DSA von TestKey") as key:
2867 keyring.unload(key)
2868 """
2869 assert isinstance(key, PGPKey)
2870 pkid = id(key)
2871 if pkid in self._keys:
2872 # remove references
2873 [ kd.remove(pkid) for kd in [self._pubkeys, self._privkeys] if pkid in kd ]
2874 # remove the key
2875 self._keys.pop(pkid)
2876
2877 # remove aliases
2878 for m, a in [ (m, a) for m in self._aliases for a, p in m.items() if p == pkid ]:
2879 m.pop(a)
2880 # do a re-sort of this alias if it was not unique
2881 if a in self:
2882 self._sort_alias(a)
2883
2884 # if key is a primary key, unload its subkeys as well
2885 if key.is_primary:
2886 [ self.unload(sk) for sk in key.subkeys.values() ]

Callers 2

test_unload_keyMethod · 0.80
test_unload_key_halfMethod · 0.80

Calls 1

_sort_aliasMethod · 0.95

Tested by 2

test_unload_keyMethod · 0.64
test_unload_key_halfMethod · 0.64