Skip to content

Commit

Permalink
Fix importing goSWID XML when there is more than one identity
Browse files Browse the repository at this point in the history
  • Loading branch information
hughsie committed Sep 18, 2023
1 parent 2048b37 commit b59eecd
Showing 1 changed file with 13 additions and 9 deletions.
22 changes: 13 additions & 9 deletions uswid/format_goswid.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ def load(self, blob: bytes) -> uSwidContainer:
container = uSwidContainer()
for identity_json in data:
identity = uSwidIdentity()
self._load_identity(identity, identity_json)
self._load_identity_internal(identity, identity_json)
container.merge(identity)
return container

Expand Down Expand Up @@ -173,14 +173,9 @@ def _load_entity(
)
) from e

def _load_identity(self, identity: uSwidIdentity, blob: bytes) -> None:
"""imports a uSwidIdentity goSWID blob"""

try:
data: Dict[str, Any] = json.loads(blob)
except json.decoder.JSONDecodeError as e:
raise NotSupportedError("invalid goSWID: {}".format(e)) from e

def _load_identity_internal(
self, identity: uSwidIdentity, data: Dict[str, Any]
) -> None:
# identity
identity.tag_id = data.get("tag-id")
tag_version = data.get("tag-version")
Expand Down Expand Up @@ -221,3 +216,12 @@ def _load_identity(self, identity: uSwidIdentity, blob: bytes) -> None:
identity.add_link(link)
except KeyError:
pass

def _load_identity(self, identity: uSwidIdentity, blob: bytes) -> None:
"""imports a uSwidIdentity goSWID blob"""

try:
data: Dict[str, Any] = json.loads(blob)
except json.decoder.JSONDecodeError as e:
raise NotSupportedError("invalid goSWID: {}".format(e)) from e
self._load_identity_internal(self, data)

0 comments on commit b59eecd

Please sign in to comment.