codekingpro/portable-devtools
114k
1"use strict";
2Object.defineProperty(exports, "__esModule", { value: true });
3exports.encodeOIDString = encodeOIDString;
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}
17function encodeVariableLengthInteger(value) {
18 const bytes = [];
19 let mask = 0x00;
20 while (value > 0) {
21 bytes.unshift((value & 0x7f) | mask);
22 value >>= 7;
23 mask = 0x80;
24 }
25 return bytes;
26}
27 