@mark1russell7/package-id 0.1.0 → 0.1.2
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.
- package/README.md +5 -0
- package/build/index.d.ts +49 -2
- package/build/index.d.ts.map +1 -1
- package/build/index.js +212 -1
- package/build/index.js.map +1 -1
- package/package.json +1 -1
- package/src/cpe.ts +173 -0
- package/src/index.ts +3 -1
- package/src/model.ts +55 -0
package/README.md
CHANGED
|
@@ -43,6 +43,11 @@ versContains(parseVers("vers:npm/>=1.0.0|<1.2.3")!, "1.1.0");
|
|
|
43
43
|
| `formatVers(vers)` | The `vers` text of a range, with the constraints in the order of their versions. |
|
|
44
44
|
| `versContains(vers, version)` | True when the version is in the range. The result is `undefined` when the order is not known. |
|
|
45
45
|
| `versEnd(vers, version)` | The end `<` of the part of the range that holds the version: for an advisory, the fixed version. |
|
|
46
|
+
| `parseCpe(text)` | The attributes of a CPE name: a formatted string of CPE 2.3 or a URI of CPE 2.2. The result is `undefined` for a text that is not a CPE name. |
|
|
47
|
+
| `formatCpe(cpe)` | The formatted string of CPE 2.3, in lower case, with a backslash before each special character only. |
|
|
48
|
+
| `cpeProductOf(text)` | The part, the vendor and the product of a CPE name, with `*` for each other attribute. |
|
|
49
|
+
| `cpeVersionOf(cpe)` | The version of a CPE name with no backslashes, or `undefined` for any version, no version or a wildcard. |
|
|
50
|
+
| `modelNumberMatches(pattern, model)` | `true` when a model number or a SKU matches a CSAF pattern: `*` for any run, `?` for one character. |
|
|
46
51
|
|
|
47
52
|
## The canonical form
|
|
48
53
|
|
package/build/index.d.ts
CHANGED
|
@@ -1,7 +1,54 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Package identities: package URLs (purl), the purl of each OSV ecosystem, the version order of each ecosystem
|
|
2
|
+
* Package identities: package URLs (purl), the purl of each OSV ecosystem, the version order of each ecosystem, version ranges (vers) and CPE names. The functions are plain functions with
|
|
3
3
|
* no fetch.
|
|
4
4
|
*/
|
|
5
|
+
/**
|
|
6
|
+
* CPE names of the NIST specification (NISTIR 7695): the formatted string of CPE 2.3, for example
|
|
7
|
+
* `cpe:2.3:a:apache:http_server:2.4.62:*:*:*:*:*:*:*`, and the URI of CPE 2.2, for example `cpe:/a:apache:http_server:2.4.62`.
|
|
8
|
+
* The functions read a name, write it as a formatted string and give the product of a name with no version. The match
|
|
9
|
+
* of a CSAF advisory to a device uses them: a vendor gives a CPE when a product has no purl.
|
|
10
|
+
*/
|
|
11
|
+
/** The part of a CPE name: `a` an application, `o` an operating system, `h` a hardware device, `*` any part. */
|
|
12
|
+
type CpePart = "a" | "o" | "h" | "*";
|
|
13
|
+
/**
|
|
14
|
+
* A CPE name. Each attribute is a value of the formatted string, in lower case: `*` is any value, `-` is no value. A
|
|
15
|
+
* special character has a backslash before it, for example `\!`. An unquoted `*` or `?` in a value is a wildcard.
|
|
16
|
+
*/
|
|
17
|
+
interface Cpe {
|
|
18
|
+
readonly part: CpePart;
|
|
19
|
+
readonly vendor: string;
|
|
20
|
+
readonly product: string;
|
|
21
|
+
readonly version: string;
|
|
22
|
+
readonly update: string;
|
|
23
|
+
readonly edition: string;
|
|
24
|
+
readonly language: string;
|
|
25
|
+
readonly swEdition: string;
|
|
26
|
+
readonly targetSw: string;
|
|
27
|
+
readonly targetHw: string;
|
|
28
|
+
readonly other: string;
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* This function reads a CPE name: a formatted string of CPE 2.3 or a URI of CPE 2.2. A formatted string with fewer than
|
|
32
|
+
* eleven attributes gets `*` for each missing attribute. A text that is not a CPE name gives `undefined`.
|
|
33
|
+
*/
|
|
34
|
+
export declare function parseCpe(text: string): Cpe | undefined;
|
|
35
|
+
/** This function writes a name as a formatted string of CPE 2.3, with each of its eleven attributes. */
|
|
36
|
+
export declare function formatCpe(cpe: Cpe): string;
|
|
37
|
+
/**
|
|
38
|
+
* This function gives the product of a CPE name: the formatted string with the part, the vendor and the product. Each
|
|
39
|
+
* other attribute is `*`. A name with no vendor or no product, or with a wildcard in them, gives `undefined`.
|
|
40
|
+
*/
|
|
41
|
+
export declare function cpeProductOf(text: string): string | undefined;
|
|
42
|
+
/**
|
|
43
|
+
* This function gives the version of a CPE name with no backslashes, for example `2.4.62`. A name with any version, no
|
|
44
|
+
* version or a wildcard in its version gives `undefined`.
|
|
45
|
+
*/
|
|
46
|
+
export declare function cpeVersionOf(cpe: Cpe): string | undefined;
|
|
47
|
+
/**
|
|
48
|
+
* This function tells if a model number or a SKU matches a pattern of a CSAF advisory. An empty pattern matches nothing.
|
|
49
|
+
* The match keeps the last `*` and its place, so its time is at most the product of the two lengths.
|
|
50
|
+
*/
|
|
51
|
+
export declare function modelNumberMatches(pattern: string, model: string): boolean;
|
|
5
52
|
/**
|
|
6
53
|
* Package URLs (purl): parse, format and normalize, as the purl specification tells
|
|
7
54
|
* (`https://github.com/package-url/purl-spec`). The form is `pkg:type/namespace/name@version?qualifiers#subpath`.
|
|
@@ -163,5 +210,5 @@ export declare function compareIntdot(a: string, b: string): number | undefined;
|
|
|
163
210
|
* comes after the end. A rest with letters before such a number, for example ` SP1` or `-beta`, has no known order.
|
|
164
211
|
*/
|
|
165
212
|
export declare function compareGeneric(a: string, b: string): number | undefined;
|
|
166
|
-
export type { OsvEvent, OsvRange, Purl, Vers, VersComparator, VersConstraint, VersionScheme };
|
|
213
|
+
export type { Cpe, CpePart, OsvEvent, OsvRange, Purl, Vers, VersComparator, VersConstraint, VersionScheme };
|
|
167
214
|
//# sourceMappingURL=index.d.ts.map
|
package/build/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","names":[],"sources":["../src/purl.ts","../src/vers.ts","../src/osv.ts","../src/version.ts"],"mappings":";;;;;;;;;;;
|
|
1
|
+
{"version":3,"file":"index.d.ts","names":[],"sources":["../src/cpe.ts","../src/model.ts","../src/purl.ts","../src/vers.ts","../src/osv.ts","../src/version.ts"],"mappings":";;;;;;;;;;;KAQY;;;;;UAMK;WACN,MAAM;WACN;WACA;WACA;WACA;WACA;WACA;WACA;WACA;WACA;WACA;;;;;;wBAiHK,SAAS,eAAe;;wBAWxB,UAAU,KAAK;;;;;wBAQf,aAAa;;;;;wBAYb,aAAa,KAAK;;;;;wBC1IlB,mBAAmB,iBAAiB;;;;;;;;UCvBnC;;WAEN;;WAEA;;WAEA;;WAEA;;WAEA,aAAa,SAAS;;WAEtB;;;;;;;wBAmDK,cAAc,MAAM,OAAO;;;;;wBAmC3B,UAAU,eAAe;;;;;wBA2DzB,WAAW,MAAM;;;;;wBAkBjB,cAAc;;KChLlB;;UAGK;WACN,YAAY;WACZ;;;UAIM;;WAEN;;WAEA;WACA,sBAAsB;;;wBAsBjB,UAAU,eAAe;;;;;wBAsBzB,WAAW,MAAM;;;;;;wBAuBjB,aAAa,MAAM,MAAM;;;;;;wBAqCzB,QAAQ,MAAM,MAAM;;;;;qBChHvB,gBAAgB,SAAS;;;;;wBAgDtB,QAAQ,mBAAmB;;;;;wBAe3B,eAAe;WAAgB;WAA4B;WAAuB;;;UAMjF;WACN;WACA;WACA;WACA;;;UAIM;WACN;WACA,iBAAiB;;;;;;;;;;wBAWZ,aAAa,mBAAmB,OAAO,WAAW;;;;;;;KChGtD;;wBAeI,cAAc,eAAe;;;;;wBAQ7B,gBAAgB,gBAAgB,WAAW;;wBAiE3C,cAAc,WAAW;;;;;wBAUzB,UAAU,WAAW;;wBA+CrB,cAAc,WAAW;;wBAqEzB,cAAc,WAAW;;wBAyDzB,WAAW,WAAW;;;;;wBAkBtB,cAAc,WAAW;;;;;;;;;;;;;wBAmCzB,eAAe,WAAW"}
|
package/build/index.js
CHANGED
|
@@ -1,3 +1,214 @@
|
|
|
1
|
+
// src/cpe.ts
|
|
2
|
+
/** The attributes of a name, in the order of the formatted string. */
|
|
3
|
+
const ATTRIBUTES = [
|
|
4
|
+
"part",
|
|
5
|
+
"vendor",
|
|
6
|
+
"product",
|
|
7
|
+
"version",
|
|
8
|
+
"update",
|
|
9
|
+
"edition",
|
|
10
|
+
"language",
|
|
11
|
+
"swEdition",
|
|
12
|
+
"targetSw",
|
|
13
|
+
"targetHw",
|
|
14
|
+
"other"
|
|
15
|
+
];
|
|
16
|
+
/** The characters that a value keeps with no backslash. */
|
|
17
|
+
const PLAIN = /^[a-z0-9._-]$/;
|
|
18
|
+
/** This function gives the formatted-string form of one character of a value: a special character gets a backslash. */
|
|
19
|
+
const quoted = (char) => PLAIN.test(char) ? char : `\\${char}`;
|
|
20
|
+
/**
|
|
21
|
+
* This function gives the canonical form of a value of a formatted string, or `undefined` for a value that is not valid.
|
|
22
|
+
* The form is lower case. A backslash stays only before a special character. Each other special character gets one.
|
|
23
|
+
*/
|
|
24
|
+
function canonicalValue(value) {
|
|
25
|
+
const text = value.toLowerCase();
|
|
26
|
+
if (text === "") return void 0;
|
|
27
|
+
if (text === "*" || text === "-") return text;
|
|
28
|
+
let out = "";
|
|
29
|
+
for (let index = 0; index < text.length; index += 1) {
|
|
30
|
+
const char = text[index];
|
|
31
|
+
if (char === "\\") {
|
|
32
|
+
const next = text[index + 1];
|
|
33
|
+
if (next === void 0) return void 0;
|
|
34
|
+
out += quoted(next);
|
|
35
|
+
index += 1;
|
|
36
|
+
} else if (char === "*" || char === "?") {
|
|
37
|
+
if (!/^[*?]+$/.test(text.slice(0, index + 1)) && !/^[*?]+$/.test(text.slice(index))) return void 0;
|
|
38
|
+
out += char;
|
|
39
|
+
} else if (char.charCodeAt(0) < 33 || char.charCodeAt(0) > 126) return;
|
|
40
|
+
else out += quoted(char);
|
|
41
|
+
}
|
|
42
|
+
return out === "-" ? "\\-" : out;
|
|
43
|
+
}
|
|
44
|
+
/** This function splits a formatted string at each colon that has no backslash before it. */
|
|
45
|
+
function splitFormatted(text) {
|
|
46
|
+
const values = [];
|
|
47
|
+
let current = "";
|
|
48
|
+
for (let index = 0; index < text.length; index += 1) {
|
|
49
|
+
const char = text[index];
|
|
50
|
+
if (char === "\\" && index + 1 < text.length) {
|
|
51
|
+
current += char + text[index + 1];
|
|
52
|
+
index += 1;
|
|
53
|
+
} else if (char === ":") {
|
|
54
|
+
values.push(current);
|
|
55
|
+
current = "";
|
|
56
|
+
} else current += char;
|
|
57
|
+
}
|
|
58
|
+
values.push(current);
|
|
59
|
+
return values;
|
|
60
|
+
}
|
|
61
|
+
/** This function gives the formatted-string value of one component of a CPE 2.2 URI, or `undefined`. */
|
|
62
|
+
function uriValue(component) {
|
|
63
|
+
if (component === "") return "*";
|
|
64
|
+
if (component === "-") return "-";
|
|
65
|
+
let out = "";
|
|
66
|
+
for (let index = 0; index < component.length; index += 1) {
|
|
67
|
+
const char = component[index];
|
|
68
|
+
if (char !== "%") {
|
|
69
|
+
if (!/^[A-Za-z0-9._~-]$/.test(char)) return void 0;
|
|
70
|
+
out += quoted(char.toLowerCase());
|
|
71
|
+
continue;
|
|
72
|
+
}
|
|
73
|
+
const code = component.slice(index + 1, index + 3);
|
|
74
|
+
if (!/^[0-9A-Fa-f]{2}$/.test(code)) return void 0;
|
|
75
|
+
index += 2;
|
|
76
|
+
const value = Number.parseInt(code, 16);
|
|
77
|
+
if (value === 1) out += "?";
|
|
78
|
+
else if (value === 2) out += "*";
|
|
79
|
+
else if (value < 33 || value > 126) return void 0;
|
|
80
|
+
else out += quoted(String.fromCharCode(value).toLowerCase());
|
|
81
|
+
}
|
|
82
|
+
return canonicalValue(out);
|
|
83
|
+
}
|
|
84
|
+
/** This function gives a name from its values in the order of the formatted string, or `undefined`. */
|
|
85
|
+
function cpeOf(values) {
|
|
86
|
+
const canonical = values.map(canonicalValue);
|
|
87
|
+
if (canonical.some((value) => value === void 0)) return void 0;
|
|
88
|
+
const part = canonical[0];
|
|
89
|
+
if (part !== "a" && part !== "o" && part !== "h" && part !== "*") return void 0;
|
|
90
|
+
return Object.fromEntries(ATTRIBUTES.map((name, index) => [name, canonical[index] ?? "*"]));
|
|
91
|
+
}
|
|
92
|
+
/** This function reads a CPE 2.2 URI. The packed edition (`~edition~sw_edition~target_sw~target_hw~other`) gives five attributes. */
|
|
93
|
+
function parseUri(text) {
|
|
94
|
+
const components = text.slice(5).split(":");
|
|
95
|
+
if (components.length > 7) return void 0;
|
|
96
|
+
const [part = "", vendor = "", product = "", version = "", update = "", edition = "", language = ""] = components;
|
|
97
|
+
const packed = edition.startsWith("~") ? edition.slice(1).split("~") : void 0;
|
|
98
|
+
if (packed !== void 0 && packed.length !== 5) return void 0;
|
|
99
|
+
const values = [
|
|
100
|
+
part,
|
|
101
|
+
vendor,
|
|
102
|
+
product,
|
|
103
|
+
version,
|
|
104
|
+
update,
|
|
105
|
+
packed?.[0] ?? edition,
|
|
106
|
+
language,
|
|
107
|
+
...packed?.slice(1) ?? []
|
|
108
|
+
].map(uriValue);
|
|
109
|
+
if (values.some((value) => value === void 0)) return void 0;
|
|
110
|
+
return cpeOf(values);
|
|
111
|
+
}
|
|
112
|
+
/**
|
|
113
|
+
* This function reads a CPE name: a formatted string of CPE 2.3 or a URI of CPE 2.2. A formatted string with fewer than
|
|
114
|
+
* eleven attributes gets `*` for each missing attribute. A text that is not a CPE name gives `undefined`.
|
|
115
|
+
*/
|
|
116
|
+
function parseCpe(text) {
|
|
117
|
+
const trimmed = text.trim();
|
|
118
|
+
const lower = trimmed.toLowerCase();
|
|
119
|
+
if (lower.startsWith("cpe:/")) return parseUri(trimmed);
|
|
120
|
+
if (!lower.startsWith("cpe:2.3:")) return void 0;
|
|
121
|
+
const values = splitFormatted(trimmed.slice(8));
|
|
122
|
+
if (values.length < 3 || values.length > ATTRIBUTES.length) return void 0;
|
|
123
|
+
return cpeOf(values);
|
|
124
|
+
}
|
|
125
|
+
/** This function writes a name as a formatted string of CPE 2.3, with each of its eleven attributes. */
|
|
126
|
+
function formatCpe(cpe) {
|
|
127
|
+
return `cpe:2.3:${ATTRIBUTES.map((name) => cpe[name]).join(":")}`;
|
|
128
|
+
}
|
|
129
|
+
/**
|
|
130
|
+
* This function gives the product of a CPE name: the formatted string with the part, the vendor and the product. Each
|
|
131
|
+
* other attribute is `*`. A name with no vendor or no product, or with a wildcard in them, gives `undefined`.
|
|
132
|
+
*/
|
|
133
|
+
function cpeProductOf(text) {
|
|
134
|
+
const cpe = parseCpe(text);
|
|
135
|
+
if (cpe === void 0) return void 0;
|
|
136
|
+
const specific = (value) => value !== "*" && value !== "-" && !/(^|[^\\])[*?]/.test(value);
|
|
137
|
+
if (!specific(cpe.vendor) || !specific(cpe.product)) return void 0;
|
|
138
|
+
return formatCpe({
|
|
139
|
+
part: cpe.part,
|
|
140
|
+
vendor: cpe.vendor,
|
|
141
|
+
product: cpe.product,
|
|
142
|
+
version: "*",
|
|
143
|
+
update: "*",
|
|
144
|
+
edition: "*",
|
|
145
|
+
language: "*",
|
|
146
|
+
swEdition: "*",
|
|
147
|
+
targetSw: "*",
|
|
148
|
+
targetHw: "*",
|
|
149
|
+
other: "*"
|
|
150
|
+
});
|
|
151
|
+
}
|
|
152
|
+
/**
|
|
153
|
+
* This function gives the version of a CPE name with no backslashes, for example `2.4.62`. A name with any version, no
|
|
154
|
+
* version or a wildcard in its version gives `undefined`.
|
|
155
|
+
*/
|
|
156
|
+
function cpeVersionOf(cpe) {
|
|
157
|
+
if (cpe.version === "*" || cpe.version === "-" || /(^|[^\\])[*?]/.test(cpe.version)) return void 0;
|
|
158
|
+
return cpe.version.replace(/\\(.)/g, "$1");
|
|
159
|
+
}
|
|
160
|
+
// src/model.ts
|
|
161
|
+
/** This function gives the tokens of a pattern. A backslash at the end is a literal backslash. */
|
|
162
|
+
function tokensOf(pattern) {
|
|
163
|
+
const chars = Array.from(pattern);
|
|
164
|
+
const tokens = [];
|
|
165
|
+
for (let index = 0; index < chars.length; index++) {
|
|
166
|
+
const char = chars[index];
|
|
167
|
+
const next = chars[index + 1];
|
|
168
|
+
if (char === "\\" && next !== void 0 && (next === "*" || next === "?" || next === "\\")) {
|
|
169
|
+
tokens.push({
|
|
170
|
+
kind: "char",
|
|
171
|
+
char: next
|
|
172
|
+
});
|
|
173
|
+
index++;
|
|
174
|
+
} else if (char === "*") {
|
|
175
|
+
if (tokens.at(-1)?.kind !== "any") tokens.push({ kind: "any" });
|
|
176
|
+
} else if (char === "?") tokens.push({ kind: "one" });
|
|
177
|
+
else tokens.push({
|
|
178
|
+
kind: "char",
|
|
179
|
+
char
|
|
180
|
+
});
|
|
181
|
+
}
|
|
182
|
+
return tokens;
|
|
183
|
+
}
|
|
184
|
+
/**
|
|
185
|
+
* This function tells if a model number or a SKU matches a pattern of a CSAF advisory. An empty pattern matches nothing.
|
|
186
|
+
* The match keeps the last `*` and its place, so its time is at most the product of the two lengths.
|
|
187
|
+
*/
|
|
188
|
+
function modelNumberMatches(pattern, model) {
|
|
189
|
+
if (pattern === "") return false;
|
|
190
|
+
const tokens = tokensOf(pattern);
|
|
191
|
+
const chars = Array.from(model);
|
|
192
|
+
let token = 0;
|
|
193
|
+
let char = 0;
|
|
194
|
+
let star = -1;
|
|
195
|
+
let resume = 0;
|
|
196
|
+
while (char < chars.length) {
|
|
197
|
+
const current = tokens[token];
|
|
198
|
+
if (current !== void 0 && (current.kind === "one" || current.kind === "char" && current.char === chars[char])) {
|
|
199
|
+
token++;
|
|
200
|
+
char++;
|
|
201
|
+
} else if (current?.kind === "any") {
|
|
202
|
+
star = token++;
|
|
203
|
+
resume = char;
|
|
204
|
+
} else if (star >= 0) {
|
|
205
|
+
token = star + 1;
|
|
206
|
+
char = ++resume;
|
|
207
|
+
} else return false;
|
|
208
|
+
}
|
|
209
|
+
while (tokens[token]?.kind === "any") token++;
|
|
210
|
+
return token === tokens.length;
|
|
211
|
+
}
|
|
1
212
|
// src/purl.ts
|
|
2
213
|
/** The pattern of a type: a letter first, then letters, digits, `.`, `+` or `-`. */
|
|
3
214
|
const TYPE = /^[a-z][a-z0-9.+-]*$/;
|
|
@@ -718,6 +929,6 @@ function versEnd(vers, version) {
|
|
|
718
929
|
const next = sortConstraints(vers.scheme, vers.constraints.filter((c) => c.comparator !== "=" && c.comparator !== "!="))?.find((c) => compareVersions(vers.scheme, version, c.version) < 0);
|
|
719
930
|
return next?.comparator === "<" ? next.version : void 0;
|
|
720
931
|
}
|
|
721
|
-
export { OSV_PURL_TYPES, compareDebian, compareGeneric, compareGo, compareIntdot, comparePep440, compareRpm, compareSemver, compareVersions, formatPurl, formatVers, normalizePurl, osvPackagePurl, osvPurl, osvRangeVers, packagePurlOf, parsePurl, parseVers, versContains, versEnd, versionScheme };
|
|
932
|
+
export { OSV_PURL_TYPES, compareDebian, compareGeneric, compareGo, compareIntdot, comparePep440, compareRpm, compareSemver, compareVersions, cpeProductOf, cpeVersionOf, formatCpe, formatPurl, formatVers, modelNumberMatches, normalizePurl, osvPackagePurl, osvPurl, osvRangeVers, packagePurlOf, parseCpe, parsePurl, parseVers, versContains, versEnd, versionScheme };
|
|
722
933
|
|
|
723
934
|
//# sourceMappingURL=index.js.map
|
package/build/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","names":[],"sources":["../src/purl.ts","../src/version.ts","../src/osv.ts","../src/vers.ts"],"sourcesContent":["/**\n * Package URLs (purl): parse, format and normalize, as the purl specification tells\n * (`https://github.com/package-url/purl-spec`). The form is `pkg:type/namespace/name@version?qualifiers#subpath`.\n *\n * The functions are plain functions with no fetch and no state.\n */\n\n/** A package URL as its parts. Each text part is decoded: it has no percent-encoding. */\nexport interface Purl {\n /** The type of the package, in lower case, for example `npm` or `pypi`. */\n readonly type: string;\n /** The namespace, with `/` between its segments, or `undefined` when the purl has no namespace. */\n readonly namespace?: string;\n /** The name of the package. */\n readonly name: string;\n /** The version, or `undefined` when the purl has no version. */\n readonly version?: string;\n /** The qualifiers, with lower-case keys. A qualifier with an empty value is not in the record. */\n readonly qualifiers?: Readonly<Record<string, string>>;\n /** The subpath, with `/` between its segments, or `undefined` when the purl has no subpath. */\n readonly subpath?: string;\n}\n\n/** The pattern of a type: a letter first, then letters, digits, `.`, `+` or `-`. */\nconst TYPE = /^[a-z][a-z0-9.+-]*$/;\n\n/** The pattern of a qualifier key: a letter first, then letters, digits, `.`, `-` or `_`. */\nconst KEY = /^[a-z][a-z0-9._-]*$/;\n\n/**\n * The types whose namespace and name are not case sensitive. The canonical form of these parts is lower case.\n * The list comes from the type definitions of the purl specification.\n */\nconst LOWER_NAMESPACE_AND_NAME: ReadonlySet<string> = new Set([\"alpm\", \"apk\", \"bitbucket\", \"composer\", \"deb\", \"github\", \"golang\", \"npm\"]);\n\n/** The types whose name only is not case sensitive. The canonical form of the name is lower case. */\nconst LOWER_NAME: ReadonlySet<string> = new Set([\"hex\", \"pub\", \"pypi\"]);\n\n/** This function percent-encodes one part of a purl. A letter, a digit, `.-_~` and `:` stay as they are. */\nfunction encode(text: string): string {\n return encodeURIComponent(text)\n .replace(/[!'()*]/g, (character) => `%${character.charCodeAt(0).toString(16).toUpperCase()}`)\n .replace(/%3A/g, \":\");\n}\n\n/** This function decodes one part of a purl, or gives `undefined` for a bad percent-encoding. */\nfunction decode(text: string): string | undefined {\n try {\n return decodeURIComponent(text);\n } catch {\n return undefined;\n }\n}\n\n/** This function splits a path into its decoded segments. It discards each empty segment. */\nfunction segments(text: string): string[] | undefined {\n const parts: string[] = [];\n for (const raw of text.split(\"/\")) {\n if (raw === \"\") continue;\n const part = decode(raw);\n if (part === undefined) return undefined;\n parts.push(part);\n }\n return parts;\n}\n\n/**\n * This function gives the canonical parts of a purl. The type and the qualifier keys are in lower case. The parts\n * follow the case rules of the type, and no part is empty.\n * It gives `undefined` when a part breaks a rule of the specification.\n */\nexport function normalizePurl(purl: Purl): Purl | undefined {\n const type = purl.type.toLowerCase();\n if (!TYPE.test(type)) return undefined;\n const lowerAll = LOWER_NAMESPACE_AND_NAME.has(type);\n const lowerName = lowerAll || LOWER_NAME.has(type);\n let name = lowerName ? purl.name.toLowerCase() : purl.name;\n if (type === \"pypi\") name = name.replace(/_/g, \"-\");\n if (name === \"\") return undefined;\n const space = purl.namespace?.split(\"/\").filter((segment) => segment !== \"\").join(\"/\");\n const namespace = space === undefined || space === \"\" ? undefined : lowerAll ? space.toLowerCase() : space;\n if (type === \"maven\" && namespace === undefined) return undefined;\n const qualifiers: Record<string, string> = {};\n for (const [key, value] of Object.entries(purl.qualifiers ?? {})) {\n const lower = key.toLowerCase();\n if (!KEY.test(lower)) return undefined;\n if (value !== \"\") qualifiers[lower] = value;\n }\n const subpath = purl.subpath\n ?.split(\"/\")\n .filter((segment) => segment !== \"\" && segment !== \".\" && segment !== \"..\")\n .join(\"/\");\n return {\n type,\n ...(namespace === undefined ? {} : { namespace }),\n name,\n ...(purl.version === undefined || purl.version === \"\" ? {} : { version: purl.version }),\n ...(Object.keys(qualifiers).length === 0 ? {} : { qualifiers }),\n ...(subpath === undefined || subpath === \"\" ? {} : { subpath }),\n };\n}\n\n/**\n * This function reads a purl text into its parts, as the parse steps of the specification tell, and normalizes them.\n * It gives `undefined` when the text is not a valid purl.\n */\nexport function parsePurl(text: string): Purl | undefined {\n let rest = text.trim();\n let subpath: string | undefined;\n const hash = rest.indexOf(\"#\");\n if (hash >= 0) {\n const parts = segments(rest.slice(hash + 1));\n if (parts === undefined) return undefined;\n subpath = parts.filter((segment) => segment !== \".\" && segment !== \"..\").join(\"/\");\n rest = rest.slice(0, hash);\n }\n let qualifiers: Record<string, string> | undefined;\n const question = rest.indexOf(\"?\");\n if (question >= 0) {\n qualifiers = {};\n for (const pair of rest.slice(question + 1).split(\"&\")) {\n if (pair === \"\") continue;\n const equal = pair.indexOf(\"=\");\n if (equal <= 0) return undefined;\n const key = pair.slice(0, equal).toLowerCase();\n const value = decode(pair.slice(equal + 1));\n if (value === undefined || key in qualifiers) return undefined;\n qualifiers[key] = value;\n }\n rest = rest.slice(0, question);\n }\n const colon = rest.indexOf(\":\");\n if (colon < 0 || rest.slice(0, colon).toLowerCase() !== \"pkg\") return undefined;\n rest = rest.slice(colon + 1).replace(/^\\/+/, \"\");\n const slash = rest.indexOf(\"/\");\n if (slash <= 0) return undefined;\n const type = rest.slice(0, slash);\n rest = rest.slice(slash + 1);\n let version: string | undefined;\n const at = rest.lastIndexOf(\"@\");\n // An npm scope in a purl is `%40`, so a raw `@` starts the version. A raw `@` at the start of the\n // namespace is not a version.\n if (at > 0) {\n version = decode(rest.slice(at + 1));\n if (version === undefined) return undefined;\n rest = rest.slice(0, at);\n }\n const path = segments(rest);\n if (path === undefined || path.length === 0) return undefined;\n const name = path[path.length - 1]!;\n const namespace = path.length > 1 ? path.slice(0, -1).join(\"/\") : undefined;\n return normalizePurl({\n type,\n ...(namespace === undefined ? {} : { namespace }),\n name,\n ...(version === undefined ? {} : { version }),\n ...(qualifiers === undefined ? {} : { qualifiers }),\n ...(subpath === undefined ? {} : { subpath }),\n });\n}\n\n/**\n * This function writes the canonical text of a purl: the parts normalized, each part percent-encoded and the\n * qualifiers in the order of their keys. It gives `undefined` when a part breaks a rule of the specification.\n */\nexport function formatPurl(purl: Purl): string | undefined {\n const canonical = normalizePurl(purl);\n if (canonical === undefined) return undefined;\n let text = `pkg:${canonical.type}/`;\n if (canonical.namespace !== undefined) text += `${canonical.namespace.split(\"/\").map(encode).join(\"/\")}/`;\n text += encode(canonical.name);\n if (canonical.version !== undefined) text += `@${encode(canonical.version)}`;\n const keys = Object.keys(canonical.qualifiers ?? {}).sort();\n // A qualifier value keeps its `/`, as the test suite of the specification does with `repository_url`.\n if (keys.length > 0) text += `?${keys.map((key) => `${key}=${encode(canonical.qualifiers![key]!).replace(/%2F/g, \"/\")}`).join(\"&\")}`;\n if (canonical.subpath !== undefined) text += `#${canonical.subpath.split(\"/\").map(encode).join(\"/\")}`;\n return text;\n}\n\n/**\n * This function gives the canonical purl of the package with no version, no qualifiers and no subpath. A person who\n * names a package with this text names each version of it. It gives `undefined` when the text is not a valid purl.\n */\nexport function packagePurlOf(text: string): string | undefined {\n const purl = parsePurl(text);\n return purl === undefined ? undefined : formatPurl({ type: purl.type, ...(purl.namespace === undefined ? {} : { namespace: purl.namespace }), name: purl.name });\n}\n","/**\n * The version order of each ecosystem: SemVer, Go modules, PEP 440, Debian and RPM. The `vers` schemes `intdot` and\n * `generic` have an order too. Each function compares two versions of one scheme. A text that is not a version of the\n * scheme gives `undefined`, not a guess.\n */\n\n/** The version schemes that this module compares. */\nexport type VersionScheme = \"semver\" | \"golang\" | \"pypi\" | \"deb\" | \"rpm\" | \"intdot\" | \"generic\";\n\n/** The version scheme of each purl type whose order this module knows. */\nconst TYPE_SCHEMES: ReadonlyMap<string, VersionScheme> = new Map([\n [\"npm\", \"semver\"],\n [\"cargo\", \"semver\"],\n [\"semver\", \"semver\"],\n [\"golang\", \"golang\"],\n [\"pypi\", \"pypi\"],\n [\"deb\", \"deb\"],\n [\"rpm\", \"rpm\"],\n [\"generic\", \"generic\"],\n]);\n\n/** This function gives the version scheme of a purl type, or `undefined` for a type whose order this module does not know. */\nexport function versionScheme(type: string): VersionScheme | undefined {\n return TYPE_SCHEMES.get(type.toLowerCase());\n}\n\n/**\n * This function compares two versions of one scheme. The result is below 0 when `a` comes before `b`, 0 when they are\n * equal and above 0 when `a` comes after `b`. When a text is not a version of the scheme, the result is `undefined`.\n */\nexport function compareVersions(scheme: string, a: string, b: string): number | undefined {\n switch (scheme) {\n case \"semver\":\n case \"npm\":\n case \"cargo\":\n return compareSemver(a, b);\n case \"golang\":\n return compareGo(a, b);\n case \"pypi\":\n return comparePep440(a, b);\n case \"deb\":\n return compareDebian(a, b);\n case \"rpm\":\n return compareRpm(a, b);\n case \"intdot\":\n return compareIntdot(a, b);\n case \"generic\":\n return compareGeneric(a, b);\n default:\n return undefined;\n }\n}\n\nconst sign = (n: number): number => (n < 0 ? -1 : n > 0 ? 1 : 0);\nconst compareText = (a: string, b: string): number => (a < b ? -1 : a > b ? 1 : 0);\nconst compareDigits = (a: string, b: string): number => {\n const x = a.replace(/^0+(?=\\d)/, \"\");\n const y = b.replace(/^0+(?=\\d)/, \"\");\n return x.length !== y.length ? sign(x.length - y.length) : compareText(x, y);\n};\n\n// SemVer 2.0.0. The build metadata does not change the order.\nconst SEMVER = /^v?(0|[1-9]\\d*)\\.(0|[1-9]\\d*)\\.(0|[1-9]\\d*)(?:-((?:0|[1-9]\\d*|\\d*[A-Za-z-][0-9A-Za-z-]*)(?:\\.(?:0|[1-9]\\d*|\\d*[A-Za-z-][0-9A-Za-z-]*))*))?(?:\\+[0-9A-Za-z-]+(?:\\.[0-9A-Za-z-]+)*)?$/;\n\n/** The parts of a SemVer version that decide its order. */\ninterface Semver {\n readonly core: readonly [string, string, string];\n readonly pre: readonly string[];\n}\n\nfunction parseSemver(text: string): Semver | undefined {\n const match = SEMVER.exec(text.trim().replace(/^=/, \"\"));\n if (match === null) return undefined;\n return { core: [match[1]!, match[2]!, match[3]!], pre: match[4] === undefined ? [] : match[4].split(\".\") };\n}\n\nfunction compareSemverParts(x: Semver, y: Semver): number {\n for (let i = 0; i < 3; i++) {\n const c = compareDigits(x.core[i]!, y.core[i]!);\n if (c !== 0) return c;\n }\n // A version with a pre-release comes before the same version with no pre-release.\n if (x.pre.length === 0 || y.pre.length === 0) return sign(y.pre.length - x.pre.length);\n for (let i = 0; i < Math.min(x.pre.length, y.pre.length); i++) {\n const p = x.pre[i]!;\n const q = y.pre[i]!;\n const pn = /^\\d+$/.test(p);\n const qn = /^\\d+$/.test(q);\n const c = pn && qn ? compareDigits(p, q) : pn ? -1 : qn ? 1 : compareText(p, q);\n if (c !== 0) return c;\n }\n return sign(x.pre.length - y.pre.length);\n}\n\n/** This function compares two SemVer 2.0.0 versions. It accepts a leading `v` or `=`, as npm does. */\nexport function compareSemver(a: string, b: string): number | undefined {\n const x = parseSemver(a);\n const y = parseSemver(b);\n return x === undefined || y === undefined ? undefined : compareSemverParts(x, y);\n}\n\n/**\n * This function compares two versions of Go modules. A Go version starts with `v` and follows SemVer. A pseudo-version is\n * a pre-release, so it has its place in the order of SemVer. The suffix `+incompatible` is build metadata.\n */\nexport function compareGo(a: string, b: string): number | undefined {\n if (!a.startsWith(\"v\") || !b.startsWith(\"v\")) return undefined;\n return compareSemver(a, b);\n}\n\n// PEP 440: the pattern of the version specification of the Python packaging guide.\nconst PEP440 =\n /^\\s*v?(?:(?:(\\d+)!)?(\\d+(?:\\.\\d+)*)(?:[-_.]?(a|b|c|rc|alpha|beta|pre|preview)[-_.]?(\\d+)?)?(?:-(\\d+)|[-_.]?(post|rev|r)[-_.]?(\\d+)?)?(?:[-_.]?(dev)[-_.]?(\\d+)?)?)(?:\\+([a-z0-9]+(?:[-_.][a-z0-9]+)*))?\\s*$/i;\n\n/** The parts of a PEP 440 version that decide its order. */\ninterface Pep440 {\n readonly epoch: number;\n readonly release: readonly number[];\n /** The pre-release as a rank (a 0, b 1, rc 2) and a number. */\n readonly pre?: readonly [number, number];\n readonly post?: number;\n readonly dev?: number;\n readonly local: readonly string[];\n}\n\nconst PRE_RANK: Readonly<Record<string, number>> = { a: 0, alpha: 0, b: 1, beta: 1, c: 2, rc: 2, pre: 2, preview: 2 };\n\nfunction parsePep440(text: string): Pep440 | undefined {\n const m = PEP440.exec(text);\n if (m === null) return undefined;\n const release = m[2]!.split(\".\").map(Number);\n while (release.length > 1 && release[release.length - 1] === 0) release.pop();\n const post = m[5] !== undefined ? Number(m[5]) : m[6] !== undefined ? Number(m[7] ?? 0) : undefined;\n return {\n epoch: Number(m[1] ?? 0),\n release,\n ...(m[3] === undefined ? {} : { pre: [PRE_RANK[m[3].toLowerCase()]!, Number(m[4] ?? 0)] as const }),\n ...(post === undefined ? {} : { post }),\n ...(m[8] === undefined ? {} : { dev: Number(m[9] ?? 0) }),\n local: m[10] === undefined ? [] : m[10].toLowerCase().split(/[-_.]/),\n };\n}\n\nfunction compareNumbers(a: readonly number[], b: readonly number[]): number {\n for (let i = 0; i < Math.max(a.length, b.length); i++) {\n const c = sign((a[i] ?? 0) - (b[i] ?? 0));\n if (c !== 0) return c;\n }\n return 0;\n}\n\n/** This function compares two PEP 440 versions, with the order of the Python packaging specification. */\nexport function comparePep440(a: string, b: string): number | undefined {\n const x = parsePep440(a);\n const y = parsePep440(b);\n if (x === undefined || y === undefined) return undefined;\n const epoch = sign(x.epoch - y.epoch);\n if (epoch !== 0) return epoch;\n const release = compareNumbers(x.release, y.release);\n if (release !== 0) return release;\n // A dev release with no pre-release and no post-release comes before each pre-release.\n const preKey = (v: Pep440): readonly number[] => (v.pre !== undefined ? [0, ...v.pre] : v.post === undefined && v.dev !== undefined ? [-1] : [1]);\n const pre = compareNumbers(preKey(x), preKey(y));\n if (pre !== 0) return pre;\n const postKey = (v: Pep440): readonly number[] => (v.post === undefined ? [-1] : [0, v.post]);\n const post = compareNumbers(postKey(x), postKey(y));\n if (post !== 0) return post;\n const devKey = (v: Pep440): readonly number[] => (v.dev === undefined ? [1] : [0, v.dev]);\n const dev = compareNumbers(devKey(x), devKey(y));\n if (dev !== 0) return dev;\n return compareLocal(x.local, y.local);\n}\n\n// A local version comes after the same version with no local part. A number segment comes after a text segment.\nfunction compareLocal(a: readonly string[], b: readonly string[]): number {\n for (let i = 0; i < Math.min(a.length, b.length); i++) {\n const p = a[i]!;\n const q = b[i]!;\n const pn = /^\\d+$/.test(p);\n const qn = /^\\d+$/.test(q);\n const c = pn && qn ? compareDigits(p, q) : pn ? 1 : qn ? -1 : compareText(p, q);\n if (c !== 0) return c;\n }\n return sign(a.length - b.length);\n}\n\n// The order of a character of a Debian version: `~` comes before the end, the end before a letter, a letter before\n// each other character. A digit has the rank of the end, as in dpkg.\nfunction debianRank(text: string, i: number): number {\n if (i >= text.length) return 0;\n const c = text[i]!;\n if (/d/.test(c)) return 0;\n if (c === \"~\") return -1;\n if (/[A-Za-z]/.test(c)) return c.charCodeAt(0);\n return c.charCodeAt(0) + 256;\n}\n\n// The comparison of dpkg: parts with no digit and parts of digits, one after the other.\nfunction compareDebianPart(a: string, b: string): number {\n let i = 0;\n let j = 0;\n while (i < a.length || j < b.length) {\n while ((i < a.length && !/\\d/.test(a[i]!)) || (j < b.length && !/\\d/.test(b[j]!))) {\n const c = debianRank(a, i) - debianRank(b, j);\n if (c !== 0) return sign(c);\n i++;\n j++;\n }\n let p = \"\";\n let q = \"\";\n while (i < a.length && /\\d/.test(a[i]!)) p += a[i++];\n while (j < b.length && /\\d/.test(b[j]!)) q += b[j++];\n const c = compareDigits(p || \"0\", q || \"0\");\n if (c !== 0) return c;\n }\n return 0;\n}\n\nconst DEBIAN = /^(?:(\\d+):)?([0-9][A-Za-z0-9.+~:-]*?)(?:-([A-Za-z0-9.+~]+))?$/;\n\n/** This function compares two Debian versions (`[epoch:]upstream[-revision]`) with the order of dpkg. */\nexport function compareDebian(a: string, b: string): number | undefined {\n const x = DEBIAN.exec(a.trim());\n const y = DEBIAN.exec(b.trim());\n if (x === null || y === null) return undefined;\n const epoch = compareDigits(x[1] ?? \"0\", y[1] ?? \"0\");\n if (epoch !== 0) return epoch;\n const upstream = compareDebianPart(x[2]!, y[2]!);\n if (upstream !== 0) return upstream;\n return compareDebianPart(x[3] ?? \"0\", y[3] ?? \"0\");\n}\n\n// The comparison of rpmvercmp: segments of letters or digits. `~` comes before each other thing, also the end. `^` comes\n// after the end, but before each other segment.\nfunction rpmvercmp(a: string, b: string): number {\n if (a === b) return 0;\n let i = 0;\n let j = 0;\n for (;;) {\n while (i < a.length && !/[A-Za-z0-9~^]/.test(a[i]!)) i++;\n while (j < b.length && !/[A-Za-z0-9~^]/.test(b[j]!)) j++;\n const ca = a[i];\n const cb = b[j];\n if (ca === \"~\" || cb === \"~\") {\n if (ca !== \"~\") return 1;\n if (cb !== \"~\") return -1;\n i++;\n j++;\n continue;\n }\n if (ca === \"^\" || cb === \"^\") {\n if (ca === undefined) return -1;\n if (cb === undefined) return 1;\n if (ca !== \"^\") return 1;\n if (cb !== \"^\") return -1;\n i++;\n j++;\n continue;\n }\n if (ca === undefined || cb === undefined) break;\n const digits = /\\d/.test(ca);\n const same = digits ? /\\d/ : /[A-Za-z]/;\n let p = \"\";\n let q = \"\";\n while (i < a.length && same.test(a[i]!)) p += a[i++];\n while (j < b.length && same.test(b[j]!)) q += b[j++];\n // A segment of digits comes after a segment of letters.\n if (q === \"\") return digits ? 1 : -1;\n const c = digits ? compareDigits(p, q) : compareText(p, q);\n if (c !== 0) return c;\n }\n if (i >= a.length && j >= b.length) return 0;\n return i >= a.length ? -1 : 1;\n}\n\nconst RPM = /^(?:(\\d+):)?([^-]+)(?:-([^-]+))?$/;\n\n/** This function compares two RPM versions (`[epoch:]version[-release]`) with the order of `rpmvercmp`. */\nexport function compareRpm(a: string, b: string): number | undefined {\n const x = RPM.exec(a.trim());\n const y = RPM.exec(b.trim());\n if (x === null || y === null) return undefined;\n const epoch = compareDigits(x[1] ?? \"0\", y[1] ?? \"0\");\n if (epoch !== 0) return epoch;\n const version = rpmvercmp(x[2]!, y[2]!);\n if (version !== 0) return version;\n // A version with no release comes before each release of that version. Thus a check of a fix does not take it as fixed.\n return rpmvercmp(x[3] ?? \"\", y[3] ?? \"\");\n}\n\nconst INTDOT = /^\\d+(?:\\.\\d+)*$/;\n\n/**\n * This function compares two versions of the `vers` scheme `intdot`: integers with a `.` between them. The integers\n * compare from left to right. A missing integer is 0, so `1.0` equals `1.0.0`.\n */\nexport function compareIntdot(a: string, b: string): number | undefined {\n const x = a.trim();\n const y = b.trim();\n if (!INTDOT.test(x) || !INTDOT.test(y)) return undefined;\n const p = x.split(\".\");\n const q = y.split(\".\");\n for (let i = 0; i < Math.max(p.length, q.length); i++) {\n const c = compareDigits(p[i] ?? \"0\", q[i] ?? \"0\");\n if (c !== 0) return c;\n }\n return 0;\n}\n\n/** This function gives the segments of a version of a vendor: the runs of digits and the runs of letters. */\nfunction genericSegments(text: string): readonly string[] | undefined {\n // One `v` before a digit is a prefix, not a segment: `V6.80` is the version `6.80`.\n const body = text.trim().replace(/^[vV](?=\\d)/, \"\");\n if (!/^\\d/.test(body)) return undefined;\n return body.match(/\\d+|[A-Za-z]+/g) ?? undefined;\n}\n\nconst isDigits = (segment: string): boolean => /^\\d/.test(segment);\n\n/**\n * This function compares two versions of the `vers` scheme `generic`, the versions of vendors, for example `V6.80` or\n * `2.9.1.0_FR`. A version starts with a digit, after one optional `v`. The segments are the runs of digits and of letters.\n * The other characters separate the segments.\n *\n * The segments compare from left to right, and the first difference decides. Two runs of digits compare as integers.\n * Two runs of letters are equal when they are the same with no regard to case. Other pairs have no known order. These\n * pairs give `undefined`: two different runs of letters, or a run of digits and a run of letters.\n *\n * When one version ends first, a rest of zeros is equal to the end. A rest with a number above 0 before its first letters\n * comes after the end. A rest with letters before such a number, for example ` SP1` or `-beta`, has no known order.\n */\nexport function compareGeneric(a: string, b: string): number | undefined {\n const p = genericSegments(a);\n const q = genericSegments(b);\n if (p === undefined || q === undefined) return undefined;\n for (let i = 0; i < Math.min(p.length, q.length); i++) {\n const x = p[i]!;\n const y = q[i]!;\n if (isDigits(x) && isDigits(y)) {\n const c = compareDigits(x, y);\n if (c !== 0) return c;\n } else if (isDigits(x) || isDigits(y) || x.toLowerCase() !== y.toLowerCase()) {\n return undefined;\n }\n }\n const rest = p.length > q.length ? p.slice(q.length) : q.slice(p.length);\n const longer = p.length > q.length ? 1 : -1;\n for (const segment of rest) {\n if (!isDigits(segment)) return undefined;\n if (/[1-9]/.test(segment)) return longer;\n }\n return 0;\n}\n","/**\n * The map from the ecosystems of OSV (`https://ossf.github.io/osv-schema/`) to purl types, and the purl of a package\n * of an OSV record.\n */\n\nimport { formatPurl, packagePurlOf } from \"./purl.ts\";\nimport type { Vers, VersConstraint } from \"./vers.ts\";\nimport { compareVersions, versionScheme } from \"./version.ts\";\n\n/**\n * The purl type of each OSV ecosystem that has one. An ecosystem that is not in the table has no purl.\n * For a Linux distribution, the table key is the part of the ecosystem before the first `:`.\n */\nexport const OSV_PURL_TYPES: Readonly<Record<string, string>> = {\n npm: \"npm\",\n PyPI: \"pypi\",\n \"crates.io\": \"cargo\",\n RubyGems: \"gem\",\n NuGet: \"nuget\",\n Go: \"golang\",\n Maven: \"maven\",\n Packagist: \"composer\",\n Pub: \"pub\",\n Hex: \"hex\",\n Hackage: \"hackage\",\n CRAN: \"cran\",\n \"GitHub Actions\": \"github\",\n Debian: \"deb\",\n Ubuntu: \"deb\",\n Alpine: \"apk\",\n};\n\n/** The purl namespace of each OSV ecosystem of a Linux distribution: the name of the distribution. */\nconst DISTRIBUTION: Readonly<Record<string, string>> = { Debian: \"debian\", Ubuntu: \"ubuntu\", Alpine: \"alpine\" };\n\n/** This function gives the namespace and the name of an OSV package name, as the purl type of its ecosystem splits them. */\nfunction split(type: string, name: string): { readonly namespace?: string; readonly name: string } | undefined {\n switch (type) {\n case \"npm\": {\n const slash = name.indexOf(\"/\");\n return name.startsWith(\"@\") && slash > 1 ? { namespace: name.slice(0, slash), name: name.slice(slash + 1) } : { name };\n }\n case \"golang\":\n case \"composer\":\n case \"github\": {\n const slash = name.lastIndexOf(\"/\");\n return slash > 0 ? { namespace: name.slice(0, slash), name: name.slice(slash + 1) } : { name };\n }\n case \"maven\": {\n const colon = name.indexOf(\":\");\n return colon > 0 ? { namespace: name.slice(0, colon), name: name.slice(colon + 1) } : undefined;\n }\n default:\n return { name };\n }\n}\n\n/**\n * This function gives the canonical purl of an OSV package, with no version. For an ecosystem with no purl type, or\n * a bad name, it gives `undefined`.\n */\nexport function osvPurl(ecosystem: string, name: string): string | undefined {\n const base = ecosystem.split(\":\")[0]!;\n const type = Object.hasOwn(OSV_PURL_TYPES, base) ? OSV_PURL_TYPES[base] : undefined;\n if (type === undefined || name === \"\") return undefined;\n const names = split(type, name);\n if (names === undefined) return undefined;\n const distribution = Object.hasOwn(DISTRIBUTION, base) ? DISTRIBUTION[base] : undefined;\n const namespace = distribution ?? names.namespace;\n return formatPurl({ type, ...(namespace === undefined ? {} : { namespace }), name: names.name });\n}\n\n/**\n * This function gives the purl of a package of an OSV record, with no version, qualifiers or subpath. A valid purl\n * of the record wins. Else the function builds the purl from the ecosystem and the name.\n */\nexport function osvPackagePurl(pkg: { readonly ecosystem: string; readonly name: string; readonly purl?: string }): string | undefined {\n const own = pkg.purl === undefined ? undefined : packagePurlOf(pkg.purl);\n return own ?? osvPurl(pkg.ecosystem, pkg.name);\n}\n\n/** One event of an OSV range, as the OSV schema writes it: each event has one of the four fields. */\nexport interface OsvEvent {\n readonly introduced?: string;\n readonly fixed?: string;\n readonly last_affected?: string;\n readonly limit?: string;\n}\n\n/** A range of an OSV record: its type (`SEMVER`, `ECOSYSTEM` or `GIT`) and its events. */\nexport interface OsvRange {\n readonly type: string;\n readonly events: readonly OsvEvent[];\n}\n\n/**\n * This function gives the `vers` range of an OSV range. A range of the type `SEMVER` has the scheme `semver`. A range\n * of the type `ECOSYSTEM` has the purl type of its ecosystem as its scheme. A `GIT` range, an ecosystem with no purl type\n * or an event with no version gives `undefined`.\n *\n * The events come in the order of their versions, as the OSV schema tells, when the scheme has a known order. Else they\n * keep the order of the record. The event `introduced 0` is the start of each version, so it gives no constraint.\n */\nexport function osvRangeVers(ecosystem: string, range: OsvRange): Vers | undefined {\n const base = ecosystem.split(\":\")[0]!;\n const type = Object.hasOwn(OSV_PURL_TYPES, base) ? OSV_PURL_TYPES[base] : undefined;\n const scheme = range.type === \"SEMVER\" ? \"semver\" : range.type === \"ECOSYSTEM\" ? type : undefined;\n if (scheme === undefined) return undefined;\n const constraints: VersConstraint[] = [];\n let all = false;\n for (const event of range.events) {\n const constraint = eventConstraint(event);\n if (constraint === undefined) return undefined;\n if (constraint === \"start\") all = true;\n else if (constraint !== \"none\") constraints.push(constraint);\n }\n if (constraints.length === 0) return all ? { scheme, all: true, constraints: [] } : undefined;\n return { scheme, all: false, constraints: sortEvents(scheme, constraints) };\n}\n\n// The constraint of one event: \"start\" for `introduced 0`, \"none\" for `limit *` (no limit).\nfunction eventConstraint(event: OsvEvent): VersConstraint | \"start\" | \"none\" | undefined {\n if (event.introduced !== undefined) return event.introduced === \"0\" ? \"start\" : { comparator: \">=\", version: event.introduced };\n if (event.fixed !== undefined) return { comparator: \"<\", version: event.fixed };\n if (event.last_affected !== undefined) return { comparator: \"<=\", version: event.last_affected };\n if (event.limit !== undefined) return event.limit === \"*\" ? \"none\" : { comparator: \"<\", version: event.limit };\n return undefined;\n}\n\n// The constraints in the order of their versions, or in their own order when the scheme has no known order.\nfunction sortEvents(scheme: string, constraints: readonly VersConstraint[]): VersConstraint[] {\n if (versionScheme(scheme) === undefined) return [...constraints];\n let unknown = false;\n const sorted = [...constraints].sort((a, b) => {\n const c = compareVersions(scheme, a.version, b.version);\n if (c === undefined) unknown = true;\n return c ?? 0;\n });\n return unknown ? [...constraints] : sorted;\n}\n","/**\n * Version ranges in the `vers` format of the purl specification, for example `vers:npm/>=1.0.0|<1.2.3`. The functions\n * parse a range, format it and tell if a version is in it, with the version order of the scheme.\n */\nimport { compareVersions } from \"./version.ts\";\n\n/** The comparators of a `vers` constraint. */\nexport type VersComparator = \"=\" | \"!=\" | \"<\" | \"<=\" | \">\" | \">=\";\n\n/** One constraint of a range: a comparator and a version. */\nexport interface VersConstraint {\n readonly comparator: VersComparator;\n readonly version: string;\n}\n\n/** A version range. A range with the constraint `*` holds each version, and its list of constraints is empty. */\nexport interface Vers {\n /** The version scheme, for example `npm`, `pypi` or `deb`. */\n readonly scheme: string;\n /** True: the range is `*`, so it holds each version. */\n readonly all: boolean;\n readonly constraints: readonly VersConstraint[];\n}\n\n// The longer comparators come first, so `<=` is not read as `<` and a version that starts with `=`.\nconst COMPARATORS: readonly VersComparator[] = [\"!=\", \"<=\", \">=\", \"<\", \">\", \"=\"];\n\n/** This function reads one constraint, for example `>=1.0.0`. A constraint with no comparator has the comparator `=`. */\nfunction parseConstraint(text: string): VersConstraint | undefined {\n const trimmed = text.trim();\n const comparator = COMPARATORS.find((c) => trimmed.startsWith(c)) ?? \"=\";\n const raw = trimmed.slice(trimmed.startsWith(comparator) ? comparator.length : 0).trim();\n if (raw === \"\") return undefined;\n let version: string;\n try {\n version = decodeURIComponent(raw);\n } catch {\n return undefined;\n }\n return { comparator, version };\n}\n\n/** This function reads a `vers` text. A text that is not a range gives `undefined`. */\nexport function parseVers(text: string): Vers | undefined {\n const match = /^vers:([A-Za-z0-9.+-]+)\\/(.+)$/.exec(text.replace(/\\s+/g, \"\"));\n if (match === null) return undefined;\n const scheme = match[1]!.toLowerCase();\n const body = match[2]!;\n if (body === \"*\") return { scheme, all: true, constraints: [] };\n const constraints: VersConstraint[] = [];\n for (const part of body.split(\"|\")) {\n const constraint = parseConstraint(part);\n if (constraint === undefined) return undefined;\n constraints.push(constraint);\n }\n return { scheme, all: false, constraints };\n}\n\n// The characters that a version keeps in a `vers` text: the others are percent-encoded.\nconst encodeVersion = (version: string): string => version.replace(/[^A-Za-z0-9.+~_:-]/g, (c) => encodeURIComponent(c));\n\n/**\n * This function gives the `vers` text of a range. The constraints come in the order of the versions, when the scheme\n * has a known order. The comparator `=` has no sign, as the specification tells.\n */\nexport function formatVers(vers: Vers): string {\n if (vers.all) return `vers:${vers.scheme}/*`;\n const sorted = sortConstraints(vers.scheme, vers.constraints) ?? vers.constraints;\n const body = sorted.map((c) => `${c.comparator === \"=\" ? \"\" : c.comparator}${encodeVersion(c.version)}`).join(\"|\");\n return `vers:${vers.scheme}/${body}`;\n}\n\n// The constraints in the order of their versions, or `undefined` when a version is not a version of the scheme.\nfunction sortConstraints(scheme: string, constraints: readonly VersConstraint[]): VersConstraint[] | undefined {\n let unknown = false;\n const sorted = [...constraints].sort((a, b) => {\n const c = compareVersions(scheme, a.version, b.version);\n if (c === undefined) unknown = true;\n return c ?? 0;\n });\n return unknown ? undefined : sorted;\n}\n\n/**\n * This function tells if a version is in a range, with the algorithm of the `vers` specification. The result is\n * `undefined` when the scheme has no known order, or when a version is not a version of the scheme. Thus a caller\n * does not take an unknown result as a match or as no match.\n */\nexport function versContains(vers: Vers, version: string): boolean | undefined {\n if (vers.all) return true;\n const compare = (a: string, b: string): number | undefined => compareVersions(vers.scheme, a, b);\n for (const constraint of vers.constraints) {\n const c = compare(version, constraint.version);\n if (c === undefined) return undefined;\n if (c === 0 && [\"=\", \"<=\", \">=\"].includes(constraint.comparator)) return true;\n if (c === 0 && constraint.comparator === \"!=\") return false;\n }\n const ranged = sortConstraints(\n vers.scheme,\n vers.constraints.filter((c) => c.comparator !== \"=\" && c.comparator !== \"!=\"),\n );\n if (ranged === undefined) return undefined;\n if (ranged.length === 0) {\n // Only `!=` constraints that the version does not equal: the version is in the range.\n return vers.constraints.some((c) => c.comparator === \"!=\");\n }\n const below = (c: VersConstraint): boolean => c.comparator === \"<\" || c.comparator === \"<=\";\n const above = (c: VersConstraint): boolean => c.comparator === \">\" || c.comparator === \">=\";\n const first = ranged[0]!;\n const last = ranged[ranged.length - 1]!;\n if (below(first) && compare(version, first.version)! < 0) return true;\n if (above(last) && compare(version, last.version)! > 0) return true;\n for (let i = 0; i + 1 < ranged.length; i++) {\n const low = ranged[i]!;\n const high = ranged[i + 1]!;\n if (above(low) && below(high) && compare(version, low.version)! > 0 && compare(version, high.version)! < 0) return true;\n }\n return false;\n}\n\n/**\n * This function gives the end of the part of a range that holds a version, when that end is a constraint `<`. For the\n * range of an advisory, it is the first fixed version above the version. The result is `undefined` for a version out\n * of the range, or for an unknown order. It is also `undefined` for a part with no such end: `<=`, an open end or `=`.\n */\nexport function versEnd(vers: Vers, version: string): string | undefined {\n if (vers.all || versContains(vers, version) !== true) return undefined;\n if (vers.constraints.some((c) => c.comparator === \"=\" && compareVersions(vers.scheme, version, c.version) === 0)) return undefined;\n const ranged = sortConstraints(\n vers.scheme,\n vers.constraints.filter((c) => c.comparator !== \"=\" && c.comparator !== \"!=\"),\n );\n const next = ranged?.find((c) => compareVersions(vers.scheme, version, c.version)! < 0);\n return next?.comparator === \"<\" ? next.version : undefined;\n}\n"],"mappings":";;AAwBA,MAAM,OAAO;;AAGb,MAAM,MAAM;;;;;AAMZ,MAAM,2CAAgD,IAAI,IAAI;CAAC;CAAQ;CAAO;CAAa;CAAY;CAAO;CAAU;CAAU;AAAK,CAAC;;AAGxI,MAAM,6BAAkC,IAAI,IAAI;CAAC;CAAO;CAAO;AAAM,CAAC;;AAGtE,SAAS,OAAO,MAAsB;CACpC,OAAO,mBAAm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,OAAO,IAAK,GAAG,OAAO;CAC/D,KAAK,IAAI,IAAI,GAAG,IAAI,IAAI,OAAO,QAAQ,KAAK;EAC1C,MAAM,MAAM,OAAO;EACnB,MAAM,OAAO,OAAO,IAAI;EACxB,IAAI,MAAM,GAAG,KAAK,MAAM,IAAI,KAAK,QAAQ,SAAS,IAAI,OAAO,IAAK,KAAK,QAAQ,SAAS,KAAK,OAAO,IAAK,GAAG,OAAO;CACrH;CACA,OAAO;AACT;;;;;;AAOA,SAAgB,QAAQ,MAAY,SAAqC;CACvE,IAAI,KAAK,OAAO,aAAa,MAAM,OAAO,MAAM,MAAM,OAAO,KAAA;CAC7D,IAAI,KAAK,YAAY,MAAM,MAAM,EAAE,eAAe,OAAO,gBAAgB,KAAK,QAAQ,SAAS,EAAE,OAAO,MAAM,CAAC,GAAG,OAAO,KAAA;CAKzH,MAAM,OAJS,gBACb,KAAK,QACL,KAAK,YAAY,QAAQ,MAAM,EAAE,eAAe,OAAO,EAAE,eAAe,IAAI,CAE5D,CAAC,EAAE,MAAM,MAAM,gBAAgB,KAAK,QAAQ,SAAS,EAAE,OAAO,IAAK,CAAC;CACtF,OAAO,MAAM,eAAe,MAAM,KAAK,UAAU,KAAA;AACnD"}
|
|
1
|
+
{"version":3,"file":"index.js","names":[],"sources":["../src/cpe.ts","../src/model.ts","../src/purl.ts","../src/version.ts","../src/osv.ts","../src/vers.ts"],"sourcesContent":["/**\n * CPE names of the NIST specification (NISTIR 7695): the formatted string of CPE 2.3, for example\n * `cpe:2.3:a:apache:http_server:2.4.62:*:*:*:*:*:*:*`, and the URI of CPE 2.2, for example `cpe:/a:apache:http_server:2.4.62`.\n * The functions read a name, write it as a formatted string and give the product of a name with no version. The match\n * of a CSAF advisory to a device uses them: a vendor gives a CPE when a product has no purl.\n */\n\n/** The part of a CPE name: `a` an application, `o` an operating system, `h` a hardware device, `*` any part. */\nexport type CpePart = \"a\" | \"o\" | \"h\" | \"*\";\n\n/**\n * A CPE name. Each attribute is a value of the formatted string, in lower case: `*` is any value, `-` is no value. A\n * special character has a backslash before it, for example `\\!`. An unquoted `*` or `?` in a value is a wildcard.\n */\nexport interface Cpe {\n readonly part: CpePart;\n readonly vendor: string;\n readonly product: string;\n readonly version: string;\n readonly update: string;\n readonly edition: string;\n readonly language: string;\n readonly swEdition: string;\n readonly targetSw: string;\n readonly targetHw: string;\n readonly other: string;\n}\n\n/** The attributes of a name, in the order of the formatted string. */\nconst ATTRIBUTES = [\"part\", \"vendor\", \"product\", \"version\", \"update\", \"edition\", \"language\", \"swEdition\", \"targetSw\", \"targetHw\", \"other\"] as const;\n\n/** The characters that a value keeps with no backslash. */\nconst PLAIN = /^[a-z0-9._-]$/;\n\n/** This function gives the formatted-string form of one character of a value: a special character gets a backslash. */\nconst quoted = (char: string): string => (PLAIN.test(char) ? char : `\\\\${char}`);\n\n/**\n * This function gives the canonical form of a value of a formatted string, or `undefined` for a value that is not valid.\n * The form is lower case. A backslash stays only before a special character. Each other special character gets one.\n */\nfunction canonicalValue(value: string): string | undefined {\n const text = value.toLowerCase();\n if (text === \"\") return undefined;\n if (text === \"*\" || text === \"-\") return text;\n let out = \"\";\n for (let index = 0; index < text.length; index += 1) {\n const char = text[index]!;\n if (char === \"\\\\\") {\n const next = text[index + 1];\n if (next === undefined) return undefined;\n out += quoted(next);\n index += 1;\n } else if (char === \"*\" || char === \"?\") {\n // A wildcard is valid only at the start or the end of a value.\n if (!/^[*?]+$/.test(text.slice(0, index + 1)) && !/^[*?]+$/.test(text.slice(index))) return undefined;\n out += char;\n } else if (char.charCodeAt(0) < 0x21 || char.charCodeAt(0) > 0x7e) {\n return undefined;\n } else {\n out += quoted(char);\n }\n }\n // A value of one quoted hyphen is a hyphen, not \"no value\".\n return out === \"-\" ? \"\\\\-\" : out;\n}\n\n/** This function splits a formatted string at each colon that has no backslash before it. */\nfunction splitFormatted(text: string): readonly string[] {\n const values: string[] = [];\n let current = \"\";\n for (let index = 0; index < text.length; index += 1) {\n const char = text[index]!;\n if (char === \"\\\\\" && index + 1 < text.length) {\n current += char + text[index + 1]!;\n index += 1;\n } else if (char === \":\") {\n values.push(current);\n current = \"\";\n } else {\n current += char;\n }\n }\n values.push(current);\n return values;\n}\n\n/** This function gives the formatted-string value of one component of a CPE 2.2 URI, or `undefined`. */\nfunction uriValue(component: string): string | undefined {\n if (component === \"\") return \"*\";\n if (component === \"-\") return \"-\";\n let out = \"\";\n for (let index = 0; index < component.length; index += 1) {\n const char = component[index]!;\n if (char !== \"%\") {\n if (!/^[A-Za-z0-9._~-]$/.test(char)) return undefined;\n out += quoted(char.toLowerCase());\n continue;\n }\n const code = component.slice(index + 1, index + 3);\n if (!/^[0-9A-Fa-f]{2}$/.test(code)) return undefined;\n index += 2;\n const value = Number.parseInt(code, 16);\n // The codes %01 and %02 are the wildcards `?` and `*` of a URI.\n if (value === 1) out += \"?\";\n else if (value === 2) out += \"*\";\n else if (value < 0x21 || value > 0x7e) return undefined;\n else out += quoted(String.fromCharCode(value).toLowerCase());\n }\n return canonicalValue(out);\n}\n\n/** This function gives a name from its values in the order of the formatted string, or `undefined`. */\nfunction cpeOf(values: readonly string[]): Cpe | undefined {\n const canonical = values.map(canonicalValue);\n if (canonical.some((value) => value === undefined)) return undefined;\n const part = canonical[0];\n if (part !== \"a\" && part !== \"o\" && part !== \"h\" && part !== \"*\") return undefined;\n return Object.fromEntries(ATTRIBUTES.map((name, index) => [name, canonical[index] ?? \"*\"])) as unknown as Cpe;\n}\n\n/** This function reads a CPE 2.2 URI. The packed edition (`~edition~sw_edition~target_sw~target_hw~other`) gives five attributes. */\nfunction parseUri(text: string): Cpe | undefined {\n const components = text.slice(\"cpe:/\".length).split(\":\");\n if (components.length > 7) return undefined;\n const [part = \"\", vendor = \"\", product = \"\", version = \"\", update = \"\", edition = \"\", language = \"\"] = components;\n const packed = edition.startsWith(\"~\") ? edition.slice(1).split(\"~\") : undefined;\n if (packed !== undefined && packed.length !== 5) return undefined;\n // The order of the values is the order of the formatted string: the packed attributes come after the language.\n const values = [part, vendor, product, version, update, packed?.[0] ?? edition, language, ...(packed?.slice(1) ?? [])].map(uriValue);\n if (values.some((value) => value === undefined)) return undefined;\n return cpeOf(values as string[]);\n}\n\n/**\n * This function reads a CPE name: a formatted string of CPE 2.3 or a URI of CPE 2.2. A formatted string with fewer than\n * eleven attributes gets `*` for each missing attribute. A text that is not a CPE name gives `undefined`.\n */\nexport function parseCpe(text: string): Cpe | undefined {\n const trimmed = text.trim();\n const lower = trimmed.toLowerCase();\n if (lower.startsWith(\"cpe:/\")) return parseUri(trimmed);\n if (!lower.startsWith(\"cpe:2.3:\")) return undefined;\n const values = splitFormatted(trimmed.slice(\"cpe:2.3:\".length));\n if (values.length < 3 || values.length > ATTRIBUTES.length) return undefined;\n return cpeOf(values);\n}\n\n/** This function writes a name as a formatted string of CPE 2.3, with each of its eleven attributes. */\nexport function formatCpe(cpe: Cpe): string {\n return `cpe:2.3:${ATTRIBUTES.map((name) => cpe[name]).join(\":\")}`;\n}\n\n/**\n * This function gives the product of a CPE name: the formatted string with the part, the vendor and the product. Each\n * other attribute is `*`. A name with no vendor or no product, or with a wildcard in them, gives `undefined`.\n */\nexport function cpeProductOf(text: string): string | undefined {\n const cpe = parseCpe(text);\n if (cpe === undefined) return undefined;\n const specific = (value: string): boolean => value !== \"*\" && value !== \"-\" && !/(^|[^\\\\])[*?]/.test(value);\n if (!specific(cpe.vendor) || !specific(cpe.product)) return undefined;\n return formatCpe({ part: cpe.part, vendor: cpe.vendor, product: cpe.product, version: \"*\", update: \"*\", edition: \"*\", language: \"*\", swEdition: \"*\", targetSw: \"*\", targetHw: \"*\", other: \"*\" });\n}\n\n/**\n * This function gives the version of a CPE name with no backslashes, for example `2.4.62`. A name with any version, no\n * version or a wildcard in its version gives `undefined`.\n */\nexport function cpeVersionOf(cpe: Cpe): string | undefined {\n if (cpe.version === \"*\" || cpe.version === \"-\" || /(^|[^\\\\])[*?]/.test(cpe.version)) return undefined;\n return cpe.version.replace(/\\\\(.)/g, \"$1\");\n}\n","/**\n * The model numbers and the SKUs of CSAF 2.0. A CSAF advisory names a hardware product by a full or partial model number.\n * In such a pattern, `*` stands for zero or more characters and `?` stands for one character. A backslash before `*`,\n * `?` or a backslash makes that character literal. The comparison is exact: the case of each character counts.\n */\n\n/** One token of a pattern: any run of characters, one character, or one literal character. */\ntype Token = { readonly kind: \"any\" } | { readonly kind: \"one\" } | { readonly kind: \"char\"; readonly char: string };\n\n/** This function gives the tokens of a pattern. A backslash at the end is a literal backslash. */\nfunction tokensOf(pattern: string): readonly Token[] {\n const chars = Array.from(pattern);\n const tokens: Token[] = [];\n for (let index = 0; index < chars.length; index++) {\n const char = chars[index]!;\n const next = chars[index + 1];\n if (char === \"\\\\\" && next !== undefined && (next === \"*\" || next === \"?\" || next === \"\\\\\")) {\n tokens.push({ kind: \"char\", char: next });\n index++;\n } else if (char === \"*\") {\n if (tokens.at(-1)?.kind !== \"any\") tokens.push({ kind: \"any\" });\n } else if (char === \"?\") tokens.push({ kind: \"one\" });\n else tokens.push({ kind: \"char\", char });\n }\n return tokens;\n}\n\n/**\n * This function tells if a model number or a SKU matches a pattern of a CSAF advisory. An empty pattern matches nothing.\n * The match keeps the last `*` and its place, so its time is at most the product of the two lengths.\n */\nexport function modelNumberMatches(pattern: string, model: string): boolean {\n if (pattern === \"\") return false;\n const tokens = tokensOf(pattern);\n const chars = Array.from(model);\n let token = 0;\n let char = 0;\n let star = -1;\n let resume = 0;\n while (char < chars.length) {\n const current = tokens[token];\n if (current !== undefined && (current.kind === \"one\" || (current.kind === \"char\" && current.char === chars[char]))) {\n token++;\n char++;\n } else if (current?.kind === \"any\") {\n star = token++;\n resume = char;\n } else if (star >= 0) {\n token = star + 1;\n char = ++resume;\n } else return false;\n }\n while (tokens[token]?.kind === \"any\") token++;\n return token === tokens.length;\n}\n","/**\n * Package URLs (purl): parse, format and normalize, as the purl specification tells\n * (`https://github.com/package-url/purl-spec`). The form is `pkg:type/namespace/name@version?qualifiers#subpath`.\n *\n * The functions are plain functions with no fetch and no state.\n */\n\n/** A package URL as its parts. Each text part is decoded: it has no percent-encoding. */\nexport interface Purl {\n /** The type of the package, in lower case, for example `npm` or `pypi`. */\n readonly type: string;\n /** The namespace, with `/` between its segments, or `undefined` when the purl has no namespace. */\n readonly namespace?: string;\n /** The name of the package. */\n readonly name: string;\n /** The version, or `undefined` when the purl has no version. */\n readonly version?: string;\n /** The qualifiers, with lower-case keys. A qualifier with an empty value is not in the record. */\n readonly qualifiers?: Readonly<Record<string, string>>;\n /** The subpath, with `/` between its segments, or `undefined` when the purl has no subpath. */\n readonly subpath?: string;\n}\n\n/** The pattern of a type: a letter first, then letters, digits, `.`, `+` or `-`. */\nconst TYPE = /^[a-z][a-z0-9.+-]*$/;\n\n/** The pattern of a qualifier key: a letter first, then letters, digits, `.`, `-` or `_`. */\nconst KEY = /^[a-z][a-z0-9._-]*$/;\n\n/**\n * The types whose namespace and name are not case sensitive. The canonical form of these parts is lower case.\n * The list comes from the type definitions of the purl specification.\n */\nconst LOWER_NAMESPACE_AND_NAME: ReadonlySet<string> = new Set([\"alpm\", \"apk\", \"bitbucket\", \"composer\", \"deb\", \"github\", \"golang\", \"npm\"]);\n\n/** The types whose name only is not case sensitive. The canonical form of the name is lower case. */\nconst LOWER_NAME: ReadonlySet<string> = new Set([\"hex\", \"pub\", \"pypi\"]);\n\n/** This function percent-encodes one part of a purl. A letter, a digit, `.-_~` and `:` stay as they are. */\nfunction encode(text: string): string {\n return encodeURIComponent(text)\n .replace(/[!'()*]/g, (character) => `%${character.charCodeAt(0).toString(16).toUpperCase()}`)\n .replace(/%3A/g, \":\");\n}\n\n/** This function decodes one part of a purl, or gives `undefined` for a bad percent-encoding. */\nfunction decode(text: string): string | undefined {\n try {\n return decodeURIComponent(text);\n } catch {\n return undefined;\n }\n}\n\n/** This function splits a path into its decoded segments. It discards each empty segment. */\nfunction segments(text: string): string[] | undefined {\n const parts: string[] = [];\n for (const raw of text.split(\"/\")) {\n if (raw === \"\") continue;\n const part = decode(raw);\n if (part === undefined) return undefined;\n parts.push(part);\n }\n return parts;\n}\n\n/**\n * This function gives the canonical parts of a purl. The type and the qualifier keys are in lower case. The parts\n * follow the case rules of the type, and no part is empty.\n * It gives `undefined` when a part breaks a rule of the specification.\n */\nexport function normalizePurl(purl: Purl): Purl | undefined {\n const type = purl.type.toLowerCase();\n if (!TYPE.test(type)) return undefined;\n const lowerAll = LOWER_NAMESPACE_AND_NAME.has(type);\n const lowerName = lowerAll || LOWER_NAME.has(type);\n let name = lowerName ? purl.name.toLowerCase() : purl.name;\n if (type === \"pypi\") name = name.replace(/_/g, \"-\");\n if (name === \"\") return undefined;\n const space = purl.namespace?.split(\"/\").filter((segment) => segment !== \"\").join(\"/\");\n const namespace = space === undefined || space === \"\" ? undefined : lowerAll ? space.toLowerCase() : space;\n if (type === \"maven\" && namespace === undefined) return undefined;\n const qualifiers: Record<string, string> = {};\n for (const [key, value] of Object.entries(purl.qualifiers ?? {})) {\n const lower = key.toLowerCase();\n if (!KEY.test(lower)) return undefined;\n if (value !== \"\") qualifiers[lower] = value;\n }\n const subpath = purl.subpath\n ?.split(\"/\")\n .filter((segment) => segment !== \"\" && segment !== \".\" && segment !== \"..\")\n .join(\"/\");\n return {\n type,\n ...(namespace === undefined ? {} : { namespace }),\n name,\n ...(purl.version === undefined || purl.version === \"\" ? {} : { version: purl.version }),\n ...(Object.keys(qualifiers).length === 0 ? {} : { qualifiers }),\n ...(subpath === undefined || subpath === \"\" ? {} : { subpath }),\n };\n}\n\n/**\n * This function reads a purl text into its parts, as the parse steps of the specification tell, and normalizes them.\n * It gives `undefined` when the text is not a valid purl.\n */\nexport function parsePurl(text: string): Purl | undefined {\n let rest = text.trim();\n let subpath: string | undefined;\n const hash = rest.indexOf(\"#\");\n if (hash >= 0) {\n const parts = segments(rest.slice(hash + 1));\n if (parts === undefined) return undefined;\n subpath = parts.filter((segment) => segment !== \".\" && segment !== \"..\").join(\"/\");\n rest = rest.slice(0, hash);\n }\n let qualifiers: Record<string, string> | undefined;\n const question = rest.indexOf(\"?\");\n if (question >= 0) {\n qualifiers = {};\n for (const pair of rest.slice(question + 1).split(\"&\")) {\n if (pair === \"\") continue;\n const equal = pair.indexOf(\"=\");\n if (equal <= 0) return undefined;\n const key = pair.slice(0, equal).toLowerCase();\n const value = decode(pair.slice(equal + 1));\n if (value === undefined || key in qualifiers) return undefined;\n qualifiers[key] = value;\n }\n rest = rest.slice(0, question);\n }\n const colon = rest.indexOf(\":\");\n if (colon < 0 || rest.slice(0, colon).toLowerCase() !== \"pkg\") return undefined;\n rest = rest.slice(colon + 1).replace(/^\\/+/, \"\");\n const slash = rest.indexOf(\"/\");\n if (slash <= 0) return undefined;\n const type = rest.slice(0, slash);\n rest = rest.slice(slash + 1);\n let version: string | undefined;\n const at = rest.lastIndexOf(\"@\");\n // An npm scope in a purl is `%40`, so a raw `@` starts the version. A raw `@` at the start of the\n // namespace is not a version.\n if (at > 0) {\n version = decode(rest.slice(at + 1));\n if (version === undefined) return undefined;\n rest = rest.slice(0, at);\n }\n const path = segments(rest);\n if (path === undefined || path.length === 0) return undefined;\n const name = path[path.length - 1]!;\n const namespace = path.length > 1 ? path.slice(0, -1).join(\"/\") : undefined;\n return normalizePurl({\n type,\n ...(namespace === undefined ? {} : { namespace }),\n name,\n ...(version === undefined ? {} : { version }),\n ...(qualifiers === undefined ? {} : { qualifiers }),\n ...(subpath === undefined ? {} : { subpath }),\n });\n}\n\n/**\n * This function writes the canonical text of a purl: the parts normalized, each part percent-encoded and the\n * qualifiers in the order of their keys. It gives `undefined` when a part breaks a rule of the specification.\n */\nexport function formatPurl(purl: Purl): string | undefined {\n const canonical = normalizePurl(purl);\n if (canonical === undefined) return undefined;\n let text = `pkg:${canonical.type}/`;\n if (canonical.namespace !== undefined) text += `${canonical.namespace.split(\"/\").map(encode).join(\"/\")}/`;\n text += encode(canonical.name);\n if (canonical.version !== undefined) text += `@${encode(canonical.version)}`;\n const keys = Object.keys(canonical.qualifiers ?? {}).sort();\n // A qualifier value keeps its `/`, as the test suite of the specification does with `repository_url`.\n if (keys.length > 0) text += `?${keys.map((key) => `${key}=${encode(canonical.qualifiers![key]!).replace(/%2F/g, \"/\")}`).join(\"&\")}`;\n if (canonical.subpath !== undefined) text += `#${canonical.subpath.split(\"/\").map(encode).join(\"/\")}`;\n return text;\n}\n\n/**\n * This function gives the canonical purl of the package with no version, no qualifiers and no subpath. A person who\n * names a package with this text names each version of it. It gives `undefined` when the text is not a valid purl.\n */\nexport function packagePurlOf(text: string): string | undefined {\n const purl = parsePurl(text);\n return purl === undefined ? undefined : formatPurl({ type: purl.type, ...(purl.namespace === undefined ? {} : { namespace: purl.namespace }), name: purl.name });\n}\n","/**\n * The version order of each ecosystem: SemVer, Go modules, PEP 440, Debian and RPM. The `vers` schemes `intdot` and\n * `generic` have an order too. Each function compares two versions of one scheme. A text that is not a version of the\n * scheme gives `undefined`, not a guess.\n */\n\n/** The version schemes that this module compares. */\nexport type VersionScheme = \"semver\" | \"golang\" | \"pypi\" | \"deb\" | \"rpm\" | \"intdot\" | \"generic\";\n\n/** The version scheme of each purl type whose order this module knows. */\nconst TYPE_SCHEMES: ReadonlyMap<string, VersionScheme> = new Map([\n [\"npm\", \"semver\"],\n [\"cargo\", \"semver\"],\n [\"semver\", \"semver\"],\n [\"golang\", \"golang\"],\n [\"pypi\", \"pypi\"],\n [\"deb\", \"deb\"],\n [\"rpm\", \"rpm\"],\n [\"generic\", \"generic\"],\n]);\n\n/** This function gives the version scheme of a purl type, or `undefined` for a type whose order this module does not know. */\nexport function versionScheme(type: string): VersionScheme | undefined {\n return TYPE_SCHEMES.get(type.toLowerCase());\n}\n\n/**\n * This function compares two versions of one scheme. The result is below 0 when `a` comes before `b`, 0 when they are\n * equal and above 0 when `a` comes after `b`. When a text is not a version of the scheme, the result is `undefined`.\n */\nexport function compareVersions(scheme: string, a: string, b: string): number | undefined {\n switch (scheme) {\n case \"semver\":\n case \"npm\":\n case \"cargo\":\n return compareSemver(a, b);\n case \"golang\":\n return compareGo(a, b);\n case \"pypi\":\n return comparePep440(a, b);\n case \"deb\":\n return compareDebian(a, b);\n case \"rpm\":\n return compareRpm(a, b);\n case \"intdot\":\n return compareIntdot(a, b);\n case \"generic\":\n return compareGeneric(a, b);\n default:\n return undefined;\n }\n}\n\nconst sign = (n: number): number => (n < 0 ? -1 : n > 0 ? 1 : 0);\nconst compareText = (a: string, b: string): number => (a < b ? -1 : a > b ? 1 : 0);\nconst compareDigits = (a: string, b: string): number => {\n const x = a.replace(/^0+(?=\\d)/, \"\");\n const y = b.replace(/^0+(?=\\d)/, \"\");\n return x.length !== y.length ? sign(x.length - y.length) : compareText(x, y);\n};\n\n// SemVer 2.0.0. The build metadata does not change the order.\nconst SEMVER = /^v?(0|[1-9]\\d*)\\.(0|[1-9]\\d*)\\.(0|[1-9]\\d*)(?:-((?:0|[1-9]\\d*|\\d*[A-Za-z-][0-9A-Za-z-]*)(?:\\.(?:0|[1-9]\\d*|\\d*[A-Za-z-][0-9A-Za-z-]*))*))?(?:\\+[0-9A-Za-z-]+(?:\\.[0-9A-Za-z-]+)*)?$/;\n\n/** The parts of a SemVer version that decide its order. */\ninterface Semver {\n readonly core: readonly [string, string, string];\n readonly pre: readonly string[];\n}\n\nfunction parseSemver(text: string): Semver | undefined {\n const match = SEMVER.exec(text.trim().replace(/^=/, \"\"));\n if (match === null) return undefined;\n return { core: [match[1]!, match[2]!, match[3]!], pre: match[4] === undefined ? [] : match[4].split(\".\") };\n}\n\nfunction compareSemverParts(x: Semver, y: Semver): number {\n for (let i = 0; i < 3; i++) {\n const c = compareDigits(x.core[i]!, y.core[i]!);\n if (c !== 0) return c;\n }\n // A version with a pre-release comes before the same version with no pre-release.\n if (x.pre.length === 0 || y.pre.length === 0) return sign(y.pre.length - x.pre.length);\n for (let i = 0; i < Math.min(x.pre.length, y.pre.length); i++) {\n const p = x.pre[i]!;\n const q = y.pre[i]!;\n const pn = /^\\d+$/.test(p);\n const qn = /^\\d+$/.test(q);\n const c = pn && qn ? compareDigits(p, q) : pn ? -1 : qn ? 1 : compareText(p, q);\n if (c !== 0) return c;\n }\n return sign(x.pre.length - y.pre.length);\n}\n\n/** This function compares two SemVer 2.0.0 versions. It accepts a leading `v` or `=`, as npm does. */\nexport function compareSemver(a: string, b: string): number | undefined {\n const x = parseSemver(a);\n const y = parseSemver(b);\n return x === undefined || y === undefined ? undefined : compareSemverParts(x, y);\n}\n\n/**\n * This function compares two versions of Go modules. A Go version starts with `v` and follows SemVer. A pseudo-version is\n * a pre-release, so it has its place in the order of SemVer. The suffix `+incompatible` is build metadata.\n */\nexport function compareGo(a: string, b: string): number | undefined {\n if (!a.startsWith(\"v\") || !b.startsWith(\"v\")) return undefined;\n return compareSemver(a, b);\n}\n\n// PEP 440: the pattern of the version specification of the Python packaging guide.\nconst PEP440 =\n /^\\s*v?(?:(?:(\\d+)!)?(\\d+(?:\\.\\d+)*)(?:[-_.]?(a|b|c|rc|alpha|beta|pre|preview)[-_.]?(\\d+)?)?(?:-(\\d+)|[-_.]?(post|rev|r)[-_.]?(\\d+)?)?(?:[-_.]?(dev)[-_.]?(\\d+)?)?)(?:\\+([a-z0-9]+(?:[-_.][a-z0-9]+)*))?\\s*$/i;\n\n/** The parts of a PEP 440 version that decide its order. */\ninterface Pep440 {\n readonly epoch: number;\n readonly release: readonly number[];\n /** The pre-release as a rank (a 0, b 1, rc 2) and a number. */\n readonly pre?: readonly [number, number];\n readonly post?: number;\n readonly dev?: number;\n readonly local: readonly string[];\n}\n\nconst PRE_RANK: Readonly<Record<string, number>> = { a: 0, alpha: 0, b: 1, beta: 1, c: 2, rc: 2, pre: 2, preview: 2 };\n\nfunction parsePep440(text: string): Pep440 | undefined {\n const m = PEP440.exec(text);\n if (m === null) return undefined;\n const release = m[2]!.split(\".\").map(Number);\n while (release.length > 1 && release[release.length - 1] === 0) release.pop();\n const post = m[5] !== undefined ? Number(m[5]) : m[6] !== undefined ? Number(m[7] ?? 0) : undefined;\n return {\n epoch: Number(m[1] ?? 0),\n release,\n ...(m[3] === undefined ? {} : { pre: [PRE_RANK[m[3].toLowerCase()]!, Number(m[4] ?? 0)] as const }),\n ...(post === undefined ? {} : { post }),\n ...(m[8] === undefined ? {} : { dev: Number(m[9] ?? 0) }),\n local: m[10] === undefined ? [] : m[10].toLowerCase().split(/[-_.]/),\n };\n}\n\nfunction compareNumbers(a: readonly number[], b: readonly number[]): number {\n for (let i = 0; i < Math.max(a.length, b.length); i++) {\n const c = sign((a[i] ?? 0) - (b[i] ?? 0));\n if (c !== 0) return c;\n }\n return 0;\n}\n\n/** This function compares two PEP 440 versions, with the order of the Python packaging specification. */\nexport function comparePep440(a: string, b: string): number | undefined {\n const x = parsePep440(a);\n const y = parsePep440(b);\n if (x === undefined || y === undefined) return undefined;\n const epoch = sign(x.epoch - y.epoch);\n if (epoch !== 0) return epoch;\n const release = compareNumbers(x.release, y.release);\n if (release !== 0) return release;\n // A dev release with no pre-release and no post-release comes before each pre-release.\n const preKey = (v: Pep440): readonly number[] => (v.pre !== undefined ? [0, ...v.pre] : v.post === undefined && v.dev !== undefined ? [-1] : [1]);\n const pre = compareNumbers(preKey(x), preKey(y));\n if (pre !== 0) return pre;\n const postKey = (v: Pep440): readonly number[] => (v.post === undefined ? [-1] : [0, v.post]);\n const post = compareNumbers(postKey(x), postKey(y));\n if (post !== 0) return post;\n const devKey = (v: Pep440): readonly number[] => (v.dev === undefined ? [1] : [0, v.dev]);\n const dev = compareNumbers(devKey(x), devKey(y));\n if (dev !== 0) return dev;\n return compareLocal(x.local, y.local);\n}\n\n// A local version comes after the same version with no local part. A number segment comes after a text segment.\nfunction compareLocal(a: readonly string[], b: readonly string[]): number {\n for (let i = 0; i < Math.min(a.length, b.length); i++) {\n const p = a[i]!;\n const q = b[i]!;\n const pn = /^\\d+$/.test(p);\n const qn = /^\\d+$/.test(q);\n const c = pn && qn ? compareDigits(p, q) : pn ? 1 : qn ? -1 : compareText(p, q);\n if (c !== 0) return c;\n }\n return sign(a.length - b.length);\n}\n\n// The order of a character of a Debian version: `~` comes before the end, the end before a letter, a letter before\n// each other character. A digit has the rank of the end, as in dpkg.\nfunction debianRank(text: string, i: number): number {\n if (i >= text.length) return 0;\n const c = text[i]!;\n if (/d/.test(c)) return 0;\n if (c === \"~\") return -1;\n if (/[A-Za-z]/.test(c)) return c.charCodeAt(0);\n return c.charCodeAt(0) + 256;\n}\n\n// The comparison of dpkg: parts with no digit and parts of digits, one after the other.\nfunction compareDebianPart(a: string, b: string): number {\n let i = 0;\n let j = 0;\n while (i < a.length || j < b.length) {\n while ((i < a.length && !/\\d/.test(a[i]!)) || (j < b.length && !/\\d/.test(b[j]!))) {\n const c = debianRank(a, i) - debianRank(b, j);\n if (c !== 0) return sign(c);\n i++;\n j++;\n }\n let p = \"\";\n let q = \"\";\n while (i < a.length && /\\d/.test(a[i]!)) p += a[i++];\n while (j < b.length && /\\d/.test(b[j]!)) q += b[j++];\n const c = compareDigits(p || \"0\", q || \"0\");\n if (c !== 0) return c;\n }\n return 0;\n}\n\nconst DEBIAN = /^(?:(\\d+):)?([0-9][A-Za-z0-9.+~:-]*?)(?:-([A-Za-z0-9.+~]+))?$/;\n\n/** This function compares two Debian versions (`[epoch:]upstream[-revision]`) with the order of dpkg. */\nexport function compareDebian(a: string, b: string): number | undefined {\n const x = DEBIAN.exec(a.trim());\n const y = DEBIAN.exec(b.trim());\n if (x === null || y === null) return undefined;\n const epoch = compareDigits(x[1] ?? \"0\", y[1] ?? \"0\");\n if (epoch !== 0) return epoch;\n const upstream = compareDebianPart(x[2]!, y[2]!);\n if (upstream !== 0) return upstream;\n return compareDebianPart(x[3] ?? \"0\", y[3] ?? \"0\");\n}\n\n// The comparison of rpmvercmp: segments of letters or digits. `~` comes before each other thing, also the end. `^` comes\n// after the end, but before each other segment.\nfunction rpmvercmp(a: string, b: string): number {\n if (a === b) return 0;\n let i = 0;\n let j = 0;\n for (;;) {\n while (i < a.length && !/[A-Za-z0-9~^]/.test(a[i]!)) i++;\n while (j < b.length && !/[A-Za-z0-9~^]/.test(b[j]!)) j++;\n const ca = a[i];\n const cb = b[j];\n if (ca === \"~\" || cb === \"~\") {\n if (ca !== \"~\") return 1;\n if (cb !== \"~\") return -1;\n i++;\n j++;\n continue;\n }\n if (ca === \"^\" || cb === \"^\") {\n if (ca === undefined) return -1;\n if (cb === undefined) return 1;\n if (ca !== \"^\") return 1;\n if (cb !== \"^\") return -1;\n i++;\n j++;\n continue;\n }\n if (ca === undefined || cb === undefined) break;\n const digits = /\\d/.test(ca);\n const same = digits ? /\\d/ : /[A-Za-z]/;\n let p = \"\";\n let q = \"\";\n while (i < a.length && same.test(a[i]!)) p += a[i++];\n while (j < b.length && same.test(b[j]!)) q += b[j++];\n // A segment of digits comes after a segment of letters.\n if (q === \"\") return digits ? 1 : -1;\n const c = digits ? compareDigits(p, q) : compareText(p, q);\n if (c !== 0) return c;\n }\n if (i >= a.length && j >= b.length) return 0;\n return i >= a.length ? -1 : 1;\n}\n\nconst RPM = /^(?:(\\d+):)?([^-]+)(?:-([^-]+))?$/;\n\n/** This function compares two RPM versions (`[epoch:]version[-release]`) with the order of `rpmvercmp`. */\nexport function compareRpm(a: string, b: string): number | undefined {\n const x = RPM.exec(a.trim());\n const y = RPM.exec(b.trim());\n if (x === null || y === null) return undefined;\n const epoch = compareDigits(x[1] ?? \"0\", y[1] ?? \"0\");\n if (epoch !== 0) return epoch;\n const version = rpmvercmp(x[2]!, y[2]!);\n if (version !== 0) return version;\n // A version with no release comes before each release of that version. Thus a check of a fix does not take it as fixed.\n return rpmvercmp(x[3] ?? \"\", y[3] ?? \"\");\n}\n\nconst INTDOT = /^\\d+(?:\\.\\d+)*$/;\n\n/**\n * This function compares two versions of the `vers` scheme `intdot`: integers with a `.` between them. The integers\n * compare from left to right. A missing integer is 0, so `1.0` equals `1.0.0`.\n */\nexport function compareIntdot(a: string, b: string): number | undefined {\n const x = a.trim();\n const y = b.trim();\n if (!INTDOT.test(x) || !INTDOT.test(y)) return undefined;\n const p = x.split(\".\");\n const q = y.split(\".\");\n for (let i = 0; i < Math.max(p.length, q.length); i++) {\n const c = compareDigits(p[i] ?? \"0\", q[i] ?? \"0\");\n if (c !== 0) return c;\n }\n return 0;\n}\n\n/** This function gives the segments of a version of a vendor: the runs of digits and the runs of letters. */\nfunction genericSegments(text: string): readonly string[] | undefined {\n // One `v` before a digit is a prefix, not a segment: `V6.80` is the version `6.80`.\n const body = text.trim().replace(/^[vV](?=\\d)/, \"\");\n if (!/^\\d/.test(body)) return undefined;\n return body.match(/\\d+|[A-Za-z]+/g) ?? undefined;\n}\n\nconst isDigits = (segment: string): boolean => /^\\d/.test(segment);\n\n/**\n * This function compares two versions of the `vers` scheme `generic`, the versions of vendors, for example `V6.80` or\n * `2.9.1.0_FR`. A version starts with a digit, after one optional `v`. The segments are the runs of digits and of letters.\n * The other characters separate the segments.\n *\n * The segments compare from left to right, and the first difference decides. Two runs of digits compare as integers.\n * Two runs of letters are equal when they are the same with no regard to case. Other pairs have no known order. These\n * pairs give `undefined`: two different runs of letters, or a run of digits and a run of letters.\n *\n * When one version ends first, a rest of zeros is equal to the end. A rest with a number above 0 before its first letters\n * comes after the end. A rest with letters before such a number, for example ` SP1` or `-beta`, has no known order.\n */\nexport function compareGeneric(a: string, b: string): number | undefined {\n const p = genericSegments(a);\n const q = genericSegments(b);\n if (p === undefined || q === undefined) return undefined;\n for (let i = 0; i < Math.min(p.length, q.length); i++) {\n const x = p[i]!;\n const y = q[i]!;\n if (isDigits(x) && isDigits(y)) {\n const c = compareDigits(x, y);\n if (c !== 0) return c;\n } else if (isDigits(x) || isDigits(y) || x.toLowerCase() !== y.toLowerCase()) {\n return undefined;\n }\n }\n const rest = p.length > q.length ? p.slice(q.length) : q.slice(p.length);\n const longer = p.length > q.length ? 1 : -1;\n for (const segment of rest) {\n if (!isDigits(segment)) return undefined;\n if (/[1-9]/.test(segment)) return longer;\n }\n return 0;\n}\n","/**\n * The map from the ecosystems of OSV (`https://ossf.github.io/osv-schema/`) to purl types, and the purl of a package\n * of an OSV record.\n */\n\nimport { formatPurl, packagePurlOf } from \"./purl.ts\";\nimport type { Vers, VersConstraint } from \"./vers.ts\";\nimport { compareVersions, versionScheme } from \"./version.ts\";\n\n/**\n * The purl type of each OSV ecosystem that has one. An ecosystem that is not in the table has no purl.\n * For a Linux distribution, the table key is the part of the ecosystem before the first `:`.\n */\nexport const OSV_PURL_TYPES: Readonly<Record<string, string>> = {\n npm: \"npm\",\n PyPI: \"pypi\",\n \"crates.io\": \"cargo\",\n RubyGems: \"gem\",\n NuGet: \"nuget\",\n Go: \"golang\",\n Maven: \"maven\",\n Packagist: \"composer\",\n Pub: \"pub\",\n Hex: \"hex\",\n Hackage: \"hackage\",\n CRAN: \"cran\",\n \"GitHub Actions\": \"github\",\n Debian: \"deb\",\n Ubuntu: \"deb\",\n Alpine: \"apk\",\n};\n\n/** The purl namespace of each OSV ecosystem of a Linux distribution: the name of the distribution. */\nconst DISTRIBUTION: Readonly<Record<string, string>> = { Debian: \"debian\", Ubuntu: \"ubuntu\", Alpine: \"alpine\" };\n\n/** This function gives the namespace and the name of an OSV package name, as the purl type of its ecosystem splits them. */\nfunction split(type: string, name: string): { readonly namespace?: string; readonly name: string } | undefined {\n switch (type) {\n case \"npm\": {\n const slash = name.indexOf(\"/\");\n return name.startsWith(\"@\") && slash > 1 ? { namespace: name.slice(0, slash), name: name.slice(slash + 1) } : { name };\n }\n case \"golang\":\n case \"composer\":\n case \"github\": {\n const slash = name.lastIndexOf(\"/\");\n return slash > 0 ? { namespace: name.slice(0, slash), name: name.slice(slash + 1) } : { name };\n }\n case \"maven\": {\n const colon = name.indexOf(\":\");\n return colon > 0 ? { namespace: name.slice(0, colon), name: name.slice(colon + 1) } : undefined;\n }\n default:\n return { name };\n }\n}\n\n/**\n * This function gives the canonical purl of an OSV package, with no version. For an ecosystem with no purl type, or\n * a bad name, it gives `undefined`.\n */\nexport function osvPurl(ecosystem: string, name: string): string | undefined {\n const base = ecosystem.split(\":\")[0]!;\n const type = Object.hasOwn(OSV_PURL_TYPES, base) ? OSV_PURL_TYPES[base] : undefined;\n if (type === undefined || name === \"\") return undefined;\n const names = split(type, name);\n if (names === undefined) return undefined;\n const distribution = Object.hasOwn(DISTRIBUTION, base) ? DISTRIBUTION[base] : undefined;\n const namespace = distribution ?? names.namespace;\n return formatPurl({ type, ...(namespace === undefined ? {} : { namespace }), name: names.name });\n}\n\n/**\n * This function gives the purl of a package of an OSV record, with no version, qualifiers or subpath. A valid purl\n * of the record wins. Else the function builds the purl from the ecosystem and the name.\n */\nexport function osvPackagePurl(pkg: { readonly ecosystem: string; readonly name: string; readonly purl?: string }): string | undefined {\n const own = pkg.purl === undefined ? undefined : packagePurlOf(pkg.purl);\n return own ?? osvPurl(pkg.ecosystem, pkg.name);\n}\n\n/** One event of an OSV range, as the OSV schema writes it: each event has one of the four fields. */\nexport interface OsvEvent {\n readonly introduced?: string;\n readonly fixed?: string;\n readonly last_affected?: string;\n readonly limit?: string;\n}\n\n/** A range of an OSV record: its type (`SEMVER`, `ECOSYSTEM` or `GIT`) and its events. */\nexport interface OsvRange {\n readonly type: string;\n readonly events: readonly OsvEvent[];\n}\n\n/**\n * This function gives the `vers` range of an OSV range. A range of the type `SEMVER` has the scheme `semver`. A range\n * of the type `ECOSYSTEM` has the purl type of its ecosystem as its scheme. A `GIT` range, an ecosystem with no purl type\n * or an event with no version gives `undefined`.\n *\n * The events come in the order of their versions, as the OSV schema tells, when the scheme has a known order. Else they\n * keep the order of the record. The event `introduced 0` is the start of each version, so it gives no constraint.\n */\nexport function osvRangeVers(ecosystem: string, range: OsvRange): Vers | undefined {\n const base = ecosystem.split(\":\")[0]!;\n const type = Object.hasOwn(OSV_PURL_TYPES, base) ? OSV_PURL_TYPES[base] : undefined;\n const scheme = range.type === \"SEMVER\" ? \"semver\" : range.type === \"ECOSYSTEM\" ? type : undefined;\n if (scheme === undefined) return undefined;\n const constraints: VersConstraint[] = [];\n let all = false;\n for (const event of range.events) {\n const constraint = eventConstraint(event);\n if (constraint === undefined) return undefined;\n if (constraint === \"start\") all = true;\n else if (constraint !== \"none\") constraints.push(constraint);\n }\n if (constraints.length === 0) return all ? { scheme, all: true, constraints: [] } : undefined;\n return { scheme, all: false, constraints: sortEvents(scheme, constraints) };\n}\n\n// The constraint of one event: \"start\" for `introduced 0`, \"none\" for `limit *` (no limit).\nfunction eventConstraint(event: OsvEvent): VersConstraint | \"start\" | \"none\" | undefined {\n if (event.introduced !== undefined) return event.introduced === \"0\" ? \"start\" : { comparator: \">=\", version: event.introduced };\n if (event.fixed !== undefined) return { comparator: \"<\", version: event.fixed };\n if (event.last_affected !== undefined) return { comparator: \"<=\", version: event.last_affected };\n if (event.limit !== undefined) return event.limit === \"*\" ? \"none\" : { comparator: \"<\", version: event.limit };\n return undefined;\n}\n\n// The constraints in the order of their versions, or in their own order when the scheme has no known order.\nfunction sortEvents(scheme: string, constraints: readonly VersConstraint[]): VersConstraint[] {\n if (versionScheme(scheme) === undefined) return [...constraints];\n let unknown = false;\n const sorted = [...constraints].sort((a, b) => {\n const c = compareVersions(scheme, a.version, b.version);\n if (c === undefined) unknown = true;\n return c ?? 0;\n });\n return unknown ? [...constraints] : sorted;\n}\n","/**\n * Version ranges in the `vers` format of the purl specification, for example `vers:npm/>=1.0.0|<1.2.3`. The functions\n * parse a range, format it and tell if a version is in it, with the version order of the scheme.\n */\nimport { compareVersions } from \"./version.ts\";\n\n/** The comparators of a `vers` constraint. */\nexport type VersComparator = \"=\" | \"!=\" | \"<\" | \"<=\" | \">\" | \">=\";\n\n/** One constraint of a range: a comparator and a version. */\nexport interface VersConstraint {\n readonly comparator: VersComparator;\n readonly version: string;\n}\n\n/** A version range. A range with the constraint `*` holds each version, and its list of constraints is empty. */\nexport interface Vers {\n /** The version scheme, for example `npm`, `pypi` or `deb`. */\n readonly scheme: string;\n /** True: the range is `*`, so it holds each version. */\n readonly all: boolean;\n readonly constraints: readonly VersConstraint[];\n}\n\n// The longer comparators come first, so `<=` is not read as `<` and a version that starts with `=`.\nconst COMPARATORS: readonly VersComparator[] = [\"!=\", \"<=\", \">=\", \"<\", \">\", \"=\"];\n\n/** This function reads one constraint, for example `>=1.0.0`. A constraint with no comparator has the comparator `=`. */\nfunction parseConstraint(text: string): VersConstraint | undefined {\n const trimmed = text.trim();\n const comparator = COMPARATORS.find((c) => trimmed.startsWith(c)) ?? \"=\";\n const raw = trimmed.slice(trimmed.startsWith(comparator) ? comparator.length : 0).trim();\n if (raw === \"\") return undefined;\n let version: string;\n try {\n version = decodeURIComponent(raw);\n } catch {\n return undefined;\n }\n return { comparator, version };\n}\n\n/** This function reads a `vers` text. A text that is not a range gives `undefined`. */\nexport function parseVers(text: string): Vers | undefined {\n const match = /^vers:([A-Za-z0-9.+-]+)\\/(.+)$/.exec(text.replace(/\\s+/g, \"\"));\n if (match === null) return undefined;\n const scheme = match[1]!.toLowerCase();\n const body = match[2]!;\n if (body === \"*\") return { scheme, all: true, constraints: [] };\n const constraints: VersConstraint[] = [];\n for (const part of body.split(\"|\")) {\n const constraint = parseConstraint(part);\n if (constraint === undefined) return undefined;\n constraints.push(constraint);\n }\n return { scheme, all: false, constraints };\n}\n\n// The characters that a version keeps in a `vers` text: the others are percent-encoded.\nconst encodeVersion = (version: string): string => version.replace(/[^A-Za-z0-9.+~_:-]/g, (c) => encodeURIComponent(c));\n\n/**\n * This function gives the `vers` text of a range. The constraints come in the order of the versions, when the scheme\n * has a known order. The comparator `=` has no sign, as the specification tells.\n */\nexport function formatVers(vers: Vers): string {\n if (vers.all) return `vers:${vers.scheme}/*`;\n const sorted = sortConstraints(vers.scheme, vers.constraints) ?? vers.constraints;\n const body = sorted.map((c) => `${c.comparator === \"=\" ? \"\" : c.comparator}${encodeVersion(c.version)}`).join(\"|\");\n return `vers:${vers.scheme}/${body}`;\n}\n\n// The constraints in the order of their versions, or `undefined` when a version is not a version of the scheme.\nfunction sortConstraints(scheme: string, constraints: readonly VersConstraint[]): VersConstraint[] | undefined {\n let unknown = false;\n const sorted = [...constraints].sort((a, b) => {\n const c = compareVersions(scheme, a.version, b.version);\n if (c === undefined) unknown = true;\n return c ?? 0;\n });\n return unknown ? undefined : sorted;\n}\n\n/**\n * This function tells if a version is in a range, with the algorithm of the `vers` specification. The result is\n * `undefined` when the scheme has no known order, or when a version is not a version of the scheme. Thus a caller\n * does not take an unknown result as a match or as no match.\n */\nexport function versContains(vers: Vers, version: string): boolean | undefined {\n if (vers.all) return true;\n const compare = (a: string, b: string): number | undefined => compareVersions(vers.scheme, a, b);\n for (const constraint of vers.constraints) {\n const c = compare(version, constraint.version);\n if (c === undefined) return undefined;\n if (c === 0 && [\"=\", \"<=\", \">=\"].includes(constraint.comparator)) return true;\n if (c === 0 && constraint.comparator === \"!=\") return false;\n }\n const ranged = sortConstraints(\n vers.scheme,\n vers.constraints.filter((c) => c.comparator !== \"=\" && c.comparator !== \"!=\"),\n );\n if (ranged === undefined) return undefined;\n if (ranged.length === 0) {\n // Only `!=` constraints that the version does not equal: the version is in the range.\n return vers.constraints.some((c) => c.comparator === \"!=\");\n }\n const below = (c: VersConstraint): boolean => c.comparator === \"<\" || c.comparator === \"<=\";\n const above = (c: VersConstraint): boolean => c.comparator === \">\" || c.comparator === \">=\";\n const first = ranged[0]!;\n const last = ranged[ranged.length - 1]!;\n if (below(first) && compare(version, first.version)! < 0) return true;\n if (above(last) && compare(version, last.version)! > 0) return true;\n for (let i = 0; i + 1 < ranged.length; i++) {\n const low = ranged[i]!;\n const high = ranged[i + 1]!;\n if (above(low) && below(high) && compare(version, low.version)! > 0 && compare(version, high.version)! < 0) return true;\n }\n return false;\n}\n\n/**\n * This function gives the end of the part of a range that holds a version, when that end is a constraint `<`. For the\n * range of an advisory, it is the first fixed version above the version. The result is `undefined` for a version out\n * of the range, or for an unknown order. It is also `undefined` for a part with no such end: `<=`, an open end or `=`.\n */\nexport function versEnd(vers: Vers, version: string): string | undefined {\n if (vers.all || versContains(vers, version) !== true) return undefined;\n if (vers.constraints.some((c) => c.comparator === \"=\" && compareVersions(vers.scheme, version, c.version) === 0)) return undefined;\n const ranged = sortConstraints(\n vers.scheme,\n vers.constraints.filter((c) => c.comparator !== \"=\" && c.comparator !== \"!=\"),\n );\n const next = ranged?.find((c) => compareVersions(vers.scheme, version, c.version)! < 0);\n return next?.comparator === \"<\" ? next.version : undefined;\n}\n"],"mappings":";;AA6BA,MAAM,aAAa;CAAC;CAAQ;CAAU;CAAW;CAAW;CAAU;CAAW;CAAY;CAAa;CAAY;CAAY;AAAO;;AAGzI,MAAM,QAAQ;;AAGd,MAAM,UAAU,SAA0B,MAAM,KAAK,IAAI,IAAI,OAAO,KAAK;;;;;AAMzE,SAAS,eAAe,OAAmC;CACzD,MAAM,OAAO,MAAM,YAAY;CAC/B,IAAI,SAAS,IAAI,OAAO,KAAA;CACxB,IAAI,SAAS,OAAO,SAAS,KAAK,OAAO;CACzC,IAAI,MAAM;CACV,KAAK,IAAI,QAAQ,GAAG,QAAQ,KAAK,QAAQ,SAAS,GAAG;EACnD,MAAM,OAAO,KAAK;EAClB,IAAI,SAAS,MAAM;GACjB,MAAM,OAAO,KAAK,QAAQ;GAC1B,IAAI,SAAS,KAAA,GAAW,OAAO,KAAA;GAC/B,OAAO,OAAO,IAAI;GAClB,SAAS;EACX,OAAO,IAAI,SAAS,OAAO,SAAS,KAAK;GAEvC,IAAI,CAAC,UAAU,KAAK,KAAK,MAAM,GAAG,QAAQ,CAAC,CAAC,KAAK,CAAC,UAAU,KAAK,KAAK,MAAM,KAAK,CAAC,GAAG,OAAO,KAAA;GAC5F,OAAO;EACT,OAAO,IAAI,KAAK,WAAW,CAAC,IAAI,MAAQ,KAAK,WAAW,CAAC,IAAI,KAC3D;OAEA,OAAO,OAAO,IAAI;CAEtB;CAEA,OAAO,QAAQ,MAAM,QAAQ;AAC/B;;AAGA,SAAS,eAAe,MAAiC;CACvD,MAAM,SAAmB,CAAC;CAC1B,IAAI,UAAU;CACd,KAAK,IAAI,QAAQ,GAAG,QAAQ,KAAK,QA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B,KAAK,QAAQ,SAAS,EAAE,OAAO,MAAM,CAAC,GAAG,OAAO,KAAA;CAKzH,MAAM,OAJS,gBACb,KAAK,QACL,KAAK,YAAY,QAAQ,MAAM,EAAE,eAAe,OAAO,EAAE,eAAe,IAAI,CAE5D,CAAC,EAAE,MAAM,MAAM,gBAAgB,KAAK,QAAQ,SAAS,EAAE,OAAO,IAAK,CAAC;CACtF,OAAO,MAAM,eAAe,MAAM,KAAK,UAAU,KAAA;AACnD"}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"$schema": "https://json.schemastore.org/package",
|
|
3
3
|
"name": "@mark1russell7/package-id",
|
|
4
|
-
"version": "0.1.
|
|
4
|
+
"version": "0.1.2",
|
|
5
5
|
"description": "Package URLs (purl), the purl of each OSV ecosystem, the version order of each ecosystem and version ranges (vers). Plain functions with no fetch.",
|
|
6
6
|
"keywords": [
|
|
7
7
|
"purl",
|
package/src/cpe.ts
ADDED
|
@@ -0,0 +1,173 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* CPE names of the NIST specification (NISTIR 7695): the formatted string of CPE 2.3, for example
|
|
3
|
+
* `cpe:2.3:a:apache:http_server:2.4.62:*:*:*:*:*:*:*`, and the URI of CPE 2.2, for example `cpe:/a:apache:http_server:2.4.62`.
|
|
4
|
+
* The functions read a name, write it as a formatted string and give the product of a name with no version. The match
|
|
5
|
+
* of a CSAF advisory to a device uses them: a vendor gives a CPE when a product has no purl.
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
/** The part of a CPE name: `a` an application, `o` an operating system, `h` a hardware device, `*` any part. */
|
|
9
|
+
export type CpePart = "a" | "o" | "h" | "*";
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* A CPE name. Each attribute is a value of the formatted string, in lower case: `*` is any value, `-` is no value. A
|
|
13
|
+
* special character has a backslash before it, for example `\!`. An unquoted `*` or `?` in a value is a wildcard.
|
|
14
|
+
*/
|
|
15
|
+
export interface Cpe {
|
|
16
|
+
readonly part: CpePart;
|
|
17
|
+
readonly vendor: string;
|
|
18
|
+
readonly product: string;
|
|
19
|
+
readonly version: string;
|
|
20
|
+
readonly update: string;
|
|
21
|
+
readonly edition: string;
|
|
22
|
+
readonly language: string;
|
|
23
|
+
readonly swEdition: string;
|
|
24
|
+
readonly targetSw: string;
|
|
25
|
+
readonly targetHw: string;
|
|
26
|
+
readonly other: string;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
/** The attributes of a name, in the order of the formatted string. */
|
|
30
|
+
const ATTRIBUTES = ["part", "vendor", "product", "version", "update", "edition", "language", "swEdition", "targetSw", "targetHw", "other"] as const;
|
|
31
|
+
|
|
32
|
+
/** The characters that a value keeps with no backslash. */
|
|
33
|
+
const PLAIN = /^[a-z0-9._-]$/;
|
|
34
|
+
|
|
35
|
+
/** This function gives the formatted-string form of one character of a value: a special character gets a backslash. */
|
|
36
|
+
const quoted = (char: string): string => (PLAIN.test(char) ? char : `\\${char}`);
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
* This function gives the canonical form of a value of a formatted string, or `undefined` for a value that is not valid.
|
|
40
|
+
* The form is lower case. A backslash stays only before a special character. Each other special character gets one.
|
|
41
|
+
*/
|
|
42
|
+
function canonicalValue(value: string): string | undefined {
|
|
43
|
+
const text = value.toLowerCase();
|
|
44
|
+
if (text === "") return undefined;
|
|
45
|
+
if (text === "*" || text === "-") return text;
|
|
46
|
+
let out = "";
|
|
47
|
+
for (let index = 0; index < text.length; index += 1) {
|
|
48
|
+
const char = text[index]!;
|
|
49
|
+
if (char === "\\") {
|
|
50
|
+
const next = text[index + 1];
|
|
51
|
+
if (next === undefined) return undefined;
|
|
52
|
+
out += quoted(next);
|
|
53
|
+
index += 1;
|
|
54
|
+
} else if (char === "*" || char === "?") {
|
|
55
|
+
// A wildcard is valid only at the start or the end of a value.
|
|
56
|
+
if (!/^[*?]+$/.test(text.slice(0, index + 1)) && !/^[*?]+$/.test(text.slice(index))) return undefined;
|
|
57
|
+
out += char;
|
|
58
|
+
} else if (char.charCodeAt(0) < 0x21 || char.charCodeAt(0) > 0x7e) {
|
|
59
|
+
return undefined;
|
|
60
|
+
} else {
|
|
61
|
+
out += quoted(char);
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
// A value of one quoted hyphen is a hyphen, not "no value".
|
|
65
|
+
return out === "-" ? "\\-" : out;
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
/** This function splits a formatted string at each colon that has no backslash before it. */
|
|
69
|
+
function splitFormatted(text: string): readonly string[] {
|
|
70
|
+
const values: string[] = [];
|
|
71
|
+
let current = "";
|
|
72
|
+
for (let index = 0; index < text.length; index += 1) {
|
|
73
|
+
const char = text[index]!;
|
|
74
|
+
if (char === "\\" && index + 1 < text.length) {
|
|
75
|
+
current += char + text[index + 1]!;
|
|
76
|
+
index += 1;
|
|
77
|
+
} else if (char === ":") {
|
|
78
|
+
values.push(current);
|
|
79
|
+
current = "";
|
|
80
|
+
} else {
|
|
81
|
+
current += char;
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
values.push(current);
|
|
85
|
+
return values;
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
/** This function gives the formatted-string value of one component of a CPE 2.2 URI, or `undefined`. */
|
|
89
|
+
function uriValue(component: string): string | undefined {
|
|
90
|
+
if (component === "") return "*";
|
|
91
|
+
if (component === "-") return "-";
|
|
92
|
+
let out = "";
|
|
93
|
+
for (let index = 0; index < component.length; index += 1) {
|
|
94
|
+
const char = component[index]!;
|
|
95
|
+
if (char !== "%") {
|
|
96
|
+
if (!/^[A-Za-z0-9._~-]$/.test(char)) return undefined;
|
|
97
|
+
out += quoted(char.toLowerCase());
|
|
98
|
+
continue;
|
|
99
|
+
}
|
|
100
|
+
const code = component.slice(index + 1, index + 3);
|
|
101
|
+
if (!/^[0-9A-Fa-f]{2}$/.test(code)) return undefined;
|
|
102
|
+
index += 2;
|
|
103
|
+
const value = Number.parseInt(code, 16);
|
|
104
|
+
// The codes %01 and %02 are the wildcards `?` and `*` of a URI.
|
|
105
|
+
if (value === 1) out += "?";
|
|
106
|
+
else if (value === 2) out += "*";
|
|
107
|
+
else if (value < 0x21 || value > 0x7e) return undefined;
|
|
108
|
+
else out += quoted(String.fromCharCode(value).toLowerCase());
|
|
109
|
+
}
|
|
110
|
+
return canonicalValue(out);
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
/** This function gives a name from its values in the order of the formatted string, or `undefined`. */
|
|
114
|
+
function cpeOf(values: readonly string[]): Cpe | undefined {
|
|
115
|
+
const canonical = values.map(canonicalValue);
|
|
116
|
+
if (canonical.some((value) => value === undefined)) return undefined;
|
|
117
|
+
const part = canonical[0];
|
|
118
|
+
if (part !== "a" && part !== "o" && part !== "h" && part !== "*") return undefined;
|
|
119
|
+
return Object.fromEntries(ATTRIBUTES.map((name, index) => [name, canonical[index] ?? "*"])) as unknown as Cpe;
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
/** This function reads a CPE 2.2 URI. The packed edition (`~edition~sw_edition~target_sw~target_hw~other`) gives five attributes. */
|
|
123
|
+
function parseUri(text: string): Cpe | undefined {
|
|
124
|
+
const components = text.slice("cpe:/".length).split(":");
|
|
125
|
+
if (components.length > 7) return undefined;
|
|
126
|
+
const [part = "", vendor = "", product = "", version = "", update = "", edition = "", language = ""] = components;
|
|
127
|
+
const packed = edition.startsWith("~") ? edition.slice(1).split("~") : undefined;
|
|
128
|
+
if (packed !== undefined && packed.length !== 5) return undefined;
|
|
129
|
+
// The order of the values is the order of the formatted string: the packed attributes come after the language.
|
|
130
|
+
const values = [part, vendor, product, version, update, packed?.[0] ?? edition, language, ...(packed?.slice(1) ?? [])].map(uriValue);
|
|
131
|
+
if (values.some((value) => value === undefined)) return undefined;
|
|
132
|
+
return cpeOf(values as string[]);
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
/**
|
|
136
|
+
* This function reads a CPE name: a formatted string of CPE 2.3 or a URI of CPE 2.2. A formatted string with fewer than
|
|
137
|
+
* eleven attributes gets `*` for each missing attribute. A text that is not a CPE name gives `undefined`.
|
|
138
|
+
*/
|
|
139
|
+
export function parseCpe(text: string): Cpe | undefined {
|
|
140
|
+
const trimmed = text.trim();
|
|
141
|
+
const lower = trimmed.toLowerCase();
|
|
142
|
+
if (lower.startsWith("cpe:/")) return parseUri(trimmed);
|
|
143
|
+
if (!lower.startsWith("cpe:2.3:")) return undefined;
|
|
144
|
+
const values = splitFormatted(trimmed.slice("cpe:2.3:".length));
|
|
145
|
+
if (values.length < 3 || values.length > ATTRIBUTES.length) return undefined;
|
|
146
|
+
return cpeOf(values);
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
/** This function writes a name as a formatted string of CPE 2.3, with each of its eleven attributes. */
|
|
150
|
+
export function formatCpe(cpe: Cpe): string {
|
|
151
|
+
return `cpe:2.3:${ATTRIBUTES.map((name) => cpe[name]).join(":")}`;
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
/**
|
|
155
|
+
* This function gives the product of a CPE name: the formatted string with the part, the vendor and the product. Each
|
|
156
|
+
* other attribute is `*`. A name with no vendor or no product, or with a wildcard in them, gives `undefined`.
|
|
157
|
+
*/
|
|
158
|
+
export function cpeProductOf(text: string): string | undefined {
|
|
159
|
+
const cpe = parseCpe(text);
|
|
160
|
+
if (cpe === undefined) return undefined;
|
|
161
|
+
const specific = (value: string): boolean => value !== "*" && value !== "-" && !/(^|[^\\])[*?]/.test(value);
|
|
162
|
+
if (!specific(cpe.vendor) || !specific(cpe.product)) return undefined;
|
|
163
|
+
return formatCpe({ part: cpe.part, vendor: cpe.vendor, product: cpe.product, version: "*", update: "*", edition: "*", language: "*", swEdition: "*", targetSw: "*", targetHw: "*", other: "*" });
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
/**
|
|
167
|
+
* This function gives the version of a CPE name with no backslashes, for example `2.4.62`. A name with any version, no
|
|
168
|
+
* version or a wildcard in its version gives `undefined`.
|
|
169
|
+
*/
|
|
170
|
+
export function cpeVersionOf(cpe: Cpe): string | undefined {
|
|
171
|
+
if (cpe.version === "*" || cpe.version === "-" || /(^|[^\\])[*?]/.test(cpe.version)) return undefined;
|
|
172
|
+
return cpe.version.replace(/\\(.)/g, "$1");
|
|
173
|
+
}
|
package/src/index.ts
CHANGED
|
@@ -1,8 +1,10 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Package identities: package URLs (purl), the purl of each OSV ecosystem, the version order of each ecosystem
|
|
2
|
+
* Package identities: package URLs (purl), the purl of each OSV ecosystem, the version order of each ecosystem, version ranges (vers) and CPE names. The functions are plain functions with
|
|
3
3
|
* no fetch.
|
|
4
4
|
*/
|
|
5
5
|
|
|
6
|
+
export { cpeProductOf, cpeVersionOf, formatCpe, parseCpe, type Cpe, type CpePart } from "./cpe.ts";
|
|
7
|
+
export { modelNumberMatches } from "./model.ts";
|
|
6
8
|
export { formatPurl, normalizePurl, packagePurlOf, parsePurl, type Purl } from "./purl.ts";
|
|
7
9
|
export { OSV_PURL_TYPES, osvPackagePurl, osvPurl, osvRangeVers, type OsvEvent, type OsvRange } from "./osv.ts";
|
|
8
10
|
export {
|
package/src/model.ts
ADDED
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The model numbers and the SKUs of CSAF 2.0. A CSAF advisory names a hardware product by a full or partial model number.
|
|
3
|
+
* In such a pattern, `*` stands for zero or more characters and `?` stands for one character. A backslash before `*`,
|
|
4
|
+
* `?` or a backslash makes that character literal. The comparison is exact: the case of each character counts.
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
/** One token of a pattern: any run of characters, one character, or one literal character. */
|
|
8
|
+
type Token = { readonly kind: "any" } | { readonly kind: "one" } | { readonly kind: "char"; readonly char: string };
|
|
9
|
+
|
|
10
|
+
/** This function gives the tokens of a pattern. A backslash at the end is a literal backslash. */
|
|
11
|
+
function tokensOf(pattern: string): readonly Token[] {
|
|
12
|
+
const chars = Array.from(pattern);
|
|
13
|
+
const tokens: Token[] = [];
|
|
14
|
+
for (let index = 0; index < chars.length; index++) {
|
|
15
|
+
const char = chars[index]!;
|
|
16
|
+
const next = chars[index + 1];
|
|
17
|
+
if (char === "\\" && next !== undefined && (next === "*" || next === "?" || next === "\\")) {
|
|
18
|
+
tokens.push({ kind: "char", char: next });
|
|
19
|
+
index++;
|
|
20
|
+
} else if (char === "*") {
|
|
21
|
+
if (tokens.at(-1)?.kind !== "any") tokens.push({ kind: "any" });
|
|
22
|
+
} else if (char === "?") tokens.push({ kind: "one" });
|
|
23
|
+
else tokens.push({ kind: "char", char });
|
|
24
|
+
}
|
|
25
|
+
return tokens;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* This function tells if a model number or a SKU matches a pattern of a CSAF advisory. An empty pattern matches nothing.
|
|
30
|
+
* The match keeps the last `*` and its place, so its time is at most the product of the two lengths.
|
|
31
|
+
*/
|
|
32
|
+
export function modelNumberMatches(pattern: string, model: string): boolean {
|
|
33
|
+
if (pattern === "") return false;
|
|
34
|
+
const tokens = tokensOf(pattern);
|
|
35
|
+
const chars = Array.from(model);
|
|
36
|
+
let token = 0;
|
|
37
|
+
let char = 0;
|
|
38
|
+
let star = -1;
|
|
39
|
+
let resume = 0;
|
|
40
|
+
while (char < chars.length) {
|
|
41
|
+
const current = tokens[token];
|
|
42
|
+
if (current !== undefined && (current.kind === "one" || (current.kind === "char" && current.char === chars[char]))) {
|
|
43
|
+
token++;
|
|
44
|
+
char++;
|
|
45
|
+
} else if (current?.kind === "any") {
|
|
46
|
+
star = token++;
|
|
47
|
+
resume = char;
|
|
48
|
+
} else if (star >= 0) {
|
|
49
|
+
token = star + 1;
|
|
50
|
+
char = ++resume;
|
|
51
|
+
} else return false;
|
|
52
|
+
}
|
|
53
|
+
while (tokens[token]?.kind === "any") token++;
|
|
54
|
+
return token === tokens.length;
|
|
55
|
+
}
|