JonathanWilbur / asn1-ts

ASN.1 TypeScript library, including codecs for Basic Encoding Rules (BER) and Distinguished Encoding Rules (DER).
MIT License
32 stars 6 forks source link

Broken validateConstruction function on 7.0.4 #20

Closed dicksonhk closed 1 year ago

dicksonhk commented 1 year ago

continue, instead of return, should be used for flow control

// specification.forEach((spec: ConstructedElementSpecification): void => { // <-- 7.0.3
for (const spec of specification) { // <-- 7.0.4
    if (
        (i >= elements.length)
        || (spec.tagClass && spec.tagClass !== elements[i].tagClass)
        || (spec.construction && spec.construction !== elements[i].construction)
        || (spec.tagNumber && spec.tagNumber !== elements[i].tagNumber)
    ) {
        if (!spec.optional) {
            throw new errors.ASN1ConstructionError(`Missing required element '${spec.name}'.`);
        }
        // return; // <-- this return statement "breaks out" of the loop, ending the whole function early
        continue;
    }
    // ...
}

P.S.

The validateConstruction function was working just fine up until 7.0.3.

I understand it is now deprecated, but I had been using it for validation and decode.