Skip to content

Commit 161c3e3

Browse files
committed
Metadata API: Add VerificationResult.missing
This is helper to tell how many signatures are still required. Also change the order of Roots given to RootVerificationResult (this way first is version N, second is version N+1). Signed-off-by: Jussi Kukkonen <jkukkonen@google.com>
1 parent b158c08 commit 161c3e3

1 file changed

Lines changed: 8 additions & 2 deletions

File tree

tuf/api/metadata.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -669,6 +669,11 @@ def verified(self) -> bool:
669669
"""True if threshold of signatures is met."""
670670
return len(self.signed) >= self.threshold
671671

672+
@property
673+
def missing(self) -> int:
674+
"""Number of additional signatures required to reach threshold."""
675+
return max(0, self.threshold - len(self.signed))
676+
672677

673678
@dataclass
674679
class RootVerificationResult:
@@ -995,11 +1000,12 @@ def get_root_verification_result(
9951000
elif self.version != previous.version + 1:
9961001
versions = f"v{previous.version} and v{self.version}"
9971002
raise ValueError(
998-
f"Expected sequential root versions, got {versions}.")
1003+
f"Expected sequential root versions, got {versions}."
1004+
)
9991005

10001006
return RootVerificationResult(
1001-
self.get_verification_result(Root.type, payload, signatures),
10021007
previous.get_verification_result(Root.type, payload, signatures),
1008+
self.get_verification_result(Root.type, payload, signatures),
10031009
)
10041010

10051011

0 commit comments

Comments
 (0)