@@ -12,7 +12,7 @@ import dev.whyoleg.cryptography.providers.base.*
1212import dev.whyoleg.cryptography.providers.base.algorithms.*
1313import dev.whyoleg.cryptography.providers.base.materials.*
1414import dev.whyoleg.cryptography.providers.cryptokit.internal.*
15- import dev.whyoleg.cryptography.providers.cryptokit.internal.swiftinterop .*
15+ import dev.whyoleg.cryptography.providers.cryptokit.internal.swift.DwcCryptoKitInterop .*
1616import dev.whyoleg.cryptography.providers.cryptokit.operations.*
1717import dev.whyoleg.cryptography.serialization.pem.*
1818import kotlinx.cinterop.*
@@ -33,10 +33,10 @@ internal object CryptoKitEcdsa : ECDSA {
3333 }
3434
3535 private class KeyPairGenerator (
36- private val curve : SwiftEcCurve ,
36+ private val curve : DwcEcCurve ,
3737 ) : KeyGenerator<ECDSA.KeyPair> {
3838 override fun generateKeyBlocking (): ECDSA .KeyPair {
39- val privateKey = SwiftEcdsaPrivateKey .generateWithCurve(curve)
39+ val privateKey = DwcEcdsaPrivateKey .generateWithCurve(curve)
4040 return EcdsaKeyPair (
4141 privateKey = EcdsaPrivateKey (privateKey),
4242 publicKey = EcdsaPublicKey (privateKey.publicKey())
@@ -45,40 +45,46 @@ internal object CryptoKitEcdsa : ECDSA {
4545 }
4646
4747 private class PublicKeyDecoder (
48- private val curve : SwiftEcCurve ,
48+ private val curve : DwcEcCurve ,
4949 ) : KeyDecoder<EC.PublicKey.Format, ECDSA.PublicKey> {
5050 override fun decodeFromByteArrayBlocking (format : EC .PublicKey .Format , bytes : ByteArray ): ECDSA .PublicKey {
5151 return EcdsaPublicKey (swiftTry { error ->
5252 when (format) {
5353 EC .PublicKey .Format .JWK -> error(" JWK is not supported" )
54- EC .PublicKey .Format .RAW -> bytes.useNSData { SwiftEcdsaPublicKey .decodeRawWithCurve(curve, it, error) }
55- EC .PublicKey .Format .RAW .Compressed -> bytes.useNSData { SwiftEcdsaPublicKey .decodeRawCompressedWithCurve(curve, it, error) }
56- EC .PublicKey .Format .DER -> bytes.useNSData { SwiftEcdsaPublicKey .decodeDerWithCurve(curve, it, error) }
57- EC .PublicKey .Format .PEM -> SwiftEcdsaPublicKey .decodePemWithCurve(curve, bytes.decodeToString(), error)
54+ EC .PublicKey .Format .RAW -> bytes.useNSData { DwcEcdsaPublicKey .decodeRawWithCurve(curve, it, error) }
55+ EC .PublicKey .Format .RAW .Compressed -> bytes.useNSData {
56+ DwcEcdsaPublicKey .decodeRawCompressedWithCurve(
57+ curve,
58+ it,
59+ error
60+ )
61+ }
62+ EC .PublicKey .Format .DER -> bytes.useNSData { DwcEcdsaPublicKey .decodeDerWithCurve(curve, it, error) }
63+ EC .PublicKey .Format .PEM -> DwcEcdsaPublicKey .decodePemWithCurve(curve, bytes.decodeToString(), error)
5864 }
5965 })
6066 }
6167 }
6268
6369 private class PrivateKeyDecoder (
64- private val curve : SwiftEcCurve ,
70+ private val curve : DwcEcCurve ,
6571 ) : KeyDecoder<EC.PrivateKey.Format, ECDSA.PrivateKey> {
6672 override fun decodeFromByteArrayBlocking (format : EC .PrivateKey .Format , bytes : ByteArray ): ECDSA .PrivateKey {
6773 return EcdsaPrivateKey (swiftTry { error ->
6874 when (format) {
6975 EC .PrivateKey .Format .JWK -> error(" JWK is not supported" )
70- EC .PrivateKey .Format .RAW -> bytes.useNSData { SwiftEcdsaPrivateKey .decodeRawWithCurve(curve, it, error) }
76+ EC .PrivateKey .Format .RAW -> bytes.useNSData { DwcEcdsaPrivateKey .decodeRawWithCurve(curve, it, error) }
7177 EC .PrivateKey .Format .DER -> decodeFromDer(bytes, error)
7278 EC .PrivateKey .Format .DER .SEC1 -> decodeFromDer(convertEcPrivateKeyFromSec1ToPkcs8(bytes), error)
7379 EC .PrivateKey .Format .PEM ,
7480 EC .PrivateKey .Format .PEM .SEC1 ,
75- -> SwiftEcdsaPrivateKey .decodePemWithCurve(curve, bytes.decodeToString(), error)
81+ -> DwcEcdsaPrivateKey .decodePemWithCurve(curve, bytes.decodeToString(), error)
7682 }
7783 })
7884 }
7985
80- private fun decodeFromDer (bytes : ByteArray , error : SwiftErrorPointer ): SwiftEcdsaPrivateKey ? {
81- return bytes.useNSData { SwiftEcdsaPrivateKey .decodeDerWithCurve(curve, it, error) }
86+ private fun decodeFromDer (bytes : ByteArray , error : DwcErrorPointer ): DwcEcdsaPrivateKey ? {
87+ return bytes.useNSData { DwcEcdsaPrivateKey .decodeDerWithCurve(curve, it, error) }
8288 }
8389 }
8490}
@@ -90,7 +96,7 @@ private class EcdsaKeyPair(
9096
9197@OptIn(UnsafeNumber ::class )
9298private class EcdsaPublicKey (
93- private val publicKey : SwiftEcdsaPublicKey ,
99+ private val publicKey : DwcEcdsaPublicKey ,
94100) : ECDSA.PublicKey {
95101 override fun encodeToByteArrayBlocking (format : EC .PublicKey .Format ): ByteArray = when (format) {
96102 EC .PublicKey .Format .JWK -> error(" JWK is not supported" )
@@ -112,7 +118,7 @@ private class EcdsaPublicKey(
112118
113119@OptIn(UnsafeNumber ::class )
114120private class EcdsaPrivateKey (
115- private val privateKey : SwiftEcdsaPrivateKey ,
121+ private val privateKey : DwcEcdsaPrivateKey ,
116122) : ECDSA.PrivateKey {
117123 override fun encodeToByteArrayBlocking (format : EC .PrivateKey .Format ): ByteArray = when (format) {
118124 EC .PrivateKey .Format .JWK -> error(" JWK is not supported" )
@@ -138,26 +144,26 @@ private class EcdsaPrivateKey(
138144
139145@OptIn(UnsafeNumber ::class )
140146private class EcdsaSignatureGenerator (
141- private val algorithm : SwiftHashAlgorithm ,
142- private val privateKey : SwiftEcdsaPrivateKey ,
147+ private val algorithm : DwcHashAlgorithm ,
148+ private val privateKey : DwcEcdsaPrivateKey ,
143149 private val format : ECDSA .SignatureFormat ,
144150) : SignatureGenerator {
145151 override fun createSignFunction (): SignFunction = EcdsaSignFunction (algorithm, privateKey, format)
146152}
147153
148154@OptIn(UnsafeNumber ::class )
149155private class EcdsaSignatureVerifier (
150- private val algorithm : SwiftHashAlgorithm ,
151- private val publicKey : SwiftEcdsaPublicKey ,
156+ private val algorithm : DwcHashAlgorithm ,
157+ private val publicKey : DwcEcdsaPublicKey ,
152158 private val format : ECDSA .SignatureFormat ,
153159) : SignatureVerifier {
154160 override fun createVerifyFunction (): VerifyFunction = EcdsaVerifyFunction (algorithm, publicKey, format)
155161}
156162
157163@OptIn(UnsafeNumber ::class )
158164private class EcdsaSignFunction (
159- algorithm : SwiftHashAlgorithm ,
160- private val privateKey : SwiftEcdsaPrivateKey ,
165+ algorithm : DwcHashAlgorithm ,
166+ private val privateKey : DwcEcdsaPrivateKey ,
161167 private val format : ECDSA .SignatureFormat ,
162168) : HashBasedFunction(algorithm), SignFunction {
163169 override fun signIntoByteArray (destination : ByteArray , destinationOffset : Int ): Int {
@@ -182,8 +188,8 @@ private class EcdsaSignFunction(
182188
183189@OptIn(UnsafeNumber ::class )
184190private class EcdsaVerifyFunction (
185- algorithm : SwiftHashAlgorithm ,
186- private val publicKey : SwiftEcdsaPublicKey ,
191+ algorithm : DwcHashAlgorithm ,
192+ private val publicKey : DwcEcdsaPublicKey ,
187193 private val format : ECDSA .SignatureFormat ,
188194) : HashBasedFunction(algorithm), VerifyFunction {
189195 override fun tryVerify (signature : ByteArray , startIndex : Int , endIndex : Int ): Boolean {
0 commit comments