From dac50fd2b1fde3832f6666a5c86d407529210986 Mon Sep 17 00:00:00 2001 From: Richard Hughes Date: Mon, 18 Sep 2023 21:10:40 +0100 Subject: [PATCH] Autocreate the identity ID from the software-name if required This is really useful for software like 'gcc' that has no defined UUID or GUID. --- uswid/identity.py | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/uswid/identity.py b/uswid/identity.py index 1c7b085..3ad8a74 100644 --- a/uswid/identity.py +++ b/uswid/identity.py @@ -8,6 +8,7 @@ # pylint: disable=protected-access,too-many-boolean-expressions from typing import Dict, Optional, List +import uuid from .errors import NotSupportedError from .enums import uSwidVersionScheme @@ -43,7 +44,7 @@ def __init__( self._auto_increment_tag_version = False self.tag_id: Optional[str] = tag_id self.tag_version: int = tag_version - self.software_name: Optional[str] = software_name + self._software_name: Optional[str] = software_name self.software_version: Optional[str] = software_version self.version_scheme: Optional[uSwidVersionScheme] = None self.summary: Optional[str] = None @@ -57,6 +58,16 @@ def __init__( self._entities: Dict[str, uSwidEntity] = {} self._links: Dict[str, uSwidLink] = {} + @property + def software_name(self) -> Optional[str]: + return self._software_name + + @software_name.setter + def software_name(self, software_name: Optional[str]) -> None: + if not self.tag_id and software_name: + self.tag_id = str(uuid.uuid5(uuid.NAMESPACE_DNS, identity.software_name)) + self._software_name = software_name + def merge(self, identity_new: "uSwidIdentity") -> None: """adds new things from the new identity into the current one""" if identity_new.tag_version: