cybara 1.0.1756 → 1.0.1791
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/package.json +1 -1
- package/scripts/download.cjs +14 -15
package/package.json
CHANGED
package/scripts/download.cjs
CHANGED
|
@@ -47,6 +47,17 @@ function fetch(url) {
|
|
|
47
47
|
});
|
|
48
48
|
}
|
|
49
49
|
|
|
50
|
+
function verifyChecksum(payload, sidecar, asset) {
|
|
51
|
+
const expected = (String(sidecar).trim().split(/\s+/)[0] || "").toLowerCase();
|
|
52
|
+
if (!/^[a-f0-9]{64}$/.test(expected)) {
|
|
53
|
+
throw new Error(`invalid checksum sidecar for ${asset}`);
|
|
54
|
+
}
|
|
55
|
+
const actual = crypto.createHash("sha256").update(payload).digest("hex");
|
|
56
|
+
if (actual !== expected) {
|
|
57
|
+
throw new Error(`checksum mismatch for ${asset}`);
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
|
|
50
61
|
async function download(options) {
|
|
51
62
|
const silent = options && options.silent;
|
|
52
63
|
const slug = slugFor(process.platform, process.arch);
|
|
@@ -59,20 +70,8 @@ async function download(options) {
|
|
|
59
70
|
|
|
60
71
|
const payload = await fetch(`${base}/${asset}`);
|
|
61
72
|
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
const sidecar = (await fetch(`${base}/${asset}.sha256`)).toString("utf8").trim();
|
|
65
|
-
const first = sidecar.split(/\s+/)[0];
|
|
66
|
-
if (first) expected = first.toLowerCase();
|
|
67
|
-
} catch {
|
|
68
|
-
expected = null;
|
|
69
|
-
}
|
|
70
|
-
if (expected) {
|
|
71
|
-
const actual = crypto.createHash("sha256").update(payload).digest("hex");
|
|
72
|
-
if (actual !== expected) {
|
|
73
|
-
throw new Error(`checksum mismatch for ${asset}`);
|
|
74
|
-
}
|
|
75
|
-
}
|
|
73
|
+
const sidecar = (await fetch(`${base}/${asset}.sha256`)).toString("utf8");
|
|
74
|
+
verifyChecksum(payload, sidecar, asset);
|
|
76
75
|
|
|
77
76
|
const dest = binaryPath();
|
|
78
77
|
fs.mkdirSync(path.dirname(dest), { recursive: true });
|
|
@@ -82,4 +81,4 @@ async function download(options) {
|
|
|
82
81
|
return dest;
|
|
83
82
|
}
|
|
84
83
|
|
|
85
|
-
module.exports = { download, binaryPath };
|
|
84
|
+
module.exports = { download, binaryPath, verifyChecksum };
|