(length: number)
| 101 | return Buffer.concat([Buffer.from([tag]), lengthBytes, data]); |
| 102 | } |
| 103 | private static _encodeLength(length: number): Buffer { |
| 104 | if (length < 128) { |
| 105 | return Buffer.from([length]); |
| 106 | } else { |
| 107 | const lengthBytes = []; |
| 108 | while (length > 0) { |
| 109 | lengthBytes.unshift(length & 0xFF); |
| 110 | length >>= 8; |
| 111 | } |
| 112 | return Buffer.from([0x80 | lengthBytes.length, ...lengthBytes]); |
| 113 | } |
| 114 | } |
| 115 | } |
| 116 | |
| 117 | // X.509 Specification: https://datatracker.ietf.org/doc/html/rfc2459#section-4.1 |