Skip to content

Commit 43f8fa9

Browse files
committed
Metadata API: Add a comment for Key validation
Clarify that we don't semantically validate "Key" instances during initialization and that this is a responsibility of securesystemslib. Signed-off-by: Martin Vrachev <[email protected]>
1 parent f20664d commit 43f8fa9

File tree

1 file changed

+5
-9
lines changed

1 file changed

+5
-9
lines changed

tuf/api/metadata.py

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -376,6 +376,8 @@ def bump_version(self) -> None:
376376

377377
class Key:
378378
"""A container class representing the public portion of a Key.
379+
Please note that "Key" instances are not semanticly validated during
380+
initialization. We consider this as responsibility of securesystemslib.
379381
380382
Attributes:
381383
keyid: An identifier string that must uniquely identify a key within
@@ -398,15 +400,9 @@ def __init__(
398400
keyval: Dict[str, str],
399401
unrecognized_fields: Optional[Mapping[str, Any]] = None,
400402
) -> None:
401-
public_val = keyval.get("public")
402-
if not public_val or not isinstance(public_val, str):
403-
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!")
403+
val = keyval.get("public")
404+
if not all(isinstance(at, str) for at in [keyid, keytype, scheme, val]):
405+
raise ValueError("Attributes don't follow the type annotations!")
410406
self.keyid = keyid
411407
self.keytype = keytype
412408
self.scheme = scheme

0 commit comments

Comments
 (0)