Skip to content

Instantly share code, notes, and snippets.

@J08nY
Last active August 4, 2017 21:35
Show Gist options
  • Save J08nY/dc91e71801179ee0bf2bb32706fcfa23 to your computer and use it in GitHub Desktop.
Save J08nY/dc91e71801179ee0bf2bb32706fcfa23 to your computer and use it in GitHub Desktop.
def _can_revoke(revoker, target_primary):
for self_sig in target_primary.self_signatures:
for rk in self_sig.revocation_key:
if rk.algorithm == revoker.key_algorithm and rk.fingerprint == revoker.fingerprint:
return True
return False
hash_algo = prefs.pop('hash', None)
sig_type = None
if isinstance(target, PGPUID):
sig_type = SignatureType.CertRevocation
elif isinstance(target, PGPKey):
# Check that we are revoking a key we can revoke.
if target.is_primary:
if target.fingerprint == self.fingerprint or _can_revoke(self, target):
sig_type = SignatureType.KeyRevocation
else:
if target in self or _can_revoke(self, target.parent):
sig_type = SignatureType.SubkeyRevocation
else: # pragma: no cover
raise TypeError
if sig_type is None:
raise PGPError("Can't revoke the given key with this key.")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment