1818# Copyright (c) OWASP Foundation. All Rights Reserved.
1919
2020import datetime
21+ from importlib .metadata import version
2122from typing import List
2223from uuid import uuid4
2324
25+ from . import HashType
2426from .component import Component
2527from ..parser import BaseParser
2628
2729
30+ class Tool :
31+ """
32+ This is out internal representation of the toolType complex type within the CycloneDX standard.
33+
34+ Tool(s) are the things used in the creation of the BOM.
35+
36+ .. note::
37+ See the CycloneDX Schema for toolType: https://cyclonedx.org/docs/1.3/#type_toolType
38+ """
39+
40+ _vendor : str = None
41+ _name : str = None
42+ _version : str = None
43+ _hashes : List [HashType ] = []
44+
45+ def __init__ (self , vendor : str , name : str , version : str , hashes : List [HashType ] = []):
46+ self ._vendor = vendor
47+ self ._name = name
48+ self ._version = version
49+ self ._hashes = hashes
50+
51+ def get_hashes (self ) -> List [HashType ]:
52+ """
53+ List of cryptographic hashes that identify this version of this Tool.
54+
55+ Returns:
56+ `List` of `HashType` objects where there are any hashes, else an empty `List`.
57+ """
58+ return self ._hashes
59+
60+ def get_name (self ) -> str :
61+ """
62+ The name of this Tool.
63+
64+ Returns:
65+ `str` representing the name of the Tool
66+ """
67+ return self ._name
68+
69+ def get_vendor (self ) -> str :
70+ """
71+ The vendor of this Tool.
72+
73+ Returns:
74+ `str` representing the vendor of the Tool
75+ """
76+ return self ._vendor
77+
78+ def get_version (self ) -> str :
79+ """
80+ The version of this Tool.
81+
82+ Returns:
83+ `str` representing the version of the Tool
84+ """
85+ return self ._version
86+
87+ def __repr__ (self ):
88+ return '<Tool {}:{}:{}>' .format (self ._vendor , self ._name , self ._version )
89+
90+
91+ try :
92+ ThisTool = Tool (vendor = 'CycloneDX' , name = 'cyclonedx-python-lib' , version = version ('cyclonedx-python-lib' ))
93+ except Exception :
94+ ThisTool = Tool (vendor = 'CycloneDX' , name = 'cyclonedx-python-lib' , version = 'UNKNOWN' )
95+
96+
2897class BomMetaData :
2998 """
3099 This is our internal representation of the metadata complex type within the CycloneDX standard.
@@ -34,9 +103,13 @@ class BomMetaData:
34103 """
35104
36105 _timestamp : datetime .datetime
106+ _tools : List [Tool ] = []
37107
38- def __init__ (self ):
108+ def __init__ (self , tools : List [ Tool ] = [] ):
39109 self ._timestamp = datetime .datetime .now (tz = datetime .timezone .utc )
110+ if len (tools ) == 0 :
111+ tools .append (ThisTool )
112+ self ._tools = tools
40113
41114 def get_timestamp (self ) -> datetime .datetime :
42115 """
@@ -47,6 +120,15 @@ def get_timestamp(self) -> datetime.datetime:
47120 """
48121 return self ._timestamp
49122
123+ def get_tools (self ) -> List [Tool ]:
124+ """
125+ Tools used to create this BOM.
126+
127+ Returns:
128+ `List` of `Tool` objects where there are any, else an empty `List`.
129+ """
130+ return self ._tools
131+
50132
51133class Bom :
52134 """
0 commit comments