Skip to content

Instantly share code, notes, and snippets.

@Commod0re
Forked from J08nY/revocation_logic.py
Last active August 4, 2017 21:48
Show Gist options
  • Save Commod0re/46026d6c01bfb4a202303e727f8a1438 to your computer and use it in GitHub Desktop.
Save Commod0re/46026d6c01bfb4a202303e727f8a1438 to your computer and use it in GitHub Desktop.
def _can_revoke(revoker, target):
if revoker.is_primary and revoker.fingerprint == target.fingerprint:
return True
self_sigs = target.self_signatures if target.is_primary else target.parent.self_signatures
for self_sig in self_sigs:
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 _can_revoke(self, target):
sig_type = SignatureType.KeyRevocation if target.is_primary else sig_type = Signature.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