Skip to content

Commit f20664d

Browse files
committed
Metadata API: Add Key attributes types validation
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>
1 parent de78251 commit f20664d

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

tuf/api/metadata.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -398,8 +398,15 @@ def __init__(
398398
keyval: Dict[str, str],
399399
unrecognized_fields: Optional[Mapping[str, Any]] = None,
400400
) -> None:
401-
if not keyval.get("public"):
401+
public_val = keyval.get("public")
402+
if not public_val or not isinstance(public_val, str):
402403
raise ValueError("keyval doesn't follow the specification format!")
404+
if not isinstance(scheme, str):
405+
raise ValueError("scheme should be a string!")
406+
if not isinstance(keytype, str):
407+
raise ValueError("keytype should be a string!")
408+
if not isinstance(keyid, str):
409+
raise ValueError("keyid should be a string!")
403410
self.keyid = keyid
404411
self.keytype = keytype
405412
self.scheme = scheme

0 commit comments

Comments
 (0)