Skip to content

Commit f60fb4a

Browse files
committed
Metadata API: Tweak get_root_verification_result args
Change the "other" argument to optional "previous" and handle the None case in code. Signed-off-by: Jussi Kukkonen <jkukkonen@google.com>
1 parent b8dbe30 commit f60fb4a

2 files changed

Lines changed: 14 additions & 10 deletions

File tree

examples/repository/_simplerepo.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -99,11 +99,9 @@ def _get_verification_result(
9999
if role == Root.type:
100100
assert isinstance(md.signed, Root)
101101
root = self.root()
102-
if root.version == 0:
103-
# special case first root
104-
root = md.signed
102+
previous = root if root.version > 0 else None
105103
return md.signed.get_root_verification_result(
106-
root, md.signed_bytes, md.signatures
104+
previous, md.signed_bytes, md.signatures
107105
)
108106
if role in [Timestamp.type, Snapshot.type, Targets.type]:
109107
delegator: Signed = self.root()

tuf/api/metadata.py

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -965,30 +965,36 @@ def get_key(self, keyid: str) -> Key: # noqa: D102
965965

966966
def get_root_verification_result(
967967
self,
968-
other: "Root",
968+
previous: Optional["Root"],
969969
payload: bytes,
970970
signatures: Dict[str, Signature],
971971
) -> RootVerificationResult:
972972
"""Return signature threshold verification result for two root roles.
973973
974-
Verify root metadata with two roles (the root role from `self` and
975-
`other`). If you have only one role (in the case of root v1) you can
976-
provide the same Root as both `self` and `other`.
974+
Verify root metadata with two roles (`self` and optionally `previous`).
975+
976+
If the repository has no root role versions yet, `previous` can be left
977+
None. In all other cases, `previous` must be the previous version of
978+
the Root.
977979
978980
NOTE: Unlike `verify_delegate()` this method does not raise, if the
979981
root metadata is not fully verified.
980982
981983
Args:
982-
other: The other `Root` to verify payload with
984+
previous: The previous `Root` to verify payload with, or None
983985
payload: Signed payload bytes for root
984986
signatures: Signatures over payload bytes
985987
986988
Raises:
987989
ValueError: no delegation was found for ``delegated_role``.
988990
"""
991+
992+
if previous is None:
993+
previous = self
994+
989995
return RootVerificationResult(
990996
self.get_verification_result(Root.type, payload, signatures),
991-
other.get_verification_result(Root.type, payload, signatures),
997+
previous.get_verification_result(Root.type, payload, signatures),
992998
)
993999

9941000

0 commit comments

Comments
 (0)