From b59eecdae7d9708f197fd1bc1238f7c0ca1db92f Mon Sep 17 00:00:00 2001 From: Richard Hughes Date: Mon, 18 Sep 2023 15:16:05 +0100 Subject: [PATCH] Fix importing goSWID XML when there is more than one identity --- uswid/format_goswid.py | 22 +++++++++++++--------- 1 file changed, 13 insertions(+), 9 deletions(-) diff --git a/uswid/format_goswid.py b/uswid/format_goswid.py index 26fdcb8..5fcaefe 100644 --- a/uswid/format_goswid.py +++ b/uswid/format_goswid.py @@ -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 @@ -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") @@ -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)