-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(x25519): add x25519 implementation for ios, macos (#80)
- Loading branch information
1 parent
a25798c
commit c18c0eb
Showing
3 changed files
with
33 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
29 changes: 27 additions & 2 deletions
29
...ric-encryption/src/iosMain/kotlin/io/iohk/atala/prism/apollo/utils/KMMX25519PrivateKey.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,32 @@ | ||
package io.iohk.atala.prism.apollo.utils | ||
|
||
import cocoapods.IOHKCryptoKit.X25519 | ||
import kotlinx.cinterop.ObjCObjectVar | ||
import kotlinx.cinterop.alloc | ||
import kotlinx.cinterop.memScoped | ||
import kotlinx.cinterop.ptr | ||
import kotlinx.cinterop.value | ||
import platform.Foundation.NSError | ||
|
||
actual class KMMX25519PrivateKey { | ||
init { | ||
throw NotImplementedError("X25519 is yet to be implemented in iOS") | ||
public val raw: ByteArray | ||
|
||
constructor(raw: ByteArray) { | ||
this.raw = raw | ||
} | ||
|
||
constructor() { | ||
this.raw = X25519.createPrivateKey().toByteArray() | ||
} | ||
|
||
@Throws(RuntimeException::class) | ||
public fun publicKey(): KMMX25519PublicKey { | ||
memScoped { | ||
val errorRef = alloc<ObjCObjectVar<NSError?>>() | ||
val result = X25519.publicKeyWithPrivateKey(raw.toNSData(), errorRef.ptr) | ||
errorRef.value?.let { throw RuntimeException(it.localizedDescription()) } | ||
val publicRaw = result?.toByteArray() ?: throw RuntimeException("Null result") | ||
return KMMX25519PublicKey(publicRaw) | ||
} | ||
} | ||
} |
6 changes: 4 additions & 2 deletions
6
...tric-encryption/src/iosMain/kotlin/io/iohk/atala/prism/apollo/utils/KMMX25519PublicKey.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,9 @@ | ||
package io.iohk.atala.prism.apollo.utils | ||
|
||
actual class KMMX25519PublicKey { | ||
init { | ||
throw NotImplementedError("X25519 is yet to be implemented in iOS") | ||
public val raw: ByteArray | ||
|
||
constructor(raw: ByteArray) { | ||
this.raw = raw | ||
} | ||
} |