File tree Expand file tree Collapse file tree 4 files changed +36
-7
lines changed
cryptography-serialization/asn1
modules/src/commonMain/kotlin
src/commonMain/kotlin/internal Expand file tree Collapse file tree 4 files changed +36
-7
lines changed Original file line number Diff line number Diff line change @@ -45,9 +45,18 @@ public abstract class AlgorithmIdentifierSerializer<AI : AlgorithmIdentifier> :
4545 index = 0 ,
4646 deserializer = ObjectIdentifier .serializer()
4747 )
48- check(decodeElementIndex(descriptor) == 1 )
49- val parameters = decodeParameters(algorithm)
50- check(decodeElementIndex(descriptor) == CompositeDecoder .DECODE_DONE )
51- parameters
48+ when (val idx = decodeElementIndex(descriptor)) {
49+ 1 -> {
50+ val parameters = decodeParameters(algorithm)
51+ check(decodeElementIndex(descriptor) == CompositeDecoder .DECODE_DONE )
52+ parameters
53+ }
54+ CompositeDecoder .DECODE_DONE -> {
55+ // Some algorithms (e.g., Ed25519/Ed448/X25519/X448 per RFC 8410) omit parameters.
56+ // Delegate to subclass to construct an identifier without consuming parameters from the stream.
57+ decodeParameters(algorithm)
58+ }
59+ else -> error(" Unexpected element index: $idx " )
60+ }
5261 }
53- }
62+ }
Original file line number Diff line number Diff line change @@ -26,8 +26,9 @@ internal object KeyAlgorithmIdentifierSerializer : AlgorithmIdentifierSerializer
2626 }
2727 ObjectIdentifier .EC -> EcKeyAlgorithmIdentifier (decodeParameters(EcParameters .serializer()))
2828 else -> {
29- // TODO: somehow we should ignore parameters here
29+ // For algorithms like Ed25519/Ed448/X25519/X448 (RFC 8410), parameters are absent.
30+ // Do not attempt to read parameters when the element is omitted; just construct the identifier.
3031 UnknownKeyAlgorithmIdentifier (algorithm)
3132 }
3233 }
33- }
34+ }
Original file line number Diff line number Diff line change 1+ /*
2+ * Copyright (c) 2025 Oleg Yukhnevich. Use of this source code is governed by the Apache 2.0 license.
3+ */
4+
5+ package dev.whyoleg.cryptography.serialization.asn1.modules
6+
7+ import dev.whyoleg.cryptography.serialization.asn1.ObjectIdentifier
8+
9+ public object EdwardsOids {
10+ public val Ed25519 : ObjectIdentifier = ObjectIdentifier (" 1.3.101.112" )
11+ public val Ed448 : ObjectIdentifier = ObjectIdentifier (" 1.3.101.113" )
12+ }
13+
14+ public object MontgomeryOids {
15+ public val X25519 : ObjectIdentifier = ObjectIdentifier (" 1.3.101.110" )
16+ public val X448 : ObjectIdentifier = ObjectIdentifier (" 1.3.101.111" )
17+ }
18+
Original file line number Diff line number Diff line change @@ -36,6 +36,7 @@ internal class DerDecoder(
3636
3737 while (true ) {
3838 val index = currentIndex
39+ if (index >= descriptor.elementsCount) return CompositeDecoder .DECODE_DONE
3940 tagOverride = descriptor.getElementContextSpecificTag(index)
4041
4142 if (descriptor.isElementOptional(index)) {
You can’t perform that action at this time.
0 commit comments