Skip to content

Commit

Permalink
Metadata API: Add Key attributes types validation
Browse files Browse the repository at this point in the history
In our discussion with Jussi we come to the conclusion that we want
to verify that all Key attributes contain values in the expected types,
but at the same time, we don't want to focus on validating the semantics
behind them.
The reason is that having a Key instance with invalid attributes is
possible and supported by the spec.
That's why we have a "threshold" for the roles meaning we can have up to
a certain number of invalid Keys until we satisfy
the required threshold.

Also, for deeper semantic validation it's better to be done in
securesystemslib which does the actual work with keys.

For context see: #1438

Signed-off-by: Martin Vrachev <mvrachev@vmware.com>
  • Loading branch information
MVrachev committed Jun 15, 2021
1 parent de78251 commit f20664d
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion tuf/api/metadata.py
Original file line number Diff line number Diff line change
Expand Up @@ -398,8 +398,15 @@ def __init__(
keyval: Dict[str, str],
unrecognized_fields: Optional[Mapping[str, Any]] = None,
) -> None:
if not keyval.get("public"):
public_val = keyval.get("public")
if not public_val or not isinstance(public_val, str):
raise ValueError("keyval doesn't follow the specification format!")
if not isinstance(scheme, str):
raise ValueError("scheme should be a string!")
if not isinstance(keytype, str):
raise ValueError("keytype should be a string!")
if not isinstance(keyid, str):
raise ValueError("keyid should be a string!")
self.keyid = keyid
self.keytype = keytype
self.scheme = scheme
Expand Down

0 comments on commit f20664d

Please sign in to comment.