Revoke a key, a subkey, or all current certification signatures of a User ID that were generated by this key so far. :param target: The key to revoke :type target: :py:obj:`PGPKey`, :py:obj:`PGPUID` :raises: :py:exc:`~pgpy.errors.PGPError` if the key is passphrase-p
(self, target, **prefs)
| 2223 | |
| 2224 | @KeyAction(KeyFlags.Certify, is_unlocked=True, is_public=False) |
| 2225 | def revoke(self, target, **prefs): |
| 2226 | """ |
| 2227 | Revoke a key, a subkey, or all current certification signatures of a User ID that were generated by this key so far. |
| 2228 | |
| 2229 | :param target: The key to revoke |
| 2230 | :type target: :py:obj:`PGPKey`, :py:obj:`PGPUID` |
| 2231 | :raises: :py:exc:`~pgpy.errors.PGPError` if the key is passphrase-protected and has not been unlocked |
| 2232 | :raises: :py:exc:`~pgpy.errors.PGPError` if the key is public |
| 2233 | :returns: :py:obj:`PGPSignature` |
| 2234 | |
| 2235 | In addition to the optional keyword arguments accepted by :py:meth:`PGPKey.sign`, the following optional |
| 2236 | keyword arguments can be used with :py:meth:`PGPKey.revoke`. |
| 2237 | |
| 2238 | :keyword reason: Defaults to :py:obj:`constants.RevocationReason.NotSpecified` |
| 2239 | :type reason: One of :py:obj:`constants.RevocationReason`. |
| 2240 | :keyword comment: Defaults to an empty string. |
| 2241 | :type comment: ``str`` |
| 2242 | """ |
| 2243 | hash_algo = prefs.pop('hash', None) |
| 2244 | if isinstance(target, PGPUID): |
| 2245 | sig_type = SignatureType.CertRevocation |
| 2246 | |
| 2247 | elif isinstance(target, PGPKey): |
| 2248 | ##TODO: check to make sure that the key that is being revoked: |
| 2249 | # - is this key |
| 2250 | # - is one of this key's subkeys |
| 2251 | # - specifies this key as its revocation key |
| 2252 | if target.is_primary: |
| 2253 | sig_type = SignatureType.KeyRevocation |
| 2254 | |
| 2255 | else: |
| 2256 | sig_type = SignatureType.SubkeyRevocation |
| 2257 | |
| 2258 | else: # pragma: no cover |
| 2259 | raise TypeError |
| 2260 | |
| 2261 | sig = PGPSignature.new(sig_type, self.key_algorithm, hash_algo, self.fingerprint.keyid, created=prefs.pop('created', None)) |
| 2262 | |
| 2263 | # signature options that only make sense when revoking |
| 2264 | reason = prefs.pop('reason', RevocationReason.NotSpecified) |
| 2265 | comment = prefs.pop('comment', "") |
| 2266 | sig._signature.subpackets.addnew('ReasonForRevocation', hashed=True, code=reason, string=comment) |
| 2267 | |
| 2268 | return self._sign(target, sig, **prefs) |
| 2269 | |
| 2270 | @KeyAction(is_unlocked=True, is_public=False) |
| 2271 | def revoker(self, revoker, **prefs): |