Calling toString and toJSON on a SET_OFASN1Element that is not uniquely tagged throws ASN1ConstructionError, after the introduction of uniqueness checking for SET introduced in v7.0.6.
Calling setOf, instead of set, could be one way of solving the issue, as both SET and SET_OF have the same signature.
get set (): SET<ASN1Element> {
const ret = this.sequence;
if (!isUniquelyTagged(ret)) {
throw new errors.ASN1ConstructionError("Duplicate tag in SET.", this);
}
return ret;
}
source/asn1.ts
// toString()
switch (this.tagNumber) {
case (ASN1UniversalType.set): return ("{ " + this.set // <-- this could be a SET_OF, with might not be uniquely tagged
.map((el) => (el.name.length ? `${el.name} ${el.toString()}` : el.toString()))
.join(" , ") + " }");
}
source/asn1.ts
// toJSON()
switch (this.tagNumber) {
case (ASN1UniversalType.set): { // <-- this could be a SET_OF, with might not be uniquely tagged
if (!recurse) {
return null;
}
return this.set.map((el) => el.toJSON());
}
}
I fixed this just now. I released version 7.0.18, which fixes both this bug and #20 . Thank you so much for your very thoughtful issue reporting and PR!
7.0.6
Calling
toString
andtoJSON
on aSET_OF
ASN1Element
that is not uniquely tagged throwsASN1ConstructionError
, after the introduction of uniqueness checking forSET
introduced inv7.0.6
.Calling
setOf
, instead ofcould be one way of solving the issue, as bothset
,SET
andSET_OF
have the same signature.source/codecs/ber.ts
,source/codecs/cer.ts
,source/codecs/der.ts
:source/asn1.ts
source/asn1.ts