Files
NapCatQQ/.pnpm-store/v3/files/e3/64b871713e71642e0c01feebe8355bf418294d7669d0701cc0858a123ad428cc7ca21ce9ea0dbc5867b93969a01621f480963d2dd325702b5ce1cb61e59886
TanTan e311ca3275
Build NapCat Artifacts / Windows Loader Test (push) Canceled after 0s
Build NapCat Artifacts / Type Check & Test (push) Canceled after 0s
Build NapCat Artifacts / Build NapCat.Framework (push) Canceled after 0s
Build NapCat Artifacts / Build NapCat.Shell (push) Canceled after 0s
docs: 仓库链接指向本镜像仓库
2026-11-13 09:25:58 +08:00

39 lines
1.5 KiB
Plaintext

import { AsnSerializer, AsnParser } from "@peculiar/asn1-codec";
import * as asn1js from "asn1js";
export function asnNodeToLegacyType(node) {
if (node.ctx && node.start !== undefined && node.end !== undefined) {
const contextData = node.ctx.data.slice(node.start, node.end);
const parsed = asn1js.fromBER(contextData.buffer);
if (parsed.offset === -1) {
throw new Error("Error parsing ASN.1 with asn1js: " + parsed.result.error);
}
return parsed.result;
}
const derBytes = AsnSerializer.nodeToBytes(node);
const parsed = asn1js.fromBER(derBytes.buffer);
if (parsed.offset === -1) {
throw new Error("Error parsing ASN.1 with asn1js: " + parsed.result.error);
}
return parsed.result;
}
function legacyTypeToAsnNode(value) {
const derBytes = value.toBER();
const parseResult = AsnParser.parse(new Uint8Array(derBytes), { captureRaw: true });
if (parseResult.errors?.length) {
throw new Error(`Failed to parse serialized ASN.1: ${parseResult.errors[0].message}`);
}
return parseResult.root;
}
export function createLegacyConverterAdapter(legacyConverter) {
return {
fromASN: (value) => {
const legacyValue = asnNodeToLegacyType(value);
return legacyConverter.fromASN(legacyValue);
},
toASN: (value) => {
const legacyResult = legacyConverter.toASN(value);
return legacyTypeToAsnNode(legacyResult);
},
};
}