a-sit-plus / signum

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

Proper ASN.1 Tagging #117

Closed JesusMcCloud closed 1 day ago

JesusMcCloud commented 6 days ago
nodh commented 6 days ago

This encoding test fails for me:

"fails" {
        val it = 2204309167L
        val bytes = (it).toTwosComplementByteArray()
        val fromBC = ASN1Integer(it).encoded
        val long = Long.decodeFromDerValue(bytes)
        val encoded = Asn1Primitive(Asn1Element.Tag.INT, bytes).derEncoded
        encoded shouldBe fromBC
        long shouldBe it
    }

with

Expected :[2, 5, 0, -125, 99, 22, -81]
Actual   :[2, 6, 0, 0, -125, 99, 22, -81]
JesusMcCloud commented 6 days ago

This encoding test fails for me:

"fails" {
        val it = 2204309167L
        val bytes = (it).toTwosComplementByteArray()
        val fromBC = ASN1Integer(it).encoded
        val long = Long.decodeFromDerValue(bytes)
        val encoded = Asn1Primitive(Asn1Element.Tag.INT, bytes).derEncoded
        encoded shouldBe fromBC
        long shouldBe it
    }

with

Expected :[2, 5, 0, -125, 99, 22, -81]
Actual   :[2, 6, 0, 0, -125, 99, 22, -81]

@iaik-jheher i thought you fixed it?

JesusMcCloud commented 1 day ago

decodeTag is broken!. encoding works perfectly fine though, so debugging should be easy

JesusMcCloud commented 1 day ago

decodeTag is broken!. encoding works perfectly fine though, so debugging should be easy

was varint decoding bug. fixed now

iaik-jheher commented 1 day ago

decodeTag is broken!. encoding works perfectly fine though, so debugging should be easy

was varint decoding bug. fixed now

did you add a test case that covers this, since it was not caught before?

JesusMcCloud commented 1 day ago

decodeTag is broken!. encoding works perfectly fine though, so debugging should be easy

was varint decoding bug. fixed now

did you add a test case that covers this, since it was not caught before?

totally forgot do test for trainlign bytes. now there's a testcase for longs and ints and both caught the error