@cyclonedx/cyclonedx-library 1.0.0-beta.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (169) hide show
  1. package/LICENSE +201 -0
  2. package/NOTICE +5 -0
  3. package/README.md +152 -0
  4. package/dist.node/_index.node.js +53 -0
  5. package/dist.node/_index.node.js.map +1 -0
  6. package/dist.node/enums/attachmentEncoding.js +26 -0
  7. package/dist.node/enums/attachmentEncoding.js.map +1 -0
  8. package/dist.node/enums/componentScope.js +28 -0
  9. package/dist.node/enums/componentScope.js.map +1 -0
  10. package/dist.node/enums/componentType.js +33 -0
  11. package/dist.node/enums/componentType.js.map +1 -0
  12. package/dist.node/enums/externalReferenceType.js +41 -0
  13. package/dist.node/enums/externalReferenceType.js.map +1 -0
  14. package/dist.node/enums/hashAlogorithm.js +37 -0
  15. package/dist.node/enums/hashAlogorithm.js.map +1 -0
  16. package/dist.node/enums/index.js +40 -0
  17. package/dist.node/enums/index.js.map +1 -0
  18. package/dist.node/factories/index.js +36 -0
  19. package/dist.node/factories/index.js.map +1 -0
  20. package/dist.node/factories/licenseFactory.js +56 -0
  21. package/dist.node/factories/licenseFactory.js.map +1 -0
  22. package/dist.node/helpers/types.js +26 -0
  23. package/dist.node/helpers/types.js.map +1 -0
  24. package/dist.node/models/attachment.js +30 -0
  25. package/dist.node/models/attachment.js.map +1 -0
  26. package/dist.node/models/bom.js +67 -0
  27. package/dist.node/models/bom.js.map +1 -0
  28. package/dist.node/models/bomRef.js +37 -0
  29. package/dist.node/models/bomRef.js.map +1 -0
  30. package/dist.node/models/component.js +96 -0
  31. package/dist.node/models/component.js.map +1 -0
  32. package/dist.node/models/externalReference.js +40 -0
  33. package/dist.node/models/externalReference.js.map +1 -0
  34. package/dist.node/models/hash.js +29 -0
  35. package/dist.node/models/hash.js.map +1 -0
  36. package/dist.node/models/index.js +47 -0
  37. package/dist.node/models/index.js.map +1 -0
  38. package/dist.node/models/license.js +103 -0
  39. package/dist.node/models/license.js.map +1 -0
  40. package/dist.node/models/metadata.js +35 -0
  41. package/dist.node/models/metadata.js.map +1 -0
  42. package/dist.node/models/organizationalContact.js +41 -0
  43. package/dist.node/models/organizationalContact.js.map +1 -0
  44. package/dist.node/models/organizationalEntity.js +31 -0
  45. package/dist.node/models/organizationalEntity.js.map +1 -0
  46. package/dist.node/models/swid.js +58 -0
  47. package/dist.node/models/swid.js.map +1 -0
  48. package/dist.node/models/tool.js +45 -0
  49. package/dist.node/models/tool.js.map +1 -0
  50. package/dist.node/resources.node.js +55 -0
  51. package/dist.node/resources.node.js.map +1 -0
  52. package/dist.node/serialize/_index.node.js +37 -0
  53. package/dist.node/serialize/_index.node.js.map +1 -0
  54. package/dist.node/serialize/baseSerializer.js +56 -0
  55. package/dist.node/serialize/baseSerializer.js.map +1 -0
  56. package/dist.node/serialize/bomRefDiscriminator.js +66 -0
  57. package/dist.node/serialize/bomRefDiscriminator.js.map +1 -0
  58. package/dist.node/serialize/index.js +55 -0
  59. package/dist.node/serialize/index.js.map +1 -0
  60. package/dist.node/serialize/json/index.js +47 -0
  61. package/dist.node/serialize/json/index.js.map +1 -0
  62. package/dist.node/serialize/json/normalize.js +431 -0
  63. package/dist.node/serialize/json/normalize.js.map +1 -0
  64. package/dist.node/serialize/json/types.js +35 -0
  65. package/dist.node/serialize/json/types.js.map +1 -0
  66. package/dist.node/serialize/jsonSerializer.js +55 -0
  67. package/dist.node/serialize/jsonSerializer.js.map +1 -0
  68. package/dist.node/serialize/types.js +21 -0
  69. package/dist.node/serialize/types.js.map +1 -0
  70. package/dist.node/serialize/xml/index.js +47 -0
  71. package/dist.node/serialize/xml/index.js.map +1 -0
  72. package/dist.node/serialize/xml/normalize.js +560 -0
  73. package/dist.node/serialize/xml/normalize.js.map +1 -0
  74. package/dist.node/serialize/xml/types.js +31 -0
  75. package/dist.node/serialize/xml/types.js.map +1 -0
  76. package/dist.node/serialize/xmlBaseSerializer.js +52 -0
  77. package/dist.node/serialize/xmlBaseSerializer.js.map +1 -0
  78. package/dist.node/serialize/xmlSerializer.node.js +30 -0
  79. package/dist.node/serialize/xmlSerializer.node.js.map +1 -0
  80. package/dist.node/spdx.js +35 -0
  81. package/dist.node/spdx.js.map +1 -0
  82. package/dist.node/spec.js +229 -0
  83. package/dist.node/spec.js.map +1 -0
  84. package/dist.node/types/cpe.js +28 -0
  85. package/dist.node/types/cpe.js.map +1 -0
  86. package/dist.node/types/index.js +39 -0
  87. package/dist.node/types/index.js.map +1 -0
  88. package/dist.node/types/integer.js +36 -0
  89. package/dist.node/types/integer.js.map +1 -0
  90. package/dist.node/types/mimeType.js +28 -0
  91. package/dist.node/types/mimeType.js.map +1 -0
  92. package/dist.node/types/urn.js +28 -0
  93. package/dist.node/types/urn.js.map +1 -0
  94. package/dist.web/lib.dev.js +3487 -0
  95. package/dist.web/lib.dev.js.map +1 -0
  96. package/dist.web/lib.js +2 -0
  97. package/dist.web/lib.js.LICENSE.txt +18 -0
  98. package/libs/universal-node-xml/index.d.ts +33 -0
  99. package/libs/universal-node-xml/index.js +42 -0
  100. package/libs/universal-node-xml/stringifiers/helpers.js +17 -0
  101. package/libs/universal-node-xml/stringifiers/xmlbuilder2.js +51 -0
  102. package/package.json +86 -0
  103. package/res/README.md +27 -0
  104. package/res/bom-1.0.SNAPSHOT.xsd +247 -0
  105. package/res/bom-1.1.SNAPSHOT.xsd +731 -0
  106. package/res/bom-1.2-strict.SNAPSHOT.schema.json +1026 -0
  107. package/res/bom-1.2.SNAPSHOT.schema.json +997 -0
  108. package/res/bom-1.2.SNAPSHOT.xsd +1418 -0
  109. package/res/bom-1.3-strict.SNAPSHOT.schema.json +1085 -0
  110. package/res/bom-1.3.SNAPSHOT.schema.json +1054 -0
  111. package/res/bom-1.3.SNAPSHOT.xsd +1631 -0
  112. package/res/bom-1.4.SNAPSHOT.schema.json +1697 -0
  113. package/res/bom-1.4.SNAPSHOT.xsd +2407 -0
  114. package/res/jsf-0.82.SNAPSHOT.schema.json +244 -0
  115. package/res/spdx.SNAPSHOT.schema.json +533 -0
  116. package/res/spdx.SNAPSHOT.xsd +2639 -0
  117. package/src/_index.node.ts +31 -0
  118. package/src/_index.web.ts +27 -0
  119. package/src/enums/attachmentEncoding.ts +22 -0
  120. package/src/enums/componentScope.ts +24 -0
  121. package/src/enums/componentType.ts +29 -0
  122. package/src/enums/externalReferenceType.ts +37 -0
  123. package/src/enums/hashAlogorithm.ts +33 -0
  124. package/src/enums/index.ts +24 -0
  125. package/src/factories/index.ts +20 -0
  126. package/src/factories/licenseFactory.ts +62 -0
  127. package/src/helpers/README.md +3 -0
  128. package/src/helpers/types.ts +28 -0
  129. package/src/models/attachment.ts +37 -0
  130. package/src/models/bom.ts +85 -0
  131. package/src/models/bomRef.ts +41 -0
  132. package/src/models/component.ts +136 -0
  133. package/src/models/externalReference.ts +48 -0
  134. package/src/models/hash.ts +38 -0
  135. package/src/models/index.ts +31 -0
  136. package/src/models/license.ts +133 -0
  137. package/src/models/metadata.ts +50 -0
  138. package/src/models/organizationalContact.ts +49 -0
  139. package/src/models/organizationalEntity.ts +38 -0
  140. package/src/models/swid.ts +71 -0
  141. package/src/models/tool.ts +58 -0
  142. package/src/resources.node.ts +59 -0
  143. package/src/serialize/_index.node.ts +23 -0
  144. package/src/serialize/_index.web.ts +23 -0
  145. package/src/serialize/baseSerializer.ts +52 -0
  146. package/src/serialize/bomRefDiscriminator.ts +69 -0
  147. package/src/serialize/index.ts +35 -0
  148. package/src/serialize/json/index.ts +23 -0
  149. package/src/serialize/json/normalize.ts +450 -0
  150. package/src/serialize/json/types.ts +187 -0
  151. package/src/serialize/jsonSerializer.ts +59 -0
  152. package/src/serialize/types.ts +38 -0
  153. package/src/serialize/xml/index.ts +23 -0
  154. package/src/serialize/xml/normalize.ts +590 -0
  155. package/src/serialize/xml/types.ts +112 -0
  156. package/src/serialize/xmlBaseSerializer.ts +52 -0
  157. package/src/serialize/xmlSerializer.node.ts +35 -0
  158. package/src/serialize/xmlSerializer.web.ts +89 -0
  159. package/src/spdx.ts +48 -0
  160. package/src/spec.ts +289 -0
  161. package/src/types/cpe.ts +33 -0
  162. package/src/types/index.ts +23 -0
  163. package/src/types/integer.ts +50 -0
  164. package/src/types/mimeType.ts +31 -0
  165. package/src/types/urn.ts +33 -0
  166. package/tsconfig.json +108 -0
  167. package/tsconfig.node.json +8 -0
  168. package/tsconfig.web.json +5 -0
  169. package/webpack.config.js +74 -0
