asn1-ts
Version:
ASN.1 encoding and decoding, including BER, CER, and DER.
14 lines (13 loc) • 439 B
JavaScript
import * as errors from "../errors.mjs";
import { Buffer } from "node:buffer";
export default function decodeUnsignedBigEndianInteger(value) {
if (value.length === 0) {
return 0;
}
if (value.length > 4) {
throw new errors.ASN1OverflowError(`Number on ${value.length} bytes is too long to decode.`);
}
const ret = Buffer.alloc(4);
ret.set(value, (4 - value.length));
return ret.readUInt32BE();
}