-
Notifications
You must be signed in to change notification settings - Fork 292
Make hashes, length and delegations optional + improvements #1367
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -511,16 +511,19 @@ class Root(Signed): | |
| supports consistent snapshots. | ||
| keys: A dictionary that contains a public key store used to verify | ||
| top level roles metadata signatures:: | ||
| { | ||
| '<KEYID>': <Key instance>, | ||
| ... | ||
| }, | ||
MVrachev marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| { | ||
| '<KEYID>': <Key instance>, | ||
| ... | ||
| }, | ||
|
|
||
| roles: A dictionary that contains a list of signing keyids and | ||
| a signature threshold for each top level role:: | ||
| { | ||
| '<ROLE>': <Role istance>, | ||
| ... | ||
| } | ||
|
|
||
| { | ||
| '<ROLE>': <Role istance>, | ||
| ... | ||
| } | ||
|
|
||
| """ | ||
|
|
||
|
|
@@ -612,7 +615,7 @@ class Timestamp(Signed): | |
| '<HASH ALGO 1>': '<SNAPSHOT METADATA FILE HASH 1>', | ||
| '<HASH ALGO 2>': '<SNAPSHOT METADATA FILE HASH 2>', | ||
| ... | ||
| } | ||
| } // optional | ||
| } | ||
| } | ||
|
|
||
|
|
@@ -648,14 +651,19 @@ def to_dict(self) -> Dict[str, Any]: | |
|
|
||
| # Modification. | ||
| def update( | ||
| self, version: int, length: int, hashes: Mapping[str, Any] | ||
| self, | ||
| version: int, | ||
| length: Optional[int] = None, | ||
| hashes: Optional[Mapping[str, Any]] = None, | ||
| ) -> None: | ||
| """Assigns passed info about snapshot metadata to meta dict.""" | ||
| self.meta["snapshot.json"] = { | ||
| "version": version, | ||
| "length": length, | ||
| "hashes": hashes, | ||
| } | ||
| self.meta["snapshot.json"] = {"version": version} | ||
|
|
||
| if length is not None: | ||
| self.meta["snapshot.json"]["length"] = length | ||
|
|
||
| if hashes is not None: | ||
| self.meta["snapshot.json"]["hashes"] = hashes | ||
|
Comment on lines
+660
to
+666
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit: Not a huge fan of three separate lookups of "snapshot.json" key... it's not a major deal here, just pointing it out
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I imagine this would be something we would change when we fix #1333.
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't think that's related: you don't need more than a single lookup even now but it is a small detail |
||
|
|
||
|
|
||
| class Snapshot(Signed): | ||
|
|
@@ -755,34 +763,34 @@ class Targets(Signed): | |
| roles and public key store used to verify their metadata | ||
| signatures:: | ||
|
|
||
| { | ||
| 'keys' : { | ||
| '<KEYID>': { | ||
| 'keytype': '<KEY TYPE>', | ||
| 'scheme': '<KEY SCHEME>', | ||
| 'keyid_hash_algorithms': [ | ||
| '<HASH ALGO 1>', | ||
| '<HASH ALGO 2>' | ||
| ... | ||
| ], | ||
| 'keyval': { | ||
| 'public': '<PUBLIC KEY HEX REPRESENTATION>' | ||
| } | ||
| { | ||
| 'keys' : { | ||
| '<KEYID>': { | ||
| 'keytype': '<KEY TYPE>', | ||
| 'scheme': '<KEY SCHEME>', | ||
| 'keyid_hash_algorithms': [ | ||
| '<HASH ALGO 1>', | ||
| '<HASH ALGO 2>' | ||
| ... | ||
| ], | ||
| 'keyval': { | ||
| 'public': '<PUBLIC KEY HEX REPRESENTATION>' | ||
| } | ||
| }, | ||
| ... | ||
| }, | ||
| 'roles': [ | ||
| { | ||
| 'name': '<ROLENAME>', | ||
| 'keyids': ['<SIGNING KEY KEYID>', ...], | ||
| 'threshold': <SIGNATURE THRESHOLD>, | ||
| 'terminating': <TERMINATING BOOLEAN>, | ||
| 'path_hash_prefixes': ['<HEX DIGEST>', ... ], // or | ||
| 'paths' : ['PATHPATTERN', ... ], | ||
| }, | ||
| ... | ||
| }, | ||
| 'roles': [ | ||
| { | ||
| 'name': '<ROLENAME>', | ||
| 'keyids': ['<SIGNING KEY KEYID>', ...], | ||
| 'threshold': <SIGNATURE THRESHOLD>, | ||
| 'terminating': <TERMINATING BOOLEAN>, | ||
| 'path_hash_prefixes': ['<HEX DIGEST>', ... ], // or | ||
| 'paths' : ['PATHPATTERN', ... ], | ||
| }, | ||
| ... | ||
| ] | ||
| } | ||
| ] | ||
| } | ||
|
|
||
| """ | ||
|
|
||
|
|
@@ -798,7 +806,7 @@ def __init__( | |
| spec_version: str, | ||
| expires: datetime, | ||
| targets: Mapping[str, Any], | ||
| delegations: Mapping[str, Any], | ||
| delegations: Optional[Mapping[str, Any]] = None, | ||
| unrecognized_fields: Optional[Mapping[str, Any]] = None, | ||
| ) -> None: | ||
| super().__init__(version, spec_version, expires, unrecognized_fields) | ||
|
|
@@ -811,19 +819,16 @@ def from_dict(cls, targets_dict: Mapping[str, Any]) -> "Targets": | |
| """Creates Targets object from its dict representation.""" | ||
| common_args = cls._common_fields_from_dict(targets_dict) | ||
| targets = targets_dict.pop("targets") | ||
| delegations = targets_dict.pop("delegations") | ||
| delegations = targets_dict.pop("delegations", None) | ||
| # All fields left in the targets_dict are unrecognized. | ||
| return cls(*common_args, targets, delegations, targets_dict) | ||
|
|
||
| def to_dict(self) -> Dict[str, Any]: | ||
| """Returns the dict representation of self.""" | ||
| targets_dict = self._common_fields_to_dict() | ||
| targets_dict.update( | ||
| { | ||
| "targets": self.targets, | ||
| "delegations": self.delegations, | ||
| } | ||
| ) | ||
| targets_dict["targets"] = self.targets | ||
| if self.delegations: | ||
| targets_dict["delegations"] = self.delegations | ||
| return targets_dict | ||
|
|
||
| # Modification. | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.