SecurityInnovation / PGPy

Pretty Good Privacy for Python
BSD 3-Clause "New" or "Revised" License
313 stars 98 forks source link

improve API for signatures and subkeys #451

Open dkg opened 1 year ago

dkg commented 1 year ago

On top of #450, this change makes the following API adjustments (from the diff in the changelog):

The following properties of PGPSignature now return None if the
corresponding subpacket is not present (they used to return an empty
string in that case):

* keyserver
* policy_uri
* signer
* signer_fingerprint

And the following properties of PGPSignature now return an
enum.IntFlag object instead of a set of custom FlagEnum objects.  When
the corresponding subpacket is not present at all, they return None:

* key_flags
* keyserverprefs
* features

PGPKey.subkeys now returns an OrderedDict indexed by Fingerprint
instead of KeyID.  When accessing this property via subscript (i.e.,
key.subkeys[x]), you can *also* index it by KeyID, but using a full
Fingerprint is recommended.

These underlying changes have a few advantages:

dkg commented 1 year ago

In addition to the API tune-up, with this PR applied, mypy pgpy returns no errors.

(mypy --strict pgpy still returns 1575 errors indicating that we don't have complete type coverage, but i'll work on fixing that in a subsequent PR)

dkg commented 1 year ago

Given that #450 is still a WIP, this is also a WIP. I'll remove "WIP" when it is a bit more stable, but i wanted to make clear the specific API changes i'm considering making.