diff --git a/crypter-ffi/src/crypter.swift b/crypter-ffi/src/crypter.swift index 59ecdc0..a7fbd98 100644 --- a/crypter-ffi/src/crypter.swift +++ b/crypter-ffi/src/crypter.swift @@ -19,13 +19,13 @@ fileprivate extension RustBuffer { } static func from(_ ptr: UnsafeBufferPointer) -> RustBuffer { - try! rustCall { ffi_crypter_a934_rustbuffer_from_bytes(ForeignBytes(bufferPointer: ptr), $0) } + try! rustCall { ffi_crypter_9c38_rustbuffer_from_bytes(ForeignBytes(bufferPointer: ptr), $0) } } // Frees the buffer in place. // The buffer must not be used after this is called. func deallocate() { - try! rustCall { ffi_crypter_a934_rustbuffer_free(self, $0) } + try! rustCall { ffi_crypter_9c38_rustbuffer_free(self, $0) } } } @@ -438,13 +438,27 @@ extension CrypterError: Equatable, Hashable {} extension CrypterError: Error { } +public func pubkeyFromSecretKey(mySecretKey: String) throws -> String { + return try FfiConverterString.lift( + try + + rustCallWithError(FfiConverterTypeCrypterError.self) { + + crypter_9c38_pubkey_from_secret_key( + FfiConverterString.lower(mySecretKey), $0) +} + ) +} + + + public func deriveSharedSecret(theirPubkey: String, mySecretKey: String) throws -> String { return try FfiConverterString.lift( try rustCallWithError(FfiConverterTypeCrypterError.self) { - crypter_a934_derive_shared_secret( + crypter_9c38_derive_shared_secret( FfiConverterString.lower(theirPubkey), FfiConverterString.lower(mySecretKey), $0) } @@ -459,7 +473,7 @@ public func encrypt(plaintext: String, secret: String, nonce: String) throws -> rustCallWithError(FfiConverterTypeCrypterError.self) { - crypter_a934_encrypt( + crypter_9c38_encrypt( FfiConverterString.lower(plaintext), FfiConverterString.lower(secret), FfiConverterString.lower(nonce), $0) @@ -475,7 +489,7 @@ public func decrypt(ciphertext: String, secret: String) throws -> String { rustCallWithError(FfiConverterTypeCrypterError.self) { - crypter_a934_decrypt( + crypter_9c38_decrypt( FfiConverterString.lower(ciphertext), FfiConverterString.lower(secret), $0) } diff --git a/crypter-ffi/src/crypter.udl b/crypter-ffi/src/crypter.udl index ecabcf8..ee14321 100644 --- a/crypter-ffi/src/crypter.udl +++ b/crypter-ffi/src/crypter.udl @@ -11,6 +11,8 @@ enum CrypterError { }; namespace crypter { + [Throws=CrypterError] + string pubkey_from_secret_key(string my_secret_key); [Throws=CrypterError] string derive_shared_secret(string their_pubkey, string my_secret_key); [Throws=CrypterError] diff --git a/crypter-ffi/src/crypterFFI.h b/crypter-ffi/src/crypterFFI.h index f39a13a..4cc0138 100644 --- a/crypter-ffi/src/crypterFFI.h +++ b/crypter-ffi/src/crypterFFI.h @@ -46,31 +46,35 @@ typedef struct RustCallStatus { // ⚠️ increment the version suffix in all instances of UNIFFI_SHARED_HEADER_V4 in this file. ⚠️ #endif // def UNIFFI_SHARED_H -RustBuffer crypter_a934_derive_shared_secret( +RustBuffer crypter_9c38_pubkey_from_secret_key( + RustBuffer my_secret_key, + RustCallStatus *_Nonnull out_status + ); +RustBuffer crypter_9c38_derive_shared_secret( RustBuffer their_pubkey,RustBuffer my_secret_key, RustCallStatus *_Nonnull out_status ); -RustBuffer crypter_a934_encrypt( +RustBuffer crypter_9c38_encrypt( RustBuffer plaintext,RustBuffer secret,RustBuffer nonce, RustCallStatus *_Nonnull out_status ); -RustBuffer crypter_a934_decrypt( +RustBuffer crypter_9c38_decrypt( RustBuffer ciphertext,RustBuffer secret, RustCallStatus *_Nonnull out_status ); -RustBuffer ffi_crypter_a934_rustbuffer_alloc( +RustBuffer ffi_crypter_9c38_rustbuffer_alloc( int32_t size, RustCallStatus *_Nonnull out_status ); -RustBuffer ffi_crypter_a934_rustbuffer_from_bytes( +RustBuffer ffi_crypter_9c38_rustbuffer_from_bytes( ForeignBytes bytes, RustCallStatus *_Nonnull out_status ); -void ffi_crypter_a934_rustbuffer_free( +void ffi_crypter_9c38_rustbuffer_free( RustBuffer buf, RustCallStatus *_Nonnull out_status ); -RustBuffer ffi_crypter_a934_rustbuffer_reserve( +RustBuffer ffi_crypter_9c38_rustbuffer_reserve( RustBuffer buf,int32_t additional, RustCallStatus *_Nonnull out_status ); diff --git a/crypter-ffi/src/uniffi/crypter/crypter.kt b/crypter-ffi/src/uniffi/crypter/crypter.kt index 62e7dfc..7f9ef3c 100644 --- a/crypter-ffi/src/uniffi/crypter/crypter.kt +++ b/crypter-ffi/src/uniffi/crypter/crypter.kt @@ -40,7 +40,7 @@ open class RustBuffer : Structure() { companion object { internal fun alloc(size: Int = 0) = rustCall() { status -> - _UniFFILib.INSTANCE.ffi_crypter_a934_rustbuffer_alloc(size, status).also { + _UniFFILib.INSTANCE.ffi_crypter_9c38_rustbuffer_alloc(size, status).also { if(it.data == null) { throw RuntimeException("RustBuffer.alloc() returned null data pointer (size=${size})") } @@ -48,7 +48,7 @@ open class RustBuffer : Structure() { } internal fun free(buf: RustBuffer.ByValue) = rustCall() { status -> - _UniFFILib.INSTANCE.ffi_crypter_a934_rustbuffer_free(buf, status) + _UniFFILib.INSTANCE.ffi_crypter_9c38_rustbuffer_free(buf, status) } } @@ -257,31 +257,35 @@ internal interface _UniFFILib : Library { } } - fun crypter_a934_derive_shared_secret(`theirPubkey`: RustBuffer.ByValue,`mySecretKey`: RustBuffer.ByValue, + fun crypter_9c38_pubkey_from_secret_key(`mySecretKey`: RustBuffer.ByValue, _uniffi_out_err: RustCallStatus ): RustBuffer.ByValue - fun crypter_a934_encrypt(`plaintext`: RustBuffer.ByValue,`secret`: RustBuffer.ByValue,`nonce`: RustBuffer.ByValue, + fun crypter_9c38_derive_shared_secret(`theirPubkey`: RustBuffer.ByValue,`mySecretKey`: RustBuffer.ByValue, _uniffi_out_err: RustCallStatus ): RustBuffer.ByValue - fun crypter_a934_decrypt(`ciphertext`: RustBuffer.ByValue,`secret`: RustBuffer.ByValue, + fun crypter_9c38_encrypt(`plaintext`: RustBuffer.ByValue,`secret`: RustBuffer.ByValue,`nonce`: RustBuffer.ByValue, _uniffi_out_err: RustCallStatus ): RustBuffer.ByValue - fun ffi_crypter_a934_rustbuffer_alloc(`size`: Int, + fun crypter_9c38_decrypt(`ciphertext`: RustBuffer.ByValue,`secret`: RustBuffer.ByValue, _uniffi_out_err: RustCallStatus ): RustBuffer.ByValue - fun ffi_crypter_a934_rustbuffer_from_bytes(`bytes`: ForeignBytes.ByValue, + fun ffi_crypter_9c38_rustbuffer_alloc(`size`: Int, _uniffi_out_err: RustCallStatus ): RustBuffer.ByValue - fun ffi_crypter_a934_rustbuffer_free(`buf`: RustBuffer.ByValue, + fun ffi_crypter_9c38_rustbuffer_from_bytes(`bytes`: ForeignBytes.ByValue, + _uniffi_out_err: RustCallStatus + ): RustBuffer.ByValue + + fun ffi_crypter_9c38_rustbuffer_free(`buf`: RustBuffer.ByValue, _uniffi_out_err: RustCallStatus ): Unit - fun ffi_crypter_a934_rustbuffer_reserve(`buf`: RustBuffer.ByValue,`additional`: Int, + fun ffi_crypter_9c38_rustbuffer_reserve(`buf`: RustBuffer.ByValue,`additional`: Int, _uniffi_out_err: RustCallStatus ): RustBuffer.ByValue @@ -389,10 +393,20 @@ public object FfiConverterTypeCrypterError : FfiConverterRustBuffer + _UniFFILib.INSTANCE.crypter_9c38_pubkey_from_secret_key(FfiConverterString.lower(`mySecretKey`), _status) +}) +} + + +@Throws(CrypterException::class) + fun `deriveSharedSecret`(`theirPubkey`: String, `mySecretKey`: String): String { return FfiConverterString.lift( rustCallWithError(CrypterException) { _status -> - _UniFFILib.INSTANCE.crypter_a934_derive_shared_secret(FfiConverterString.lower(`theirPubkey`), FfiConverterString.lower(`mySecretKey`), _status) + _UniFFILib.INSTANCE.crypter_9c38_derive_shared_secret(FfiConverterString.lower(`theirPubkey`), FfiConverterString.lower(`mySecretKey`), _status) }) } @@ -402,7 +416,7 @@ fun `deriveSharedSecret`(`theirPubkey`: String, `mySecretKey`: String): String { fun `encrypt`(`plaintext`: String, `secret`: String, `nonce`: String): String { return FfiConverterString.lift( rustCallWithError(CrypterException) { _status -> - _UniFFILib.INSTANCE.crypter_a934_encrypt(FfiConverterString.lower(`plaintext`), FfiConverterString.lower(`secret`), FfiConverterString.lower(`nonce`), _status) + _UniFFILib.INSTANCE.crypter_9c38_encrypt(FfiConverterString.lower(`plaintext`), FfiConverterString.lower(`secret`), FfiConverterString.lower(`nonce`), _status) }) } @@ -412,7 +426,7 @@ fun `encrypt`(`plaintext`: String, `secret`: String, `nonce`: String): String { fun `decrypt`(`ciphertext`: String, `secret`: String): String { return FfiConverterString.lift( rustCallWithError(CrypterException) { _status -> - _UniFFILib.INSTANCE.crypter_a934_decrypt(FfiConverterString.lower(`ciphertext`), FfiConverterString.lower(`secret`), _status) + _UniFFILib.INSTANCE.crypter_9c38_decrypt(FfiConverterString.lower(`ciphertext`), FfiConverterString.lower(`secret`), _status) }) }