in src/asn1.ts [282:312]
function decodeSequence(sequence: Buffer) {
const { tag } = decodeIdentifier(sequence[0]);
if (tag !== Asn1Tag.Sequence) {
throw new Asn1DecodingError(
`Expected a sequence to decode, but got tag ${tag}`
);
}
const { firstByteOffset, lastByteOffset } = decodeLengthValue(
sequence.slice(1)
);
const sequenceValue = sequence.slice(
1 + firstByteOffset,
1 + 1 + lastByteOffset
);
const parts: ILV[] = [];
let offset = 0;
while (offset < sequenceValue.length) {
// Silence false postive: accessing an octet in a Buffer at a particular index
// is to be done with index operator: [index]
// eslint-disable-next-line security/detect-object-injection
const identifier = decodeIdentifier(sequenceValue[offset]);
const next = decodeLengthValue(sequenceValue.slice(offset + 1));
const value = sequenceValue.slice(
offset + 1 + next.firstByteOffset,
offset + 1 + next.lastByteOffset
);
parts.push({ identifier, length: next.length, value });
offset += 1 + next.lastByteOffset;
}
return parts;
}