|
| 1 | +package algorithms |
| 2 | + |
| 3 | +import dev.whyoleg.cryptography.* |
| 4 | +import dev.whyoleg.cryptography.materials.key.* |
| 5 | +import kotlin.jvm.* |
| 6 | + |
| 7 | +@SubclassOptInRequired(CryptographyProviderApi::class) |
| 8 | +public interface Ed<PublicK : Ed.PublicKey, PrivateK : Ed.PrivateKey, KP : Ed.KeyPair<PublicK, PrivateK>> : CryptographyAlgorithm { |
| 9 | + public fun publicKeyDecoder(curve: Curve): KeyDecoder<PublicKey.Format, PublicK> |
| 10 | + public fun privateKeyDecoder(curve: Curve): KeyDecoder<PrivateKey.Format, PrivateK> |
| 11 | + public fun keyPairGenerator(curve: Curve): KeyGenerator<KP> |
| 12 | + |
| 13 | + @JvmInline |
| 14 | + public value class Curve(public val name: String) { |
| 15 | + public companion object { |
| 16 | + public val Ed25519: Curve get() = Curve("Ed25519") |
| 17 | + public val X25519: Curve get() = Curve("X25519") |
| 18 | + |
| 19 | + public val Ed448: Curve get() = Curve("Ed448") |
| 20 | + public val X448: Curve get() = Curve("X448") |
| 21 | + } |
| 22 | + } |
| 23 | + |
| 24 | + // Similar key interfaces but with Edwards-specific formats |
| 25 | + @SubclassOptInRequired(CryptographyProviderApi::class) |
| 26 | + public interface KeyPair<PublicK : PublicKey, PrivateK : PrivateKey> : Key { |
| 27 | + public val publicKey: PublicK |
| 28 | + public val privateKey: PrivateK |
| 29 | + } |
| 30 | + |
| 31 | + @SubclassOptInRequired(CryptographyProviderApi::class) |
| 32 | + public interface PublicKey : EncodableKey<PublicKey.Format> { |
| 33 | + public sealed class Format : KeyFormat { |
| 34 | + final override fun toString(): String = name |
| 35 | + |
| 36 | + public data object JWK : Format() { |
| 37 | + override val name: String get() = "JWK" |
| 38 | + } |
| 39 | + |
| 40 | + public data object RAW : Format() { |
| 41 | + override val name: String get() = "RAW" |
| 42 | + } |
| 43 | + |
| 44 | + public data object DER : Format() { |
| 45 | + override val name: String get() = "DER" |
| 46 | + } |
| 47 | + |
| 48 | + public data object PEM : Format() { |
| 49 | + override val name: String get() = "PEM" |
| 50 | + } |
| 51 | + } |
| 52 | + } |
| 53 | + |
| 54 | + @SubclassOptInRequired(CryptographyProviderApi::class) |
| 55 | + public interface PrivateKey : EncodableKey<PrivateKey.Format> { |
| 56 | + public sealed class Format : KeyFormat { |
| 57 | + final override fun toString(): String = name |
| 58 | + |
| 59 | + public data object JWK : Format() { |
| 60 | + override val name: String get() = "JWK" |
| 61 | + } |
| 62 | + |
| 63 | + public data object RAW : Format() { |
| 64 | + override val name: String get() = "RAW" |
| 65 | + } |
| 66 | + |
| 67 | + public data object DER : Format() { |
| 68 | + override val name: String get() = "DER" |
| 69 | + } |
| 70 | + |
| 71 | + public data object PEM : Format() { |
| 72 | + override val name: String get() = "PEM" |
| 73 | + } |
| 74 | + } |
| 75 | + } |
| 76 | +} |
0 commit comments