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> :
45
45
index = 0 ,
46
46
deserializer = ObjectIdentifier .serializer()
47
47
)
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
+ }
52
61
}
53
- }
62
+ }
Original file line number Diff line number Diff line change @@ -26,8 +26,9 @@ internal object KeyAlgorithmIdentifierSerializer : AlgorithmIdentifierSerializer
26
26
}
27
27
ObjectIdentifier .EC -> EcKeyAlgorithmIdentifier (decodeParameters(EcParameters .serializer()))
28
28
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.
30
31
UnknownKeyAlgorithmIdentifier (algorithm)
31
32
}
32
33
}
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(
36
36
37
37
while (true ) {
38
38
val index = currentIndex
39
+ if (index >= descriptor.elementsCount) return CompositeDecoder .DECODE_DONE
39
40
tagOverride = descriptor.getElementContextSpecificTag(index)
40
41
41
42
if (descriptor.isElementOptional(index)) {
You can’t perform that action at this time.
0 commit comments