@@ -0,0 +1,52 @@
1
+ /*!
2
+ This file is part of CycloneDX JavaScript Library.
3
+
4
+ Licensed under the Apache License, Version 2.0 (the "License");
5
+ you may not use this file except in compliance with the License.
6
+ You may obtain a copy of the License at
7
+
8
+ http://www.apache.org/licenses/LICENSE-2.0
9
+
10
+ Unless required by applicable law or agreed to in writing, software
11
+ distributed under the License is distributed on an "AS IS" BASIS,
12
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ See the License for the specific language governing permissions and
14
+ limitations under the License.
15
+
16
+ SPDX-License-Identifier: Apache-2.0
17
+ Copyright (c) OWASP Foundation. All Rights Reserved.
18
+ */
19
+
20
+ import { Bom } from '../models'
21
+ import { Format, UnsupportedFormatError } from '../spec'
22
+ import { BaseSerializer } from './baseSerializer'
23
+ import { NormalizerOptions } from './types'
24
+ import { Factory as NormalizerFactory } from './xml/normalize'
25
+ import { SimpleXml } from './xml/types'
26
+
27
+ /**
28
+ * Base XML serializer.
29
+ */
30
+ export abstract class XmlBaseSerializer extends BaseSerializer<SimpleXml.Element> {
31
+ readonly #normalizerFactory: NormalizerFactory
32
+
33
+ /**
34
+ * @throws {UnsupportedFormatError} if {@see normalizerFactory.spec} does not support {@see Format.XML}.
35
+ */
36
+ constructor (normalizerFactory: NormalizerFactory) {
37
+ if (!normalizerFactory.spec.supportsFormat(Format.JSON)) {
38
+ throw new UnsupportedFormatError('Spec does not support JSON format.')
39
+ }
40
+
41
+ super()
42
+ this.#normalizerFactory = normalizerFactory
43
+ }
44
+
45
+ protected _normalize (
46
+ bom: Bom,
47
+ options: NormalizerOptions = {}
48
+ ): SimpleXml.Element {
49
+ return this.#normalizerFactory.makeForBom()
50
+ .normalize(bom, options)
51
+ }
52
+ }
@@ -0,0 +1,35 @@
1
+ /*!
2
+ This file is part of CycloneDX JavaScript Library.
3
+
4
+ Licensed under the Apache License, Version 2.0 (the "License");
5
+ you may not use this file except in compliance with the License.
6
+ You may obtain a copy of the License at
7
+
8
+ http://www.apache.org/licenses/LICENSE-2.0
9
+
10
+ Unless required by applicable law or agreed to in writing, software
11
+ distributed under the License is distributed on an "AS IS" BASIS,
12
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ See the License for the specific language governing permissions and
14
+ limitations under the License.
15
+
16
+ SPDX-License-Identifier: Apache-2.0
17
+ Copyright (c) OWASP Foundation. All Rights Reserved.
18
+ */
19
+
20
+ import { SerializerOptions } from './types'
21
+ import { XmlBaseSerializer } from './xmlBaseSerializer'
22
+ import { SimpleXml } from './xml/types'
23
+ import { stringifyFallback } from '../../libs/universal-node-xml'
24
+
25
+ /**
26
+ * XML serializer for node.
27
+ */
28
+ export class XmlSerializer extends XmlBaseSerializer {
29
+ protected _serialize (
30
+ normalizedBom: SimpleXml.Element,
31
+ options: SerializerOptions = {}
32
+ ): string {
33
+ return stringifyFallback(normalizedBom, options)
34
+ }
35
+ }
@@ -0,0 +1,89 @@
1
+ /*!
2
+ This file is part of CycloneDX JavaScript Library.
3
+
4
+ Licensed under the Apache License, Version 2.0 (the "License");
5
+ you may not use this file except in compliance with the License.
6
+ You may obtain a copy of the License at
7
+
8
+ http://www.apache.org/licenses/LICENSE-2.0
9
+
10
+ Unless required by applicable law or agreed to in writing, software
11
+ distributed under the License is distributed on an "AS IS" BASIS,
12
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ See the License for the specific language governing permissions and
14
+ limitations under the License.
15
+
16
+ SPDX-License-Identifier: Apache-2.0
17
+ Copyright (c) OWASP Foundation. All Rights Reserved.
18
+ */
19
+
20
+ import { isNotUndefined } from '../helpers/types'
21
+ import { SerializerOptions } from './types'
22
+ import { XmlBaseSerializer } from './xmlBaseSerializer'
23
+ import { SimpleXml } from './xml/types'
24
+
25
+ /**
26
+ * XML serializer for web browsers.
27
+ */
28
+ export class XmlSerializer extends XmlBaseSerializer {
29
+ protected _serialize (
30
+ normalizedBom: SimpleXml.Element,
31
+ { space }: SerializerOptions = {}
32
+ ): string {
33
+ const doc = this.#buildXmlDocument(normalizedBom)
34
+ // TODO: add indention based on `space`
35
+ return (new XMLSerializer()).serializeToString(doc)
36
+ }
37
+
38
+ #buildXmlDocument (
39
+ normalizedBom: SimpleXml.Element
40
+ ): XMLDocument {
41
+ const namespace = null
42
+ const doc = document.implementation.createDocument(namespace, null)
43
+ doc.appendChild(this.#buildElement(normalizedBom, doc, namespace))
44
+ return doc
45
+ }
46
+
47
+ #getNS (element: SimpleXml.Element): string | null {
48
+ const ns = (element.namespace ?? element.attributes?.xmlns)?.toString() ?? ''
49
+ return ns.length > 0
50
+ ? ns
51
+ : null
52
+ }
53
+
54
+ #buildElement (element: SimpleXml.Element, doc: XMLDocument, parentNS: string | null): Element {
55
+ const ns = this.#getNS(element) ?? parentNS
56
+ const node: Element = doc.createElementNS(ns, element.name)
57
+ if (isNotUndefined(element.attributes)) {
58
+ this.#setAttributes(node, element.attributes)
59
+ }
60
+ if (isNotUndefined(element.children)) {
61
+ this.#setChildren(node, element.children, ns)
62
+ }
63
+ return node
64
+ }
65
+
66
+ #setAttributes (node: Element, attributes: SimpleXml.ElementAttributes): void {
67
+ for (const [name, value] of Object.entries(attributes)) {
68
+ if (isNotUndefined(value) && name !== 'xmlns') {
69
+ // reminder: cannot change a namespace(xmlns) after the fact.
70
+ node.setAttribute(name, `${value}`)
71
+ }
72
+ }
73
+ }
74
+
75
+ #setChildren (node: Element, children: SimpleXml.ElementChildren, parentNS: string | null = null): void {
76
+ if (typeof children === 'string' || typeof children === 'number') {
77
+ node.textContent = children.toString()
78
+ return
79
+ }
80
+
81
+ const doc = node.ownerDocument
82
+ for (const child of (children as Iterable<SimpleXml.Comment | SimpleXml.Element>)) {
83
+ if (child.type === 'element') {
84
+ node.appendChild(this.#buildElement(child, doc, parentNS))
85
+ }
86
+ // comments are not implemented, yet
87
+ }
88
+ }
89
+ }
package/src/spdx.ts ADDED
@@ -0,0 +1,48 @@
1
+ /*!
2
+ This file is part of CycloneDX JavaScript Library.
3
+
4
+ Licensed under the Apache License, Version 2.0 (the "License");
5
+ you may not use this file except in compliance with the License.
6
+ You may obtain a copy of the License at
7
+
8
+ http://www.apache.org/licenses/LICENSE-2.0
9
+
10
+ Unless required by applicable law or agreed to in writing, software
11
+ distributed under the License is distributed on an "AS IS" BASIS,
12
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ See the License for the specific language governing permissions and
14
+ limitations under the License.
15
+
16
+ SPDX-License-Identifier: Apache-2.0
17
+ Copyright (c) OWASP Foundation. All Rights Reserved.
18
+ */
19
+
20
+ /* eslint-disable */
21
+ /* @ts-ignore: TS6059 -- this works as long as the file/path is available in dist-package */
22
+ import {enum as _spdxSpecEnum} from '../res/spdx.SNAPSHOT.schema.json'
23
+ /* eslint-enable */
24
+
25
+ /**
26
+ * One of the known SPDX licence identifiers.
27
+ * @see {@link http://cyclonedx.org/schema/spdx}
28
+ * @see isSupportedSpdxId
29
+ * @see fixupSpdxId
30
+ */
31
+ export type SpdxId = string
32
+
33
+ const spdxIds: ReadonlySet<SpdxId> = new Set(_spdxSpecEnum)
34
+
35
+ const spdxLowerToActual: ReadonlyMap<string, SpdxId> = new Map(
36
+ _spdxSpecEnum.map(spdxId => [spdxId.toLowerCase(), spdxId])
37
+ )
38
+
39
+ export function isSupportedSpdxId (value: SpdxId | any): value is SpdxId {
40
+ return spdxIds.has(value)
41
+ }
42
+
43
+ /** Try to convert a string to `SpdxId`. */
44
+ export function fixupSpdxId (value: string | any): SpdxId | undefined {
45
+ return typeof value === 'string' && value.length > 0
46
+ ? spdxLowerToActual.get(value.toLowerCase())
47
+ : undefined
48
+ }
package/src/spec.ts ADDED
@@ -0,0 +1,289 @@
1
+ /*!
2
+ This file is part of CycloneDX JavaScript Library.
3
+
4
+ Licensed under the Apache License, Version 2.0 (the "License");
5
+ you may not use this file except in compliance with the License.
6
+ You may obtain a copy of the License at
7
+
8
+ http://www.apache.org/licenses/LICENSE-2.0
9
+
10
+ Unless required by applicable law or agreed to in writing, software
11
+ distributed under the License is distributed on an "AS IS" BASIS,
12
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ See the License for the specific language governing permissions and
14
+ limitations under the License.
15
+
16
+ SPDX-License-Identifier: Apache-2.0
17
+ Copyright (c) OWASP Foundation. All Rights Reserved.
18
+ */
19
+
20
+ import { ComponentType, ExternalReferenceType, HashAlgorithm } from './enums'
21
+ import { HashContent } from './models'
22
+
23
+ export enum Version {
24
+ v1dot0 = '1.0',
25
+ v1dot1 = '1.1',
26
+ v1dot2 = '1.2',
27
+ v1dot3 = '1.3',
28
+ v1dot4 = '1.4',
29
+ }
30
+
31
+ export enum Format {
32
+ XML = 'xml',
33
+ JSON = 'json',
34
+ }
35
+
36
+ export class UnsupportedFormatError extends Error {
37
+ }
38
+
39
+ export interface Protocol {
40
+ readonly version: Version
41
+
42
+ supportsFormat: (f: Format | any) => boolean
43
+
44
+ supportsComponentType: (ct: ComponentType | any) => boolean
45
+
46
+ supportsHashAlgorithm: (ha: HashAlgorithm | any) => boolean
47
+
48
+ supportsHashValue: (hv: HashContent | any) => boolean
49
+
50
+ supportsExternalReferenceType: (ert: ExternalReferenceType | any) => boolean
51
+
52
+ readonly supportsDependencyGraph: boolean
53
+
54
+ readonly supportsToolReferences: boolean
55
+ }
56
+
57
+ /**
58
+ * @internal This class was never intended to be public,
59
+ * but it is a helper to get the exact spec-versions implemented according to {@see Protocol}.
60
+ */
61
+ class Spec implements Protocol {
62
+ readonly #version: Version
63
+ readonly #formats: ReadonlySet<Format>
64
+ readonly #componentTypes: ReadonlySet<ComponentType>
65
+ readonly #hashAlgorithms: ReadonlySet<HashAlgorithm>
66
+ readonly #hashValuePattern: RegExp
67
+ readonly #externalReferenceTypes: ReadonlySet<ExternalReferenceType>
68
+ readonly #supportsDependencyGraph: boolean
69
+ readonly #supportsToolReferences: boolean
70
+
71
+ constructor (
72
+ version: Version,
73
+ formats: Iterable<Format>,
74
+ componentTypes: Iterable<ComponentType>,
75
+ hashAlgorithms: Iterable<HashAlgorithm>,
76
+ hashValuePattern: RegExp,
77
+ externalReferenceTypes: Iterable<ExternalReferenceType>,
78
+ supportsDependencyGraph: boolean,
79
+ supportsToolReferences: boolean
80
+ ) {
81
+ this.#version = version
82
+ this.#formats = new Set(formats)
83
+ this.#componentTypes = new Set(componentTypes)
84
+ this.#hashAlgorithms = new Set(hashAlgorithms)
85
+ this.#hashValuePattern = hashValuePattern
86
+ this.#externalReferenceTypes = new Set(externalReferenceTypes)
87
+ this.#supportsDependencyGraph = supportsDependencyGraph
88
+ this.#supportsToolReferences = supportsToolReferences
89
+ }
90
+
91
+ get version (): Version {
92
+ return this.#version
93
+ }
94
+
95
+ supportsFormat (f: Format | any): boolean {
96
+ return this.#formats.has(f)
97
+ }
98
+
99
+ supportsComponentType (ct: ComponentType | any): boolean {
100
+ return this.#componentTypes.has(ct)
101
+ }
102
+
103
+ supportsHashAlgorithm (ha: HashAlgorithm | any): boolean {
104
+ return this.#hashAlgorithms.has(ha)
105
+ }
106
+
107
+ supportsHashValue (hv: HashContent | any): boolean {
108
+ return typeof hv === 'string' &&
109
+ this.#hashValuePattern.test(hv)
110
+ }
111
+
112
+ supportsExternalReferenceType (ert: ExternalReferenceType | any): boolean {
113
+ return this.#externalReferenceTypes.has(ert)
114
+ }
115
+
116
+ get supportsDependencyGraph (): boolean {
117
+ return this.#supportsDependencyGraph
118
+ }
119
+
120
+ get supportsToolReferences (): boolean {
121
+ return this.#supportsToolReferences
122
+ }
123
+ }
124
+
125
+ /** Specification v1.2 */
126
+ export const Spec1dot2: Readonly<Protocol> = Object.freeze(new Spec(
127
+ Version.v1dot2,
128
+ [
129
+ Format.XML,
130
+ Format.JSON
131
+ ],
132
+ [
133
+ ComponentType.Application,
134
+ ComponentType.Framework,
135
+ ComponentType.Library,
136
+ ComponentType.Container,
137
+ ComponentType.OperatingSystem,
138
+ ComponentType.Device,
139
+ ComponentType.Firmware,
140
+ ComponentType.File
141
+ ],
142
+ [
143
+ HashAlgorithm.MD5,
144
+ HashAlgorithm['SHA-1'],
145
+ HashAlgorithm['SHA-256'],
146
+ HashAlgorithm['SHA-384'],
147
+ HashAlgorithm['SHA-512'],
148
+ HashAlgorithm['SHA3-256'],
149
+ HashAlgorithm['SHA3-384'],
150
+ HashAlgorithm['SHA3-512'],
151
+ HashAlgorithm['BLAKE2b-256'],
152
+ HashAlgorithm['BLAKE2b-384'],
153
+ HashAlgorithm['BLAKE2b-512'],
154
+ HashAlgorithm.BLAKE3
155
+ ],
156
+ /^([a-fA-F0-9]{32})$|^([a-fA-F0-9]{40})$|^([a-fA-F0-9]{64})$|^([a-fA-F0-9]{96})$|^([a-fA-F0-9]{128})$/,
157
+ [
158
+ ExternalReferenceType.VCS,
159
+ ExternalReferenceType.IssueTracker,
160
+ ExternalReferenceType.Website,
161
+ ExternalReferenceType.Advisories,
162
+ ExternalReferenceType.BOM,
163
+ ExternalReferenceType.MailingList,
164
+ ExternalReferenceType.Social,
165
+ ExternalReferenceType.Chat,
166
+ ExternalReferenceType.Documentation,
167
+ ExternalReferenceType.Support,
168
+ ExternalReferenceType.Distribution,
169
+ ExternalReferenceType.License,
170
+ ExternalReferenceType.BuildMeta,
171
+ ExternalReferenceType.BuildSystem,
172
+ ExternalReferenceType.Other
173
+ ],
174
+ true,
175
+ false
176
+ ))
177
+
178
+ /** Specification v1.3 */
179
+ export const Spec1dot3: Readonly<Protocol> = Object.freeze(new Spec(
180
+ Version.v1dot3,
181
+ [
182
+ Format.XML,
183
+ Format.JSON
184
+ ],
185
+ [
186
+ ComponentType.Application,
187
+ ComponentType.Framework,
188
+ ComponentType.Library,
189
+ ComponentType.Container,
190
+ ComponentType.OperatingSystem,
191
+ ComponentType.Device,
192
+ ComponentType.Firmware,
193
+ ComponentType.File
194
+ ],
195
+ [
196
+ HashAlgorithm.MD5,
197
+ HashAlgorithm['SHA-1'],
198
+ HashAlgorithm['SHA-256'],
199
+ HashAlgorithm['SHA-384'],
200
+ HashAlgorithm['SHA-512'],
201
+ HashAlgorithm['SHA3-256'],
202
+ HashAlgorithm['SHA3-384'],
203
+ HashAlgorithm['SHA3-512'],
204
+ HashAlgorithm['BLAKE2b-256'],
205
+ HashAlgorithm['BLAKE2b-384'],
206
+ HashAlgorithm['BLAKE2b-512'],
207
+ HashAlgorithm.BLAKE3
208
+ ],
209
+ /^([a-fA-F0-9]{32})$|^([a-fA-F0-9]{40})$|^([a-fA-F0-9]{64})$|^([a-fA-F0-9]{96})$|^([a-fA-F0-9]{128})$/,
210
+ [
211
+ ExternalReferenceType.VCS,
212
+ ExternalReferenceType.IssueTracker,
213
+ ExternalReferenceType.Website,
214
+ ExternalReferenceType.Advisories,
215
+ ExternalReferenceType.BOM,
216
+ ExternalReferenceType.MailingList,
217
+ ExternalReferenceType.Social,
218
+ ExternalReferenceType.Chat,
219
+ ExternalReferenceType.Documentation,
220
+ ExternalReferenceType.Support,
221
+ ExternalReferenceType.Distribution,
222
+ ExternalReferenceType.License,
223
+ ExternalReferenceType.BuildMeta,
224
+ ExternalReferenceType.BuildSystem,
225
+ ExternalReferenceType.Other
226
+ ],
227
+ true,
228
+ false
229
+ ))
230
+
231
+ /** Specification v1.4 */
232
+ export const Spec1dot4: Readonly<Protocol> = Object.freeze(new Spec(
233
+ Version.v1dot4,
234
+ [
235
+ Format.XML,
236
+ Format.JSON
237
+ ],
238
+ [
239
+ ComponentType.Application,
240
+ ComponentType.Framework,
241
+ ComponentType.Library,
242
+ ComponentType.Container,
243
+ ComponentType.OperatingSystem,
244
+ ComponentType.Device,
245
+ ComponentType.Firmware,
246
+ ComponentType.File
247
+ ],
248
+ [
249
+ HashAlgorithm.MD5,
250
+ HashAlgorithm['SHA-1'],
251
+ HashAlgorithm['SHA-256'],
252
+ HashAlgorithm['SHA-384'],
253
+ HashAlgorithm['SHA-512'],
254
+ HashAlgorithm['SHA3-256'],
255
+ HashAlgorithm['SHA3-384'],
256
+ HashAlgorithm['SHA3-512'],
257
+ HashAlgorithm['BLAKE2b-256'],
258
+ HashAlgorithm['BLAKE2b-384'],
259
+ HashAlgorithm['BLAKE2b-512'],
260
+ HashAlgorithm.BLAKE3
261
+ ],
262
+ /^([a-fA-F0-9]{32})$|^([a-fA-F0-9]{40})$|^([a-fA-F0-9]{64})$|^([a-fA-F0-9]{96})$|^([a-fA-F0-9]{128})$/,
263
+ [
264
+ ExternalReferenceType.VCS,
265
+ ExternalReferenceType.IssueTracker,
266
+ ExternalReferenceType.Website,
267
+ ExternalReferenceType.Advisories,
268
+ ExternalReferenceType.BOM,
269
+ ExternalReferenceType.MailingList,
270
+ ExternalReferenceType.Social,
271
+ ExternalReferenceType.Chat,
272
+ ExternalReferenceType.Documentation,
273
+ ExternalReferenceType.Support,
274
+ ExternalReferenceType.Distribution,
275
+ ExternalReferenceType.License,
276
+ ExternalReferenceType.BuildMeta,
277
+ ExternalReferenceType.BuildSystem,
278
+ ExternalReferenceType.ReleaseNotes,
279
+ ExternalReferenceType.Other
280
+ ],
281
+ true,
282
+ true
283
+ ))
284
+
285
+ export const SpecVersionDict = Object.freeze(Object.fromEntries([
286
+ [Version.v1dot2, Spec1dot2],
287
+ [Version.v1dot3, Spec1dot3],
288
+ [Version.v1dot4, Spec1dot4]
289
+ ]) as { [key in Version]?: Readonly<Protocol> })
@@ -0,0 +1,33 @@
1
+ /*!
2
+ This file is part of CycloneDX JavaScript Library.
3
+
4
+ Licensed under the Apache License, Version 2.0 (the "License");
5
+ you may not use this file except in compliance with the License.
6
+ You may obtain a copy of the License at
7
+
8
+ http://www.apache.org/licenses/LICENSE-2.0
9
+
10
+ Unless required by applicable law or agreed to in writing, software
11
+ distributed under the License is distributed on an "AS IS" BASIS,
12
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ See the License for the specific language governing permissions and
14
+ limitations under the License.
15
+
16
+ SPDX-License-Identifier: Apache-2.0
17
+ Copyright (c) OWASP Foundation. All Rights Reserved.
18
+ */
19
+
20
+ /**
21
+ * Define the format for acceptable CPE URIs. Supports CPE 2.2 and CPE 2.3 formats.
22
+ * Refer to {@link https://nvd.nist.gov/products/cpe} for official specification.
23
+ * @see isCPE
24
+ */
25
+ export type CPE = string
26
+
27
+ /* eslint-disable-next-line no-useless-escape -- value directly from XML or JSON spec, surrounded with ^$ */
28
+ const cpePattern = /^([c][pP][eE]:\/[AHOaho]?(:[A-Za-z0-9\._\-~%]*){0,6})$|^(cpe:2\.3:[aho\*\-](:(((\?*|\*?)([a-zA-Z0-9\-\._]|(\\[\\\*\?!&quot;#$$%&amp;'\(\)\+,\/:;&lt;=&gt;@\[\]\^`\{\|}~]))+(\?*|\*?))|[\*\-])){5}(:(([a-zA-Z]{2,3}(-([a-zA-Z]{2}|[0-9]{3}))?)|[\*\-]))(:(((\?*|\*?)([a-zA-Z0-9\-\._]|(\\[\\\*\?!&quot;#$$%&amp;'\(\)\+,\/:;&lt;=&gt;@\[\]\^`\{\|}~]))+(\?*|\*?))|[\*\-])){4})$/
29
+
30
+ export function isCPE (value: any): value is CPE {
31
+ return typeof value === 'string' &&
32
+ cpePattern.test(value)
33
+ }
@@ -0,0 +1,23 @@
1
+ /*!
2
+ This file is part of CycloneDX JavaScript Library.
3
+
4
+ Licensed under the Apache License, Version 2.0 (the "License");
5
+ you may not use this file except in compliance with the License.
6
+ You may obtain a copy of the License at
7
+
8
+ http://www.apache.org/licenses/LICENSE-2.0
9
+
10
+ Unless required by applicable law or agreed to in writing, software
11
+ distributed under the License is distributed on an "AS IS" BASIS,
12
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ See the License for the specific language governing permissions and
14
+ limitations under the License.
15
+
16
+ SPDX-License-Identifier: Apache-2.0
17
+ Copyright (c) OWASP Foundation. All Rights Reserved.
18
+ */
19
+
20
+ export * from './cpe'
21
+ export * from './integer'
22
+ export * from './mimeType'
23
+ export * from './urn'
@@ -0,0 +1,50 @@
1
+ /*!
2
+ This file is part of CycloneDX JavaScript Library.
3
+
4
+ Licensed under the Apache License, Version 2.0 (the "License");
5
+ you may not use this file except in compliance with the License.
6
+ You may obtain a copy of the License at
7
+
8
+ http://www.apache.org/licenses/LICENSE-2.0
9
+
10
+ Unless required by applicable law or agreed to in writing, software
11
+ distributed under the License is distributed on an "AS IS" BASIS,
12
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ See the License for the specific language governing permissions and
14
+ limitations under the License.
15
+
16
+ SPDX-License-Identifier: Apache-2.0
17
+ Copyright (c) OWASP Foundation. All Rights Reserved.
18
+ */
19
+
20
+ /**
21
+ * Integer
22
+ * @see isInteger
23
+ */
24
+ export type Integer = number | NonNegativeInteger
25
+
26
+ export function isInteger (value: any): value is Integer {
27
+ return Number.isInteger(value)
28
+ }
29
+
30
+ /**
31
+ * Integer >= 0
32
+ * @see isNonNegativeInteger
33
+ */
34
+ export type NonNegativeInteger = number | PositiveInteger
35
+
36
+ export function isNonNegativeInteger (value: any): value is NonNegativeInteger {
37
+ return isInteger(value) &&
38
+ value >= 0
39
+ }
40
+
41
+ /**
42
+ * Integer > 0
43
+ * @see isPositiveInteger
44
+ */
45
+ export type PositiveInteger = number
46
+
47
+ export function isPositiveInteger (value: any): value is PositiveInteger {
48
+ return isInteger(value) &&
49
+ value > 0
50
+ }
@@ -0,0 +1,31 @@
1
+ /*!
2
+ This file is part of CycloneDX JavaScript Library.
3
+
4
+ Licensed under the Apache License, Version 2.0 (the "License");
5
+ you may not use this file except in compliance with the License.
6
+ You may obtain a copy of the License at
7
+
8
+ http://www.apache.org/licenses/LICENSE-2.0
9
+
10
+ Unless required by applicable law or agreed to in writing, software
11
+ distributed under the License is distributed on an "AS IS" BASIS,
12
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ See the License for the specific language governing permissions and
14
+ limitations under the License.
15
+
16
+ SPDX-License-Identifier: Apache-2.0
17
+ Copyright (c) OWASP Foundation. All Rights Reserved.
18
+ */
19
+
20
+ /**
21
+ * @see isMimeType
22
+ */
23
+ export type MimeType = string
24
+
25
+ /* regular expression was taken from the CycloneDX schema definitions. */
26
+ const mimeTypePattern = /^[-+a-z0-9.]+\/[-+a-z0-9.]+$/
27
+
28
+ export function isMimeType (value: any): value is MimeType {
29
+ return typeof value === 'string' &&
30
+ mimeTypePattern.test(value)
31
+ }
@@ -0,0 +1,33 @@
1
+ /*!
2
+ This file is part of CycloneDX JavaScript Library.
3
+
4
+ Licensed under the Apache License, Version 2.0 (the "License");
5
+ you may not use this file except in compliance with the License.
6
+ You may obtain a copy of the License at
7
+
8
+ http://www.apache.org/licenses/LICENSE-2.0
9
+
10
+ Unless required by applicable law or agreed to in writing, software
11
+ distributed under the License is distributed on an "AS IS" BASIS,
12
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ See the License for the specific language governing permissions and
14
+ limitations under the License.
15
+
16
+ SPDX-License-Identifier: Apache-2.0
17
+ Copyright (c) OWASP Foundation. All Rights Reserved.
18
+ */
19
+
20
+ /**
21
+ * Defines a string representation of a UUID conforming to RFC 4122.
22
+ * @see {@link https://datatracker.ietf.org/doc/html/rfc4122}
23
+ * @see isUrnUuid
24
+ */
25
+ export type UrnUuid = string
26
+
27
+ /* regular expression was taken from the CycloneDX schema definitions. */
28
+ const urnUuidPattern = /^urn:uuid:[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/
29
+
30
+ export function isUrnUuid (value: any): value is UrnUuid {
31
+ return typeof value === 'string' &&
32
+ urnUuidPattern.test(value)
33
+ }