a-sit-plus / signum

Kotlin Multiplatform Crypto/PKI Library and ASN1 Parser + Encoder
https://a-sit-plus.github.io/signum/
Apache License 2.0
76 stars 6 forks source link

ASN.1: Parser API changes #121

Closed JesusMcCloud closed 2 months ago

JesusMcCloud commented 2 months ago

Currently, the parser is eager to consume all bytes, when trying to parse an ASN.1 Structure. This makes little sense, because only a single toplevel structure is allowed. If, for example, some input (which can be perfectly legal in a couple of use cases) starts with a valid ASN.1 structure, followed by other data (possibly even additional valid ASN.1 structures), parsing will fail.

Hence, the toplevel Asn1Element.parse and Asn1Element.decodeFromDerHexString should only try to parse the very first ASN.1 Structure and also return all non-parsed trailing bytes.