Skip to content

Commit

Permalink
PGPSignature API change: keyserver,policy_uri return None if no subpa…
Browse files Browse the repository at this point in the history
…cket present

This is a change in the API to more accurately reflect what is
happening in a signature.  It's possible to have a subpacket that
contains the empty string, and this allows a consumer to distinguish
between the two cases.
  • Loading branch information
dkg committed Jun 15, 2023
1 parent f66947a commit 0cb07d6
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 8 deletions.
2 changes: 2 additions & 0 deletions docs/source/changelog.rst
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ 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

Expand Down
12 changes: 6 additions & 6 deletions pgpy/pgp.py
Original file line number Diff line number Diff line change
Expand Up @@ -214,13 +214,13 @@ def key_flags(self):
return set()

@property
def keyserver(self):
def keyserver(self) -> Optional[str]:
"""
The preferred key server specified in this signature, if any. Otherwise, an empty ``str``.
The preferred key server specified in this signature, if any. Otherwise, None.
"""
if 'PreferredKeyServer' in self._signature.subpackets:
return next(iter(self._signature.subpackets['h_PreferredKeyServer'])).uri
return ''
return None

@property
def keyserverprefs(self):
Expand All @@ -243,13 +243,13 @@ def notation(self):
return {nd.name: nd.value for nd in self._signature.subpackets['NotationData']}

@property
def policy_uri(self):
def policy_uri(self) -> Optional[str]:
"""
The policy URI specified in this signature, if any. Otherwise, an empty ``str``.
The policy URI specified in this signature, if any. Otherwise, None.
"""
if 'Policy' in self._signature.subpackets:
return next(iter(self._signature.subpackets['Policy'])).uri
return ''
return None

@property
def revocable(self) -> bool:
Expand Down
4 changes: 2 additions & 2 deletions tests/test_03_armor.py
Original file line number Diff line number Diff line change
Expand Up @@ -199,11 +199,11 @@
('is_expired', False),
('key_algorithm', PubKeyAlgorithm.RSAEncryptOrSign),
('key_flags', set()),
('keyserver', ''),
('keyserverprefs', []),
('keyserver', None),
('magic', "SIGNATURE"),
('notation', {}),
('policy_uri', ''),
('policy_uri', None),
('revocable', True),
('revocation_key', None),
('signer', KeyID('FCAE54F74BA27CF7')),
Expand Down

0 comments on commit 0cb07d6

Please sign in to comment.