-
Notifications
You must be signed in to change notification settings - Fork 12
Proper ASN.1 Tagging #117
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Proper ASN.1 Tagging #117
Conversation
indispensable/src/commonMain/kotlin/at/asitplus/signum/indispensable/CryptoPublicKey.kt
Show resolved
Hide resolved
indispensable/src/commonMain/kotlin/at/asitplus/signum/indispensable/X509SignatureAlgorithm.kt
Show resolved
Hide resolved
indispensable/src/commonMain/kotlin/at/asitplus/signum/indispensable/asn1/Asn1BitString.kt
Show resolved
Hide resolved
indispensable/src/commonMain/kotlin/at/asitplus/signum/indispensable/asn1/Asn1Encoding.kt
Show resolved
Hide resolved
indispensable/src/commonMain/kotlin/at/asitplus/signum/indispensable/asn1/Asn1String.kt
Show resolved
Hide resolved
indispensable/src/commonMain/kotlin/at/asitplus/signum/indispensable/asn1/BERTags.kt
Show resolved
Hide resolved
indispensable/src/commonMain/kotlin/at/asitplus/signum/indispensable/asn1/BERTags.kt
Outdated
Show resolved
Hide resolved
indispensable/src/jvmTest/kotlin/at/asitplus/signum/indispensable/Asn1EncodingTest.kt
Outdated
Show resolved
Hide resolved
indispensable/src/commonMain/kotlin/at/asitplus/signum/indispensable/CryptoPublicKey.kt
Show resolved
Hide resolved
indispensable/src/commonMain/kotlin/at/asitplus/signum/indispensable/X509SignatureAlgorithm.kt
Outdated
Show resolved
Hide resolved
indispensable/src/commonMain/kotlin/at/asitplus/signum/indispensable/asn1/Asn1Encodable.kt
Outdated
Show resolved
Hide resolved
indispensable/src/commonMain/kotlin/at/asitplus/signum/indispensable/asn1/Asn1Encoding.kt
Outdated
Show resolved
Hide resolved
indispensable/src/commonMain/kotlin/at/asitplus/signum/indispensable/asn1/Asn1Encoding.kt
Outdated
Show resolved
Hide resolved
indispensable/src/commonMain/kotlin/at/asitplus/signum/indispensable/pki/X509Certificate.kt
Show resolved
Hide resolved
indispensable/src/jvmTest/kotlin/at/asitplus/signum/indispensable/TagEncodingTest.kt
Show resolved
Hide resolved
indispensable/src/jvmTest/kotlin/at/asitplus/signum/indispensable/OidTest.kt
Show resolved
Hide resolved
indispensable/src/commonMain/kotlin/at/asitplus/signum/indispensable/asn1/Asn1Elements.kt
Outdated
Show resolved
Hide resolved
indispensable/src/commonMain/kotlin/at/asitplus/signum/indispensable/asn1/Asn1Elements.kt
Show resolved
Hide resolved
|
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 |
@iaik-jheher i thought you fixed it? |
a59ff40 to
e6fe92b
Compare
|
|
was varint decoding bug. fixed now |
…nsable/asn1/Asn1Elements.kt Co-authored-by: Jakob Heher <[email protected]>
2d52fc2 to
ea4b1e3
Compare
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 |
ea4b1e3 to
885c2d4
Compare
* Completely revamped ASN.1 Tag Handling
* Properly handle multi-byte tags
* Introduce a new data structure `TLV.Tag` with an accompanying `TagClass` enum and a `constructed` flag to accurately represent arbitrary tags up to `ULong.MAX_VALUE`
* Make all `tag` parameters `ULong` to reflect support for multi-byte tags
* Remove `DERTags`
* Revamp implicit tagging (there is still work to be done, but at least it supports CONSTRUCTED ASN.1 elements)
* Refactor `Int.Companion.decodeFromDer()` -> `Int.Companion.decodeFromDerValue()`
* Refactor `Long.Companion.decodeFromDer()` -> `Long.Companion.decodeFromDerValue()`
* Introduce `ULong.toAsn1VarInt()` to encode ULongs into ASN.1 unsigned VarInts (**not to be confused with
multi^2_base's`UVarInt`!**)
* Introduce `decodeAsn1VarULong()` and `decodeAsn1VarUInt()` which can handle overlong inputs, as long as they start with a valid unsigned number encoding.
* Comes in three ULong flavours:
* `Iterator<Byte>.decodeAsn1VarULong()`
* `Iterable<Byte>.decodeAsn1VarULong()`
* `ByteArray.decodeAsn1VarULong()`
* and three UInt flavours:
* `Iterator<Byte>.decodeAsn1VarUInt()`
* `Iterable<Byte>.decodeAsn1VarUInt()`
* `ByteArray.decodeAsn1VarUInt()`
* Completely revamped ASN.1 Tag Handling
* Properly handle multi-byte tags
* Introduce a new data structure `TLV.Tag` with an accompanying `TagClass` enum and a `constructed` flag to accurately represent arbitrary tags up to `ULong.MAX_VALUE`
* Make all `tag` parameters `ULong` to reflect support for multi-byte tags
* Remove `DERTags`
* Revamp implicit tagging (there is still work to be done, but at least it supports CONSTRUCTED ASN.1 elements)
* Refactor `Int.Companion.decodeFromDer()` -> `Int.Companion.decodeFromDerValue()`
* Refactor `Long.Companion.decodeFromDer()` -> `Long.Companion.decodeFromDerValue()`
* Introduce `ULong.toAsn1VarInt()` to encode ULongs into ASN.1 unsigned VarInts (**not to be confused with
multi^2_base's`UVarInt`!**)
* Introduce `decodeAsn1VarULong()` and `decodeAsn1VarUInt()` which can handle overlong inputs, as long as they start with a valid unsigned number encoding.
* Comes in three ULong flavours:
* `Iterator<Byte>.decodeAsn1VarULong()`
* `Iterable<Byte>.decodeAsn1VarULong()`
* `ByteArray.decodeAsn1VarULong()`
* and three UInt flavours:
* `Iterator<Byte>.decodeAsn1VarUInt()`
* `Iterable<Byte>.decodeAsn1VarUInt()`
* `ByteArray.decodeAsn1VarUInt()`
* Completely revamped ASN.1 Tag Handling
* Properly handle multi-byte tags
* Introduce a new data structure `TLV.Tag` with an accompanying `TagClass` enum and a `constructed` flag to accurately represent arbitrary tags up to `ULong.MAX_VALUE`
* Make all `tag` parameters `ULong` to reflect support for multi-byte tags
* Remove `DERTags`
* Revamp implicit tagging (there is still work to be done, but at least it supports CONSTRUCTED ASN.1 elements)
* Refactor `Int.Companion.decodeFromDer()` -> `Int.Companion.decodeFromDerValue()`
* Refactor `Long.Companion.decodeFromDer()` -> `Long.Companion.decodeFromDerValue()`
* Introduce `ULong.toAsn1VarInt()` to encode ULongs into ASN.1 unsigned VarInts (**not to be confused with
multi^2_base's`UVarInt`!**)
* Introduce `decodeAsn1VarULong()` and `decodeAsn1VarUInt()` which can handle overlong inputs, as long as they start with a valid unsigned number encoding.
* Comes in three ULong flavours:
* `Iterator<Byte>.decodeAsn1VarULong()`
* `Iterable<Byte>.decodeAsn1VarULong()`
* `ByteArray.decodeAsn1VarULong()`
* and three UInt flavours:
* `Iterator<Byte>.decodeAsn1VarUInt()`
* `Iterable<Byte>.decodeAsn1VarUInt()`
* `ByteArray.decodeAsn1VarUInt()`
TLV.Tagwith an accompanyingTagClassenum and aconstructedflag to accurately represent arbitrary tags up toULong.MAX_VALUEtagparametersULongto reflect support for multi-byte tagsDERTagsInt.Companion.decodeFromDer()->Int.Companion.decodeFromDerValue()Long.Companion.decodeFromDer()->Long.Companion.decodeFromDerValue()ULong.toAsn1VarInt()to encode ULongs into ASN.1 unsigned VarInts (not to be confused withmulti^2_base's
UVarInt!)decodeAsn1VarULong()anddecodeAsn1VarUInt()which can handle overlong inputs, as long as they start with a valid unsigned number encoding.Iterator<Byte>.decodeAsn1VarULong()Iterable<Byte>.decodeAsn1VarULong()ByteArray.decodeAsn1VarULong()Iterator<Byte>.decodeAsn1VarUInt()Iterable<Byte>.decodeAsn1VarUInt()ByteArray.decodeAsn1VarUInt()