• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1"use strict";
2Object.defineProperty(exports, "__esModule", { value: true });
3exports.encodeOIDString = void 0;
4const ANS1_TAG_OID = 0x06;
5function encodeOIDString(oid) {
6    const parts = oid.split('.');
7    // The first two subidentifiers are encoded into the first byte
8    const first = parseInt(parts[0], 10) * 40 + parseInt(parts[1], 10);
9    const rest = [];
10    parts.slice(2).forEach((part) => {
11        const bytes = encodeVariableLengthInteger(parseInt(part, 10));
12        rest.push(...bytes);
13    });
14    const der = Buffer.from([first, ...rest]);
15    return Buffer.from([ANS1_TAG_OID, der.length, ...der]);
16}
17exports.encodeOIDString = encodeOIDString;
18function encodeVariableLengthInteger(value) {
19    const bytes = [];
20    let mask = 0x00;
21    while (value > 0) {
22        bytes.unshift((value & 0x7f) | mask);
23        value >>= 7;
24        mask = 0x80;
25    }
26    return bytes;
27}
28