forked from CycloneDX/cyclonedx-javascript-library
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path_protocol.ts
More file actions
221 lines (193 loc) · 8.04 KB
/
Copy path_protocol.ts
File metadata and controls
221 lines (193 loc) · 8.04 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
/*!
This file is part of CycloneDX JavaScript Library.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
SPDX-License-Identifier: Apache-2.0
Copyright (c) OWASP Foundation. All Rights Reserved.
*/
import type { ComponentType, ExternalReferenceType, HashAlgorithm, Vulnerability } from '../enums'
import { type HashContent, NamedLicense, SpdxLicense } from '../models'
import type { Format, Version } from './enums'
/**
* This interface is not intended to be public API.
* This interface may be affected by breaking changes without notice.
*
* See the public exported constants, like {@link Spec.Spec1dot4}, that provide objects implementing this interface.
* See also {@link Spec.SpecVersionDict} for implementations.
*/
export interface _SpecProtocol {
version: Version
supportsFormat: (f: Format | any) => boolean
supportsComponentType: (ct: ComponentType | any) => boolean
supportsHashAlgorithm: (ha: HashAlgorithm | any) => boolean
supportsHashValue: (hv: HashContent | any) => boolean
supportsExternalReferenceType: (ert: ExternalReferenceType | any) => boolean
supportsDependencyGraph: boolean
supportsToolReferences: boolean
requiresComponentVersion: boolean
supportsProperties: (model: any) => boolean
supportsVulnerabilities: boolean
supportsVulnerabilityRatingMethod: (rm: Vulnerability.RatingMethod | any) => boolean
supportsComponentEvidence: boolean
supportsMetadataLifecycles: boolean
supportsMetadataLicenses: boolean
supportsMetadataProperties: boolean
supportsExternalReferenceHashes: boolean
supportsLicenseAcknowledgement: boolean
supportsServices: boolean
supportsToolsComponentsServices: boolean
}
/**
* This class was never intended to be public API,
*
* This is a helper to get the exact spec-versions implemented according to {@link _SpecProtocol | Specification}.
*
* @internal as this class may be affected by breaking changes without notice
*/
export class _Spec implements _SpecProtocol {
readonly #version: Version
readonly #formats: ReadonlySet<Format>
readonly #componentTypes: ReadonlySet<ComponentType>
readonly #hashAlgorithms: ReadonlySet<HashAlgorithm>
readonly #hashValuePattern: RegExp
readonly #externalReferenceTypes: ReadonlySet<ExternalReferenceType>
readonly #vulnerabilityRatingMethods: ReadonlySet<Vulnerability.RatingMethod>
readonly #supportsDependencyGraph: boolean
readonly #supportsToolReferences: boolean
readonly #requiresComponentVersion: boolean
readonly #supportsProperties: boolean
readonly #supportsVulnerabilities: boolean
readonly #supportsComponentEvidence: boolean
readonly #supportsMetadataLifecycles: boolean
readonly #supportsMetadataLicenses: boolean
readonly #supportsMetadataProperties: boolean
readonly #supportsExternalReferenceHashes: boolean
readonly #supportsLicenseAcknowledgement: boolean
readonly #supportsServices: boolean
readonly #supportsToolsComponentsServices: boolean
readonly #supportsLicenseProperties: boolean
/* eslint-disable-next-line @typescript-eslint/max-params -- architectural decision */
constructor (
version: Version,
formats: Iterable<Format>,
componentTypes: Iterable<ComponentType>,
hashAlgorithms: Iterable<HashAlgorithm>,
hashValuePattern: RegExp,
externalReferenceTypes: Iterable<ExternalReferenceType>,
supportsDependencyGraph: boolean,
supportsToolReferences: boolean,
requiresComponentVersion: boolean,
supportsProperties: boolean,
supportsVulnerabilities: boolean,
vulnerabilityRatingMethods: Iterable<Vulnerability.RatingMethod>,
supportsComponentEvidence: boolean,
supportsMetadataLifecycles: boolean,
supportsMetadataLicenses: boolean,
supportsMetadataProperties: boolean,
supportsExternalReferenceHashes: boolean,
supportsLicenseAcknowledgement: boolean,
supportsServices: boolean,
supportsToolsComponentsServices: boolean,
supportsLicenseProperties: boolean
) {
this.#version = version
this.#formats = new Set(formats)
this.#componentTypes = new Set(componentTypes)
this.#hashAlgorithms = new Set(hashAlgorithms)
this.#hashValuePattern = hashValuePattern
this.#externalReferenceTypes = new Set(externalReferenceTypes)
this.#supportsDependencyGraph = supportsDependencyGraph
this.#supportsToolReferences = supportsToolReferences
this.#requiresComponentVersion = requiresComponentVersion
this.#supportsProperties = supportsProperties
this.#supportsVulnerabilities = supportsVulnerabilities
this.#vulnerabilityRatingMethods = new Set(vulnerabilityRatingMethods)
this.#supportsComponentEvidence = supportsComponentEvidence
this.#supportsMetadataLifecycles = supportsMetadataLifecycles
this.#supportsMetadataLicenses = supportsMetadataLicenses
this.#supportsMetadataProperties = supportsMetadataProperties
this.#supportsExternalReferenceHashes = supportsExternalReferenceHashes
this.#supportsLicenseAcknowledgement = supportsLicenseAcknowledgement
this.#supportsServices = supportsServices
this.#supportsToolsComponentsServices = supportsToolsComponentsServices
this.#supportsLicenseProperties = supportsLicenseProperties
}
get version (): Version {
return this.#version
}
supportsFormat (f: Format | any): boolean {
/* eslint-disable-next-line @typescript-eslint/no-unsafe-argument -- fix */
return this.#formats.has(f)
}
supportsComponentType (ct: ComponentType | any): boolean {
/* eslint-disable-next-line @typescript-eslint/no-unsafe-argument -- fix */
return this.#componentTypes.has(ct)
}
supportsHashAlgorithm (ha: HashAlgorithm | any): boolean {
/* eslint-disable-next-line @typescript-eslint/no-unsafe-argument -- fix */
return this.#hashAlgorithms.has(ha)
}
supportsHashValue (hv: HashContent | any): boolean {
return typeof hv === 'string' &&
this.#hashValuePattern.test(hv)
}
supportsExternalReferenceType (ert: ExternalReferenceType | any): boolean {
/* eslint-disable-next-line @typescript-eslint/no-unsafe-argument -- fix */
return this.#externalReferenceTypes.has(ert)
}
get supportsDependencyGraph (): boolean {
return this.#supportsDependencyGraph
}
get supportsToolReferences (): boolean {
return this.#supportsToolReferences
}
get requiresComponentVersion (): boolean {
return this.#requiresComponentVersion
}
supportsProperties (model: any): boolean {
switch (true) {
case model instanceof NamedLicense || model instanceof SpdxLicense:
return this.#supportsLicenseProperties
default:
return this.#supportsProperties
}
}
get supportsVulnerabilities (): boolean {
return this.#supportsVulnerabilities
}
supportsVulnerabilityRatingMethod (rm: Vulnerability.RatingMethod | any): boolean {
/* eslint-disable-next-line @typescript-eslint/no-unsafe-argument -- any */
return this.#vulnerabilityRatingMethods.has(rm)
}
get supportsComponentEvidence (): boolean {
return this.#supportsComponentEvidence
}
get supportsMetadataLifecycles (): boolean {
return this.#supportsMetadataLifecycles
}
get supportsMetadataLicenses (): boolean {
return this.#supportsMetadataLicenses
}
get supportsMetadataProperties (): boolean {
return this.#supportsMetadataProperties
}
get supportsExternalReferenceHashes (): boolean {
return this.#supportsExternalReferenceHashes
}
get supportsLicenseAcknowledgement (): boolean {
return this.#supportsLicenseAcknowledgement
}
get supportsServices (): boolean {
return this.#supportsServices
}
get supportsToolsComponentsServices(): boolean {
return this.#supportsToolsComponentsServices
}
}