pure-js-sftp
Version:
A pure JavaScript SFTP client with revolutionary RSA-SHA2 compatibility fixes. Zero native dependencies, built on ssh2-streams with 100% SSH key support.
27 lines • 755 B
JavaScript
;
/**
* ASN.1 Encoding Utilities
* Shared utilities for ASN.1 DER encoding operations
*/
Object.defineProperty(exports, "__esModule", { value: true });
exports.encodeLength = encodeLength;
/**
* Encode ASN.1 length field according to DER rules
* @param length The length value to encode
* @returns Buffer containing the encoded length
*/
function encodeLength(length) {
if (length <= 127) {
return Buffer.from([length]);
}
else {
const lengthBytes = [];
let len = length;
while (len > 0) {
lengthBytes.unshift(len & 0xff);
len = len >> 8;
}
return Buffer.from([0x80 | lengthBytes.length, ...lengthBytes]);
}
}
//# sourceMappingURL=asn1-utils.js.map