asn1-ts
Version:
ASN.1 encoding and decoding, including BER, CER, and DER.
25 lines (24 loc) • 801 B
JavaScript
import * as errors from "../../../errors.mjs";
export default function decodeRelativeObjectIdentifier(value) {
if (value.length === 0) {
return [];
}
if (value.length > 1 && value[value.length - 1] & 0b10000000) {
throw new errors.ASN1TruncationError("Relative OID was truncated.");
}
const nodes = [];
let current_node = 0;
for (let i = 0; i < value.length; i++) {
const byte = value[i];
if ((byte === 0x80) && (current_node === 0)) {
throw new errors.ASN1PaddingError("Prohibited padding on RELATIVE-OID node.");
}
current_node <<= 7;
current_node += (byte & 127);
if ((byte & 128) === 0) {
nodes.push(current_node);
current_node = 0;
}
}
return nodes;
}