/src/CMake/Source/cmSpdx.h
Line | Count | Source |
1 | | /* Distributed under the OSI-approved BSD 3-Clause License. See accompanying |
2 | | file LICENSE.rst or https://cmake.org/licensing for details. */ |
3 | | #pragma once |
4 | | #include <string> |
5 | | #include <vector> |
6 | | |
7 | | #include <cm/optional> |
8 | | |
9 | | #include "cmSbomObject.h" |
10 | | |
11 | | class cmSbomSerializer; |
12 | | |
13 | | using Datetime = std::string; |
14 | | using MediaType = std::string; |
15 | | using SemVer = std::string; |
16 | | |
17 | | struct cmSpdxExternalIdentifier |
18 | | { |
19 | | cm::optional<std::string> SpdxId; |
20 | | cm::optional<std::string> ExternalIdentifierType; |
21 | | cm::optional<std::string> Identifier; |
22 | | cm::optional<std::string> Comment; |
23 | | cm::optional<std::string> IdentifierLocation; |
24 | | cm::optional<std::string> IssuingAuthority; |
25 | | |
26 | | void Serialize(cmSbomSerializer&) const; |
27 | | }; |
28 | | |
29 | | struct cmSpdxExternalRef |
30 | | { |
31 | | cm::optional<std::string> SpdxId; |
32 | | cm::optional<std::string> ExternalRefType; |
33 | | cm::optional<std::string> Locator; |
34 | | cm::optional<std::string> ContentType; |
35 | | cm::optional<std::string> Comment; |
36 | | |
37 | | void Serialize(cmSbomSerializer&) const; |
38 | | }; |
39 | | |
40 | | struct cmSpdxCreationInfo |
41 | | { |
42 | | cm::optional<std::string> Id; |
43 | | cm::optional<std::string> SpdxId; |
44 | | cm::optional<SemVer> SpecVersion; |
45 | | cm::optional<std::string> Comment; |
46 | | cm::optional<Datetime> Created; |
47 | | std::vector<std::string> CreatedBy; |
48 | | std::vector<cmSbomObject> CreatedUsing; |
49 | | |
50 | | void Serialize(cmSbomSerializer&) const; |
51 | | }; |
52 | | |
53 | | struct cmSpdxIntegrityMethod |
54 | | { |
55 | | cm::optional<std::string> SpdxId; |
56 | | cm::optional<std::string> Comment; |
57 | | |
58 | | enum HashAlgorithmId |
59 | | { |
60 | | ADLER32, |
61 | | BLAKE2B256, |
62 | | BLAKE2B384, |
63 | | BLAKE2B512, |
64 | | BLAKE3, |
65 | | MD2, |
66 | | MD4, |
67 | | MD5, |
68 | | MD6, |
69 | | SHA1, |
70 | | SHA224, |
71 | | SHA256, |
72 | | SHA384, |
73 | | SHA512, |
74 | | SHA3_256, |
75 | | SHA3_384, |
76 | | SHA3_512, |
77 | | }; |
78 | | |
79 | | cmSpdxIntegrityMethod() = default; |
80 | | cmSpdxIntegrityMethod(cmSpdxIntegrityMethod const&) = default; |
81 | | cmSpdxIntegrityMethod(cmSpdxIntegrityMethod&&) = default; |
82 | | cmSpdxIntegrityMethod& operator=(cmSpdxIntegrityMethod const&) = default; |
83 | | cmSpdxIntegrityMethod& operator=(cmSpdxIntegrityMethod&&) = default; |
84 | | |
85 | | virtual void Serialize(cmSbomSerializer&) const; |
86 | 0 | virtual ~cmSpdxIntegrityMethod() = default; |
87 | | }; |
88 | | |
89 | | struct cmSpdxChecksum |
90 | | { |
91 | | cm::optional<std::string> SpdxId; |
92 | | cmSpdxIntegrityMethod::HashAlgorithmId Algorithm; |
93 | | std::string ChecksumValue; |
94 | | |
95 | | void Serialize(cmSbomSerializer&) const; |
96 | | }; |
97 | | |
98 | | struct cmSpdxElement |
99 | | { |
100 | | cm::optional<std::string> SpdxId; |
101 | | cm::optional<std::string> Name; |
102 | | cm::optional<std::string> Summary; |
103 | | cm::optional<std::string> Description; |
104 | | cm::optional<std::string> Comment; |
105 | | cm::optional<cmSbomObject> CreationInfo; |
106 | | cm::optional<cmSbomObject> VerifiedUsing; |
107 | | std::vector<cmSbomObject> ExternalRef; |
108 | | std::vector<cmSbomObject> ExternalIdentifier; |
109 | | cm::optional<cmSbomObject> Extension; |
110 | | |
111 | 0 | cmSpdxElement() = default; |
112 | 0 | cmSpdxElement(cmSpdxElement const&) = default; |
113 | 0 | cmSpdxElement(cmSpdxElement&&) = default; |
114 | | cmSpdxElement& operator=(cmSpdxElement const&) = default; |
115 | | cmSpdxElement& operator=(cmSpdxElement&&) = default; |
116 | | |
117 | 0 | virtual ~cmSpdxElement() = default; |
118 | | virtual void Serialize(cmSbomSerializer&) const; |
119 | | }; |
120 | | |
121 | | struct cmSpdxTool final : cmSpdxElement |
122 | | { |
123 | | void Serialize(cmSbomSerializer&) const override; |
124 | | }; |
125 | | |
126 | | struct cmSpdxAgent : cmSpdxElement |
127 | | { |
128 | | void Serialize(cmSbomSerializer&) const override; |
129 | | }; |
130 | | |
131 | | struct cmSpdxOrganization final : cmSpdxAgent |
132 | | { |
133 | | void Serialize(cmSbomSerializer&) const override; |
134 | | }; |
135 | | |
136 | | struct cmSpdxPerson final : cmSpdxAgent |
137 | | { |
138 | | void Serialize(cmSbomSerializer&) const override; |
139 | | }; |
140 | | |
141 | | struct cmSpdxSoftwareAgent final : cmSpdxAgent |
142 | | { |
143 | | void Serialize(cmSbomSerializer&) const override; |
144 | | }; |
145 | | |
146 | | struct cmSpdxPositiveIntegerRange |
147 | | { |
148 | | cm::optional<std::string> SpdxId; |
149 | | cm::optional<std::string> BeginIntegerRange; |
150 | | cm::optional<std::string> EndIntegerRange; |
151 | | |
152 | | void Serialize(cmSbomSerializer&) const; |
153 | | }; |
154 | | |
155 | | struct cmSpdxRelationship : cmSpdxElement |
156 | | { |
157 | | enum RelationshipTypeId |
158 | | { |
159 | | DESCRIBES, |
160 | | CONTAINS, |
161 | | DEPENDS_ON, |
162 | | HAS_DECLARED_LICENSE, |
163 | | OTHER |
164 | | }; |
165 | | |
166 | | cm::optional<cmSbomObject> From; |
167 | | std::vector<cmSbomObject> To; |
168 | | cm::optional<RelationshipTypeId> RelationshipType; |
169 | | cm::optional<Datetime> StartTime; |
170 | | cm::optional<Datetime> EndTime; |
171 | | |
172 | | void Serialize(cmSbomSerializer&) const override; |
173 | | }; |
174 | | |
175 | | struct cmSpdxLifecycleScopedRelationship final : cmSpdxRelationship |
176 | | { |
177 | | enum ScopeId |
178 | | { |
179 | | BUILD, |
180 | | DESIGN, |
181 | | RUNTIME, |
182 | | TEST |
183 | | }; |
184 | | |
185 | | cm::optional<ScopeId> Scope; |
186 | | |
187 | | void Serialize(cmSbomSerializer&) const override; |
188 | | }; |
189 | | |
190 | | struct cmSpdxArtifact : cmSpdxElement |
191 | | { |
192 | | enum SupportTypeId |
193 | | { |
194 | | COMMUNITY, |
195 | | COMMERCIAL, |
196 | | NONE |
197 | | }; |
198 | | |
199 | | std::vector<cmSbomObject> OriginatedBy; |
200 | | cm::optional<cmSbomObject> SuppliedBy; |
201 | | cm::optional<Datetime> BuiltTime; |
202 | | cm::optional<Datetime> ReleaseTime; |
203 | | cm::optional<Datetime> ValidUntilTime; |
204 | | cm::optional<std::string> StandardName; |
205 | | cm::optional<SupportTypeId> Support; |
206 | | |
207 | | void Serialize(cmSbomSerializer&) const override; |
208 | | }; |
209 | | |
210 | | struct cmSpdxIndividualElement final : cmSpdxElement |
211 | | { |
212 | | void Serialize(cmSbomSerializer&) const override; |
213 | | }; |
214 | | |
215 | | struct cmSpdxAnnotation final : cmSpdxElement |
216 | | { |
217 | | enum AnnotationTypeId |
218 | | { |
219 | | REVIEW, |
220 | | OTHER |
221 | | }; |
222 | | |
223 | | cm::optional<AnnotationTypeId> AnnotationType; |
224 | | cm::optional<MediaType> ContentType; |
225 | | cm::optional<std::string> Statement; |
226 | | cm::optional<cmSbomObject> Element; |
227 | | |
228 | | void Serialize(cmSbomSerializer&) const override; |
229 | | }; |
230 | | |
231 | | struct cmSpdxExternalMap |
232 | | { |
233 | | cm::optional<std::string> SpdxId; |
234 | | cm::optional<std::string> ExternalSpdxId; |
235 | | cm::optional<cmSbomObject> VerifiedUsing; |
236 | | cm::optional<std::string> LocationHistory; |
237 | | cm::optional<cmSbomObject> DefiningArtifact; |
238 | | |
239 | | void Serialize(cmSbomSerializer&) const; |
240 | | }; |
241 | | |
242 | | struct cmSpdxNamespaceMap |
243 | | { |
244 | | cm::optional<std::string> SpdxId; |
245 | | cm::optional<std::string> Prefix; |
246 | | cm::optional<std::string> Namespace; |
247 | | |
248 | | void Serialize(cmSbomSerializer&) const; |
249 | | }; |
250 | | |
251 | | struct cmSpdxElementCollection : cmSpdxElement |
252 | | { |
253 | | std::vector<cmSbomObject> Elements; |
254 | | std::vector<cmSbomObject> RootElements; |
255 | | std::vector<std::string> ProfileConformance; |
256 | | |
257 | | void Serialize(cmSbomSerializer&) const override; |
258 | | }; |
259 | | |
260 | | struct cmSpdxPackageVerificationCode final : cmSpdxIntegrityMethod |
261 | | { |
262 | | cm::optional<HashAlgorithmId> Algorithm; |
263 | | cm::optional<std::string> HashValue; |
264 | | cm::optional<std::string> PackageVerificationCodeExcludedFile; |
265 | | |
266 | | void Serialize(cmSbomSerializer&) const override; |
267 | | }; |
268 | | |
269 | | struct cmSpdxHash final : cmSpdxIntegrityMethod |
270 | | { |
271 | | HashAlgorithmId HashAlgorithm; |
272 | | std::string HashValue; |
273 | | |
274 | | void Serialize(cmSbomSerializer&) const override; |
275 | | }; |
276 | | |
277 | | struct cmSpdxBundle : cmSpdxElementCollection |
278 | | { |
279 | | cm::optional<std::string> Context; |
280 | | |
281 | | void Serialize(cmSbomSerializer&) const override; |
282 | | }; |
283 | | |
284 | | struct cmSpdxBom : cmSpdxBundle |
285 | | { |
286 | | void Serialize(cmSbomSerializer&) const override; |
287 | | }; |
288 | | |
289 | | struct cmSpdxSbom final : cmSpdxBom |
290 | | { |
291 | | enum TypeId |
292 | | { |
293 | | ANALYZED, |
294 | | BUILD, |
295 | | DEPLOYED, |
296 | | DESIGN, |
297 | | RUNTIME, |
298 | | SOURCE, |
299 | | TEST |
300 | | }; |
301 | | |
302 | | cm::optional<std::vector<TypeId>> Types; |
303 | | cm::optional<TypeId> LifecycleScope; |
304 | | |
305 | | void Serialize(cmSbomSerializer&) const override; |
306 | | }; |
307 | | |
308 | | struct cmSpdxSoftwareArtifact : cmSpdxArtifact |
309 | | { |
310 | | enum PurposeId |
311 | | { |
312 | | APPLICATION, |
313 | | ARCHIVE, |
314 | | CONTAINER, |
315 | | DATA, |
316 | | DEVICE, |
317 | | FIRMWARE, |
318 | | FILE, |
319 | | INSTALL, |
320 | | LIBRARY, |
321 | | MODULE, |
322 | | OPERATING_SYSTEM, |
323 | | SOURCE |
324 | | }; |
325 | | |
326 | | cm::optional<PurposeId> PrimaryPurpose; |
327 | | cm::optional<std::vector<PurposeId>> AdditionalPurpose; |
328 | | cm::optional<std::string> CopyrightText; |
329 | | cm::optional<std::string> AttributionText; |
330 | | cm::optional<cmSbomObject> ContentIdentifier; |
331 | | cm::optional<std::string> ArtifactSize; |
332 | | |
333 | | void Serialize(cmSbomSerializer&) const override; |
334 | | }; |
335 | | |
336 | | struct cmSpdxPackage final : cmSpdxSoftwareArtifact |
337 | | { |
338 | | cm::optional<std::string> DownloadLocation; |
339 | | cm::optional<std::string> Homepage; |
340 | | cm::optional<std::string> PackageVersion; |
341 | | cm::optional<std::string> PackageUrl; |
342 | | cm::optional<std::string> SourceInfo; |
343 | | |
344 | | void Serialize(cmSbomSerializer&) const override; |
345 | | }; |
346 | | |
347 | | struct cmSpdxAnyLicenseInfo : cmSpdxElement |
348 | | { |
349 | | void Serialize(cmSbomSerializer&) const override; |
350 | | }; |
351 | | |
352 | | struct cmSpdxLicenseExpression final : cmSpdxAnyLicenseInfo |
353 | | { |
354 | | cm::optional<std::string> LicenseExpression; |
355 | | |
356 | | void Serialize(cmSbomSerializer&) const override; |
357 | | }; |
358 | | |
359 | | struct cmSpdxDocument final : cmSpdxElementCollection |
360 | | { |
361 | | cm::optional<cmSbomObject> ExternalMap; |
362 | | cm::optional<cmSbomObject> NamespaceMap; |
363 | | cm::optional<cmSbomObject> DataLicense; |
364 | | |
365 | | void Serialize(cmSbomSerializer& serializer) const override; |
366 | | }; |
367 | | |
368 | | struct cmSpdxContentIdentifier final : cmSpdxIntegrityMethod |
369 | | { |
370 | | cm::optional<std::string> ContentIdentifierType; |
371 | | cm::optional<std::string> ContentValue; |
372 | | |
373 | | void Serialize(cmSbomSerializer&) const override; |
374 | | }; |
375 | | |
376 | | struct cmSpdxFile final : cmSpdxArtifact |
377 | | { |
378 | | enum FileKindId |
379 | | { |
380 | | DIRECTORY, |
381 | | FILE |
382 | | }; |
383 | | cm::optional<MediaType> ContentType; |
384 | | cm::optional<FileKindId> FileType; |
385 | | |
386 | | void Serialize(cmSbomSerializer&) const override; |
387 | | }; |
388 | | |
389 | | struct cmSpdxSnippet final : cmSpdxSoftwareArtifact |
390 | | { |
391 | | cm::optional<std::string> ByteRange; |
392 | | cm::optional<std::string> LineRange; |
393 | | cm::optional<cmSbomObject> SnippetFromFile; |
394 | | |
395 | | void Serialize(cmSbomSerializer&) const override; |
396 | | }; |
397 | | |
398 | | struct cmSbomDocument |
399 | | { |
400 | | cm::optional<std::string> Context; |
401 | | std::vector<cmSbomObject> Graph; |
402 | | |
403 | | void Serialize(cmSbomSerializer&) const; |
404 | | }; |