UNPKG

asn1-ts

Version:

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

14 lines (13 loc) 404 B
import packBits from "../../../utils/packBits.mjs"; export default function encodeBitString(value) { if (value.length === 0) { return new Uint8Array([0]); } const ret = new Uint8Array(((value.length >>> 3) + ((value.length % 8) ? 1 : 0)) + 1); ret[0] = (8 - (value.length % 8)); if (ret[0] === 8) { ret[0] = 0; } ret.set(packBits(value), 1); return ret; }