Skip to content

Commit

Permalink
signer API: Fix unrecognized_fields
Browse files Browse the repository at this point in the history
* do not check falsyness of argument containers: the results are
  unexpected if the argument container is empty
* Do not use Mapping annotation for unrecognized_fields. The original
  idea was that Metadata API is not changing them: this is true but we
  don't want to prevent users from modifying the fields...
  • Loading branch information
jku committed Nov 30, 2022
1 parent 98442f5 commit 10edc1a
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 4 deletions.
6 changes: 5 additions & 1 deletion securesystemslib/signer/_key.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,11 @@ def __init__(
self.keytype = keytype
self.scheme = scheme
self.keyval = keyval
self.unrecognized_fields = unrecognized_fields or {}

if unrecognized_fields is None:
unrecognized_fields = {}

self.unrecognized_fields = unrecognized_fields

def __eq__(self, other: Any) -> bool:
if not isinstance(other, Key):
Expand Down
10 changes: 7 additions & 3 deletions securesystemslib/signer/_signature.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
"""Signature container class"""

import logging
from typing import Any, Dict, Mapping, Optional
from typing import Any, Dict, Optional

logger = logging.getLogger(__name__)

Expand All @@ -27,11 +27,15 @@ def __init__(
self,
keyid: str,
sig: str,
unrecognized_fields: Optional[Mapping[str, Any]] = None,
unrecognized_fields: Optional[Dict[str, Any]] = None,
):
self.keyid = keyid
self.signature = sig
self.unrecognized_fields: Mapping[str, Any] = unrecognized_fields or {}

if unrecognized_fields is None:
unrecognized_fields = {}

self.unrecognized_fields = unrecognized_fields

def __eq__(self, other: Any) -> bool:
if not isinstance(other, Signature):
Expand Down

0 comments on commit 10edc1a

Please sign in to comment.