mirror of
https://github.com/morluto/rea.git
synced 2026-11-21 22:15:50 +00:00
refactor(desktop): read OpenPGP packet lengths through BinaryReader
OpenPGP packet headers read their one-, two- and four-byte lengths with raw Buffer reads after the header-width checks. Read them through an openpgp BinaryReader. This was the last counted raw numeric read, so the raw-buffer-read baseline is removed and the guard now refuses any new copy outright. The CI change-scope test names another baseline file as its static-only path. Refs #11865 Co-Authored-By: gensokyo-dev <342580529+gensokyo-dev@users.noreply.github.com>
This commit is contained in:
1 parent
6543a3c1a1
commit
006581b838
3 files changed
+14
-6
No files matched your search
@@ -1,3 +0,0 @@
|
||||
{
|
||||
"src/domain/desktop/openPgpKeys.ts": 2
|
||||
}
|
||||
@@ -1,5 +1,6 @@
|
||||
import { createHash } from "node:crypto";
|
||||
|
||||
import { BinaryReader } from "../binaryContainer.js";
|
||||
import { err, ok, type Result } from "../result.js";
|
||||
import { dearmorPublicKeys, isArmoredKey } from "./aptRepositories.js";
|
||||
|
||||
@@ -22,10 +23,16 @@ const packetHeader = (
|
||||
if ((first & 0x40) === 0) {
|
||||
const width = [1, 2, 4][first & 0x03];
|
||||
if (width === undefined || at + 1 + width > bytes.length) return undefined;
|
||||
const reader = new BinaryReader(bytes, false, "openpgp");
|
||||
return {
|
||||
tag: (first >> 2) & 0x0f,
|
||||
header: 1 + width,
|
||||
body: bytes.readUIntBE(at + 1, width),
|
||||
body:
|
||||
width === 1
|
||||
? reader.u8(at + 1)
|
||||
: width === 2
|
||||
? reader.u16(at + 1)
|
||||
: reader.u32(at + 1),
|
||||
};
|
||||
}
|
||||
const tag = first & 0x3f;
|
||||
@@ -39,7 +46,11 @@ const packetHeader = (
|
||||
: { tag, header: 3, body: ((length - 192) << 8) + next + 192 };
|
||||
}
|
||||
if (length !== 255 || at + 6 > bytes.length) return undefined;
|
||||
return { tag, header: 6, body: bytes.readUInt32BE(at + 2) };
|
||||
return {
|
||||
tag,
|
||||
header: 6,
|
||||
body: new BinaryReader(bytes, false, "openpgp").u32(at + 2),
|
||||
};
|
||||
};
|
||||
|
||||
/** A primary key's fingerprint from its packet body: SHA-1 for version 4, SHA-256 for versions 5 and 6. */
|
||||
|
||||
@@ -581,7 +581,7 @@ it("routes license inventories to docs checks and keeps blame-ignore edits forma
|
||||
for (const staticOnly of [
|
||||
"scripts/lib/module-layers.baseline.json",
|
||||
"scripts/verify/architecture-guards.mjs",
|
||||
"scripts/verify/baselines/raw-buffer-read.json",
|
||||
"scripts/verify/baselines/cleanup-dependency-binding.json",
|
||||
"tsconfig.scripts.json",
|
||||
]) {
|
||||
expect(await classifyPaths([staticOnly]), staticOnly).toMatchObject({
|
||||
|
||||
Reference in new issue
Block a user