UNPKG

asn1-ts

Version:

ASN.1 encoding and decoding, including BER, CER, and DER.

14 lines (13 loc) 448 B
import * as errors from "../errors.mjs"; import { Buffer } from "node:buffer"; export default function decodeSignedBigEndianInteger(value) { if (value.length === 0) { return 0; } if (value.length > 4) { throw new errors.ASN1OverflowError("Number too long to decode."); } const ret = Buffer.alloc(4, (value[0] >= 0b10000000) ? 0xFF : 0x00); ret.set(value, (4 - value.length)); return ret.readInt32BE(); }