From 1b583aedc2a4983fefd637f5b095a6ccdc461d66 Mon Sep 17 00:00:00 2001 From: Mathieu Morrissette Date: Thu, 8 Jan 2026 13:59:28 -0500 Subject: [PATCH 1/2] chore(uniffi): Fully switch to uniffi proc macros --- Cargo.lock | 83 +- Cargo.toml | 4 +- src/enums.rs | 7 + src/error.rs | 2 + src/lib.rs | 3 + uniffi/devolutions-crypto-uniffi/Cargo.toml | 7 +- uniffi/devolutions-crypto-uniffi/build.rs | 3 - .../src/argon2parameters.rs | 151 +- .../src/ciphertext.rs | 16 +- .../src/devolutions_crypto.udl | 160 - uniffi/devolutions-crypto-uniffi/src/key.rs | 5 +- uniffi/devolutions-crypto-uniffi/src/lib.rs | 57 +- .../src/password_hash.rs | 4 +- .../src/secret_sharing.rs | 4 +- .../src/signature.rs | 4 +- .../src/signing_key.rs | 30 +- uniffi/devolutions-crypto-uniffi/src/utils.rs | 2 +- .../crypto/devolutions_crypto_uniffi.kt | 2997 +++++++++++++++++ .../org/devolutions/crypto/AsymmetricTest.kt | 13 +- .../devolutions/crypto/SecretSharingTest.kt | 5 +- .../org/devolutions/crypto/SymmetricTest.kt | 3 +- .../org/devolutions/crypto/UtilsTest.kt | 1 + .../DevolutionsCryptoSwift.swift | 1277 ++----- .../devolutions_cryptoFFI.h | 226 +- 24 files changed, 3730 insertions(+), 1334 deletions(-) delete mode 100644 uniffi/devolutions-crypto-uniffi/build.rs delete mode 100644 uniffi/devolutions-crypto-uniffi/src/devolutions_crypto.udl create mode 100644 wrappers/kotlin/lib/src/main/kotlin/org/devolutions/crypto/devolutions_crypto_uniffi.kt diff --git a/Cargo.lock b/Cargo.lock index 9ffe4c449..7eb501a93 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -427,6 +427,12 @@ dependencies = [ "libc", ] +[[package]] +name = "crossbeam-utils" +version = "0.8.21" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d0a5c400df2834b80a4c3327b3aad3a4c4cd4de0629063962b03235697506a28" + [[package]] name = "crypto-common" version = "0.1.7" @@ -519,6 +525,7 @@ dependencies = [ "subtle", "thiserror", "typed-builder", + "uniffi", "wasm-bindgen", "wasm-bindgen-test", "x25519-dalek", @@ -567,8 +574,8 @@ name = "devolutions-crypto-uniffi" version = "0.9.3" dependencies = [ "devolutions-crypto", + "rust-argon2", "uniffi", - "uniffi-builder-macro", ] [[package]] @@ -756,6 +763,8 @@ checksum = "6717a8d2a5a929a1a2eb43a12812498ed141a0bcfb7e8f7844fbdbe4303bba9f" dependencies = [ "equivalent", "hashbrown 0.16.0", + "serde", + "serde_core", ] [[package]] @@ -1146,6 +1155,7 @@ dependencies = [ "base64 0.22.1", "blake2b_simd", "constant_time_eq 0.4.2", + "crossbeam-utils", ] [[package]] @@ -1301,6 +1311,15 @@ dependencies = [ "serde_core", ] +[[package]] +name = "serde_spanned" +version = "1.0.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f8bbf91e5a4d6315eee45e704372590b30e260ee83af6639d64557f51b067776" +dependencies = [ + "serde_core", +] + [[package]] name = "sha2" version = "0.10.9" @@ -1460,11 +1479,17 @@ dependencies = [ [[package]] name = "toml" -version = "0.5.11" +version = "0.9.8" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f4f7f0dd8d50a853a531c426359045b1998f04219d88799810762cd4ad314234" +checksum = "f0dc8b1fb61449e27716ec0e1bdf0f6b8f3e8f6b05391e8497b8b6d7804ea6d8" dependencies = [ - "serde", + "indexmap", + "serde_core", + "serde_spanned", + "toml_datetime", + "toml_parser", + "toml_writer", + "winnow", ] [[package]] @@ -1497,6 +1522,12 @@ dependencies = [ "winnow", ] +[[package]] +name = "toml_writer" +version = "1.0.6+spec-1.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ab16f14aed21ee8bfd8ec22513f7287cd4a91aa92e44edfe2c17ddd004e92607" + [[package]] name = "typed-builder" version = "0.23.2" @@ -1531,16 +1562,15 @@ checksum = "9312f7c4f6ff9069b165498234ce8be658059c6728633667c526e27dc2cf1df5" [[package]] name = "uniffi" -version = "0.29.5" +version = "0.30.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3291800a6b06569f7d3e15bdb6dc235e0f0c8bd3eb07177f430057feb076415f" +checksum = "c866f627c3f04c3df068b68bb2d725492caaa539dd313e2a9d26bb85b1a32f4e" dependencies = [ "anyhow", "camino", "cargo_metadata", "clap", "uniffi_bindgen", - "uniffi_build", "uniffi_core", "uniffi_macros", "uniffi_pipeline", @@ -1563,9 +1593,9 @@ dependencies = [ [[package]] name = "uniffi_bindgen" -version = "0.29.5" +version = "0.30.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a04b99fa7796eaaa7b87976a0dbdd1178dc1ee702ea00aca2642003aef9b669e" +checksum = "7c8ca600167641ebe7c8ba9254af40492dda3397c528cc3b2f511bd23e8541a5" dependencies = [ "anyhow", "askama", @@ -1587,22 +1617,11 @@ dependencies = [ "uniffi_udl", ] -[[package]] -name = "uniffi_build" -version = "0.29.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "025a05cba02ee22b6624ac3d257e59c7395319ea8fe1aae33a7cdb4e2a3016cc" -dependencies = [ - "anyhow", - "camino", - "uniffi_bindgen", -] - [[package]] name = "uniffi_core" -version = "0.29.5" +version = "0.30.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f38a9a27529ccff732f8efddb831b65b1e07f7dea3fd4cacd4a35a8c4b253b98" +checksum = "7e7a5a038ebffe8f4cf91416b154ef3c2468b18e828b7009e01b1b99938089f9" dependencies = [ "anyhow", "bytes", @@ -1612,9 +1631,9 @@ dependencies = [ [[package]] name = "uniffi_internal_macros" -version = "0.29.5" +version = "0.30.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "09acd2ce09c777dd65ee97c251d33c8a972afc04873f1e3b21eb3492ade16933" +checksum = "e3c2a6f93e7b73726e2015696ece25ca0ac5a5f1cf8d6a7ab5214dd0a01d2edf" dependencies = [ "anyhow", "indexmap", @@ -1625,9 +1644,9 @@ dependencies = [ [[package]] name = "uniffi_macros" -version = "0.29.5" +version = "0.30.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5596f178c4f7aafa1a501c4e0b96236a96bc2ef92bdb453d83e609dad0040152" +checksum = "64c6309fc36c7992afc03bc0c5b059c656bccbef3f2a4bc362980017f8936141" dependencies = [ "camino", "fs-err", @@ -1642,9 +1661,9 @@ dependencies = [ [[package]] name = "uniffi_meta" -version = "0.29.5" +version = "0.30.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "beadc1f460eb2e209263c49c4f5b19e9a02e00a3b2b393f78ad10d766346ecff" +checksum = "0a138823392dba19b0aa494872689f97d0ee157de5852e2bec157ce6de9cdc22" dependencies = [ "anyhow", "siphasher", @@ -1654,9 +1673,9 @@ dependencies = [ [[package]] name = "uniffi_pipeline" -version = "0.29.5" +version = "0.30.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dd76b3ac8a2d964ca9fce7df21c755afb4c77b054a85ad7a029ad179cc5abb8a" +checksum = "8c27c4b515d25f8e53cc918e238c39a79c3144a40eaf2e51c4a7958973422c29" dependencies = [ "anyhow", "heck", @@ -1667,9 +1686,9 @@ dependencies = [ [[package]] name = "uniffi_udl" -version = "0.29.5" +version = "0.30.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4319cf905911d70d5b97ce0f46f101619a22e9a189c8c46d797a9955e9233716" +checksum = "d0adacdd848aeed7af4f5af7d2f621d5e82531325d405e29463482becfdeafca" dependencies = [ "anyhow", "textwrap", diff --git a/Cargo.toml b/Cargo.toml index 909bb8a8b..ae9da019f 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -11,7 +11,7 @@ members = [ ] [workspace.dependencies] -uniffi = "0.29.1" +uniffi = "0.30.0" [package] name = "devolutions-crypto" @@ -51,6 +51,7 @@ rand_08 = { package = "rand", version = "0.8" } thiserror = "2.0.12" typed-builder = "0.23.2" rust-argon2 = { version = "3.0", default-features = false } +uniffi = { workspace = true, optional = true } ed25519-dalek = { version = "2", features = [ "rand_core" ] } x25519-dalek = { version = "2", features = [ "static_secrets" ] } @@ -76,6 +77,7 @@ wasm-bindgen-test = "0.3" default = [] fuzz = ["arbitrary", "blahaj/fuzzing"] wbindgen = ["wasm-bindgen", "serde-wasm-bindgen", "js-sys"] +uniffi-support = ["uniffi"] [dependencies.getrandom_v02] package = "getrandom" diff --git a/src/enums.rs b/src/enums.rs index fd4ceb08d..703dee101 100644 --- a/src/enums.rs +++ b/src/enums.rs @@ -10,6 +10,7 @@ use wasm_bindgen::prelude::*; /// The different data types. #[cfg_attr(feature = "wbindgen", wasm_bindgen())] #[cfg_attr(feature = "fuzz", derive(Arbitrary))] +#[cfg_attr(feature = "uniffi-support", derive(uniffi::Enum))] #[derive(Clone, Copy, PartialEq, Eq, Zeroize, IntoPrimitive, TryFromPrimitive, Debug)] #[repr(u16)] #[derive(Default)] @@ -36,6 +37,7 @@ pub enum DataType { /// The versions of the encryption scheme to use. #[cfg_attr(feature = "wbindgen", wasm_bindgen())] #[cfg_attr(feature = "fuzz", derive(Arbitrary))] +#[cfg_attr(feature = "uniffi-support", derive(uniffi::Enum))] #[derive(Clone, Copy, PartialEq, Eq, Zeroize, IntoPrimitive, TryFromPrimitive, Debug)] #[repr(u16)] #[derive(Default)] @@ -66,6 +68,7 @@ pub enum OnlineCiphertextVersion { /// The versions of the password hashing scheme to use. #[cfg_attr(feature = "wbindgen", wasm_bindgen())] #[cfg_attr(feature = "fuzz", derive(Arbitrary))] +#[cfg_attr(feature = "uniffi-support", derive(uniffi::Enum))] #[derive(Clone, Copy, PartialEq, Eq, Zeroize, IntoPrimitive, TryFromPrimitive, Debug)] #[repr(u16)] #[derive(Default)] @@ -80,6 +83,7 @@ pub enum PasswordHashVersion { /// The versions of the key scheme to use. #[cfg_attr(feature = "wbindgen", wasm_bindgen())] #[cfg_attr(feature = "fuzz", derive(Arbitrary))] +#[cfg_attr(feature = "uniffi-support", derive(uniffi::Enum))] #[derive(Clone, Copy, PartialEq, Eq, Zeroize, IntoPrimitive, TryFromPrimitive, Debug)] #[repr(u16)] #[derive(Default)] @@ -93,6 +97,7 @@ pub enum KeyVersion { #[cfg_attr(feature = "wbindgen", wasm_bindgen())] #[cfg_attr(feature = "fuzz", derive(Arbitrary))] +#[cfg_attr(feature = "uniffi-support", derive(uniffi::Enum))] #[derive(Clone, Copy, PartialEq, Eq, Zeroize, IntoPrimitive, TryFromPrimitive, Debug)] #[repr(u16)] #[derive(Default)] @@ -107,6 +112,7 @@ pub enum SigningKeyVersion { /// The versions of the secret sharing scheme to use. #[cfg_attr(feature = "wbindgen", wasm_bindgen())] #[cfg_attr(feature = "fuzz", derive(Arbitrary))] +#[cfg_attr(feature = "uniffi-support", derive(uniffi::Enum))] #[derive(Clone, Copy, PartialEq, Eq, Zeroize, IntoPrimitive, TryFromPrimitive, Debug)] #[repr(u16)] #[derive(Default)] @@ -121,6 +127,7 @@ pub enum SecretSharingVersion { /// The versions of the secret sharing scheme to use. #[cfg_attr(feature = "wbindgen", wasm_bindgen())] #[cfg_attr(feature = "fuzz", derive(Arbitrary))] +#[cfg_attr(feature = "uniffi-support", derive(uniffi::Enum))] #[derive(Clone, Copy, PartialEq, Eq, Zeroize, IntoPrimitive, TryFromPrimitive, Debug)] #[repr(u16)] #[derive(Default)] diff --git a/src/error.rs b/src/error.rs index 99a8d5ee4..cb919a1d1 100644 --- a/src/error.rs +++ b/src/error.rs @@ -22,6 +22,8 @@ pub type Result = std::result::Result; // } /// This crate's error type. +#[cfg_attr(feature = "uniffi-support", derive(uniffi::Error))] +#[cfg_attr(feature = "uniffi-support", uniffi(flat_error))] #[derive(Debug, IntoStaticStr, thiserror::Error)] pub enum Error { /// The provided data has an invalid length. Error code: -1 diff --git a/src/lib.rs b/src/lib.rs index 51e572af8..e90647ce2 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -240,3 +240,6 @@ pub const DEFAULT_PBKDF2_ITERATIONS: u32 = 10000; #[cfg(feature = "wbindgen")] pub mod wasm; + +#[cfg(feature = "uniffi-support")] +uniffi::setup_scaffolding!(); diff --git a/uniffi/devolutions-crypto-uniffi/Cargo.toml b/uniffi/devolutions-crypto-uniffi/Cargo.toml index ab404c42e..d4dd844bb 100644 --- a/uniffi/devolutions-crypto-uniffi/Cargo.toml +++ b/uniffi/devolutions-crypto-uniffi/Cargo.toml @@ -7,9 +7,6 @@ version.workspace = true crate-type = ["cdylib", "staticlib"] [dependencies] -devolutions-crypto = { path = "../../" } -uniffi-builder-macro = { path = "./uniffi-builder-macro" } +devolutions-crypto = { path = "../../", features = ["uniffi-support"] } uniffi = { workspace = true } - -[build-dependencies] -uniffi = { workspace = true, features = ["build"] } +rust-argon2 = "3.0" diff --git a/uniffi/devolutions-crypto-uniffi/build.rs b/uniffi/devolutions-crypto-uniffi/build.rs deleted file mode 100644 index 3f64bede2..000000000 --- a/uniffi/devolutions-crypto-uniffi/build.rs +++ /dev/null @@ -1,3 +0,0 @@ -fn main() { - uniffi::generate_scaffolding("src/devolutions_crypto.udl").unwrap(); -} diff --git a/uniffi/devolutions-crypto-uniffi/src/argon2parameters.rs b/uniffi/devolutions-crypto-uniffi/src/argon2parameters.rs index bb47d9e52..04060d860 100644 --- a/uniffi/devolutions-crypto-uniffi/src/argon2parameters.rs +++ b/uniffi/devolutions-crypto-uniffi/src/argon2parameters.rs @@ -1,42 +1,133 @@ -use crate::Result; +use crate::{Argon2Variant, Argon2Version, Result}; +use std::sync::{Arc, Mutex}; -use devolutions_crypto::{Argon2Variant, Argon2Version}; +#[derive(uniffi::Object)] +pub struct Argon2ParametersBuilder { + length: Mutex>, + lanes: Mutex>, + memory: Mutex>, + iterations: Mutex>, + variant: Mutex>, + version: Mutex>, + dc_version: Mutex>, + associated_data: Mutex>>, + secret_key: Mutex>>, + salt: Mutex>>, +} -use uniffi_builder_macro::UniffiBuilder; +#[uniffi::export] +impl Argon2ParametersBuilder { + #[uniffi::constructor] + pub fn new() -> Arc { + Arc::new(Self { + length: Mutex::new(None), + lanes: Mutex::new(None), + memory: Mutex::new(None), + iterations: Mutex::new(None), + variant: Mutex::new(None), + version: Mutex::new(None), + dc_version: Mutex::new(None), + associated_data: Mutex::new(None), + secret_key: Mutex::new(None), + salt: Mutex::new(None), + }) + } -#[UniffiBuilder(Argon2Parameters, devolutions_crypto::argon2parameters_defaults)] -pub struct Argon2ParametersBuilder { - length: u32, - lanes: u32, - memory: u32, - iterations: u32, - variant: Argon2Variant, - version: Argon2Version, - dc_version: u32, - - #[builder_default = Default::default()] - associated_data: Vec, - - #[builder_default = Default::default()] - secret_key: Vec, - - #[builder_default = devolutions_crypto::argon2parameters_defaults::salt().unwrap()] - salt: Vec, + pub fn length(self: Arc, value: u32) -> Arc { + *self.length.lock().unwrap() = Some(value); + self + } + + pub fn lanes(self: Arc, value: u32) -> Arc { + *self.lanes.lock().unwrap() = Some(value); + self + } + + pub fn memory(self: Arc, value: u32) -> Arc { + *self.memory.lock().unwrap() = Some(value); + self + } + + pub fn iterations(self: Arc, value: u32) -> Arc { + *self.iterations.lock().unwrap() = Some(value); + self + } + + pub fn variant(self: Arc, value: Argon2Variant) -> Arc { + *self.variant.lock().unwrap() = Some(value); + self + } + + pub fn version(self: Arc, value: Argon2Version) -> Arc { + *self.version.lock().unwrap() = Some(value); + self + } + + pub fn dc_version(self: Arc, value: u32) -> Arc { + *self.dc_version.lock().unwrap() = Some(value); + self + } + + pub fn associated_data(self: Arc, value: Vec) -> Arc { + *self.associated_data.lock().unwrap() = Some(value); + self + } + + pub fn secret_key(self: Arc, value: Vec) -> Arc { + *self.secret_key.lock().unwrap() = Some(value); + self + } + + pub fn salt(self: Arc, value: Vec) -> Arc { + *self.salt.lock().unwrap() = Some(value); + self + } + + pub fn build(self: Arc) -> Arc { + // Get all the values + let length = *self.length.lock().unwrap(); + let lanes = *self.lanes.lock().unwrap(); + let memory = *self.memory.lock().unwrap(); + let iterations = *self.iterations.lock().unwrap(); + let variant = *self.variant.lock().unwrap(); + let version = *self.version.lock().unwrap(); + let dc_version = *self.dc_version.lock().unwrap(); + let associated_data = self.associated_data.lock().unwrap().clone(); + let secret_key = self.secret_key.lock().unwrap().clone(); + let salt = self.salt.lock().unwrap().clone(); + + // Build by chaining all fields together (typed-builder requires all fields to be set) + let inner = devolutions_crypto::Argon2Parameters::builder() + .length(length.unwrap_or(32)) + .lanes(lanes.unwrap_or(1)) + .memory(memory.unwrap_or(4096)) + .iterations(iterations.unwrap_or(3)) + .variant(variant.map(|v| v.into()).unwrap_or(argon2::Variant::Argon2id)) + .version(version.map(|v| v.into()).unwrap_or(argon2::Version::Version13)) + .dc_version(dc_version.unwrap_or(1)) + .associated_data(associated_data.unwrap_or_default()) + .secret_key(secret_key.unwrap_or_default()) + .salt(salt.unwrap_or_else(|| devolutions_crypto::argon2parameters_defaults::salt().unwrap())) + .build(); + + Arc::new(Argon2Parameters { inner }) + } } -pub struct Argon2Parameters(pub devolutions_crypto::Argon2Parameters); +#[derive(uniffi::Object)] +pub struct Argon2Parameters { + pub(crate) inner: devolutions_crypto::Argon2Parameters, +} +#[uniffi::export] impl Argon2Parameters { - pub fn new_from_bytes(data: &[u8]) -> Result { - let data = data.try_into()?; - Ok(Self(data)) + #[uniffi::constructor] + pub fn new_from_bytes(data: &[u8]) -> Result> { + let inner = data.try_into()?; + Ok(Arc::new(Self { inner })) } pub fn get_bytes(&self) -> Vec { - (&self.0).into() - } - - fn get_inner_builder() -> devolutions_crypto::Argon2ParametersBuilder { - devolutions_crypto::Argon2Parameters::builder() + (&self.inner).into() } } diff --git a/uniffi/devolutions-crypto-uniffi/src/ciphertext.rs b/uniffi/devolutions-crypto-uniffi/src/ciphertext.rs index 8ed09fc46..741ac304c 100644 --- a/uniffi/devolutions-crypto-uniffi/src/ciphertext.rs +++ b/uniffi/devolutions-crypto-uniffi/src/ciphertext.rs @@ -1,16 +1,20 @@ use crate::CiphertextVersion; use crate::Result; -pub fn encrypt(data: &[u8], key: &[u8], version: CiphertextVersion) -> Result> { +#[uniffi::export(default(version = None))] +pub fn encrypt(data: &[u8], key: &[u8], version: Option) -> Result> { + let version = version.unwrap_or(CiphertextVersion::Latest); Ok(devolutions_crypto::ciphertext::encrypt(data, key, version)?.into()) } +#[uniffi::export(default(version = None))] pub fn encrypt_with_aad( data: &[u8], key: &[u8], aad: &[u8], - version: CiphertextVersion, + version: Option, ) -> Result> { + let version = version.unwrap_or(CiphertextVersion::Latest); Ok(devolutions_crypto::ciphertext::encrypt_with_aad(data, key, aad, version)?.into()) } @@ -26,17 +30,21 @@ fn decrypt_with_aad(data: &[u8], key: &[u8], aad: &[u8]) -> Result> { data.decrypt_with_aad(key, aad) } -pub fn encrypt_asymmetric(data: &[u8], key: &[u8], version: CiphertextVersion) -> Result> { +#[uniffi::export(default(version = None))] +pub fn encrypt_asymmetric(data: &[u8], key: &[u8], version: Option) -> Result> { + let version = version.unwrap_or(CiphertextVersion::Latest); let key = key.try_into()?; Ok(devolutions_crypto::ciphertext::encrypt_asymmetric(data, &key, version)?.into()) } +#[uniffi::export(default(version = None))] pub fn encrypt_asymmetric_with_aad( data: &[u8], key: &[u8], aad: &[u8], - version: CiphertextVersion, + version: Option, ) -> Result> { + let version = version.unwrap_or(CiphertextVersion::Latest); let key = key.try_into()?; Ok( devolutions_crypto::ciphertext::encrypt_asymmetric_with_aad(data, &key, aad, version)? diff --git a/uniffi/devolutions-crypto-uniffi/src/devolutions_crypto.udl b/uniffi/devolutions-crypto-uniffi/src/devolutions_crypto.udl deleted file mode 100644 index ffb3e16bb..000000000 --- a/uniffi/devolutions-crypto-uniffi/src/devolutions_crypto.udl +++ /dev/null @@ -1,160 +0,0 @@ -[Remote] -enum DataType { - "None", - "Key", - "Ciphertext", - "PasswordHash", - "Share", - "SigningKey", - "Signature", - "OnlineCiphertext", -}; - -[Remote] -enum CiphertextVersion { - "Latest", - "V1", - "V2", -}; - -[Remote] -enum PasswordHashVersion { - "Latest", - "V1", -}; - -[Remote] -enum KeyVersion { - "Latest", - "V1", -}; - -[Remote] -enum SigningKeyVersion { - "Latest", - "V1", -}; - -[Remote] -enum SecretSharingVersion { - "Latest", - "V1", -}; - -[Remote] -enum SignatureVersion { - "Latest", - "V1", -}; - -[Remote] -enum Argon2Version { - "Version10", - "Version13", -}; - -[Remote] -enum Argon2Variant { - "Argon2d", - "Argon2i", - "Argon2id", -}; - -[Error, Remote] -enum DevolutionsCryptoError { - "InvalidLength", - "InvalidKeyLength", - "InvalidOutputLength", - "InvalidSignature", - "InvalidMac", - "InvalidDataType", - "UnknownType", - "UnknownSubtype", - "UnknownVersion", - "InvalidData", - "NullPointer", - "CryptoError", - "RandomError", - "IoError", - "NotEnoughShares", - "InconsistentVersion", - "InvalidChunkLength", - "PoisonedMutex", -}; - -interface Argon2ParametersBuilder { - constructor(); - [Self=ByArc] - Argon2ParametersBuilder length(u32 value); - [Self=ByArc] - Argon2ParametersBuilder lanes(u32 value); - [Self=ByArc] - Argon2ParametersBuilder memory(u32 value); - [Self=ByArc] - Argon2ParametersBuilder iterations(u32 value); - [Self=ByArc] - Argon2ParametersBuilder variant(Argon2Variant value); - [Self=ByArc] - Argon2ParametersBuilder version(Argon2Version value); - [Self=ByArc] - Argon2ParametersBuilder dc_version(u32 value); - [Self=ByArc] - Argon2ParametersBuilder associated_data(bytes value); - [Self=ByArc] - Argon2ParametersBuilder secret_key(bytes value); - [Self=ByArc] - Argon2ParametersBuilder salt(bytes value); - [Self=ByArc] - Argon2Parameters build(); -}; - -interface Argon2Parameters { - [Name=new_from_bytes, Throws=DevolutionsCryptoError] - constructor([ByRef] bytes data); - bytes get_bytes(); -}; - -dictionary KeyPair { - bytes public_key; - bytes private_key; -}; - -interface SigningKeyPair { - [Name=new_from_bytes, Throws=DevolutionsCryptoError] - constructor([ByRef] bytes data); - bytes get_public_key(); - bytes get_private_key(); -}; - -namespace devolutions_crypto { - // Ciphertext - [Throws=DevolutionsCryptoError] - bytes encrypt([ByRef] bytes data, [ByRef] bytes key, optional CiphertextVersion version = "Latest"); - - [Throws=DevolutionsCryptoError] - bytes encrypt_with_aad([ByRef] bytes data, [ByRef] bytes key, [ByRef] bytes aad, optional CiphertextVersion version = "Latest"); - - [Throws=DevolutionsCryptoError] - bytes encrypt_asymmetric([ByRef] bytes data, [ByRef] bytes key, optional CiphertextVersion version = "Latest"); - - [Throws=DevolutionsCryptoError] - bytes encrypt_asymmetric_with_aad([ByRef] bytes data, [ByRef] bytes key, [ByRef] bytes aad, optional CiphertextVersion version = "Latest"); - - // Keys - KeyPair generate_keypair(optional KeyVersion version = "Latest"); - - // Password Hash - [Throws=DevolutionsCryptoError] - bytes hash_password([ByRef] bytes password, optional u32 iterations = 10000, optional PasswordHashVersion version = "Latest"); - - // Secret Sharing - [Throws=DevolutionsCryptoError] - sequence generate_shared_key(u8 n_shares, u8 threshold, optional u32 length = 32, optional SecretSharingVersion version = "Latest"); - - // Signature - [Throws=DevolutionsCryptoError] - bytes sign([ByRef] bytes data, [ByRef] bytes keypair, optional SignatureVersion version = "Latest"); - - // Signing Key - SigningKeyPair generate_signing_keypair(optional SigningKeyVersion version = "Latest"); -}; \ No newline at end of file diff --git a/uniffi/devolutions-crypto-uniffi/src/key.rs b/uniffi/devolutions-crypto-uniffi/src/key.rs index 59eed6243..cbfb43544 100644 --- a/uniffi/devolutions-crypto-uniffi/src/key.rs +++ b/uniffi/devolutions-crypto-uniffi/src/key.rs @@ -1,6 +1,7 @@ use crate::KeyVersion; use crate::Result; +#[derive(uniffi::Record)] pub struct KeyPair { pub private_key: Vec, pub public_key: Vec, @@ -15,7 +16,9 @@ impl From for KeyPair { } } -pub fn generate_keypair(version: KeyVersion) -> KeyPair { +#[uniffi::export(default(version = None))] +pub fn generate_keypair(version: Option) -> KeyPair { + let version = version.unwrap_or(KeyVersion::Latest); devolutions_crypto::key::generate_keypair(version).into() } diff --git a/uniffi/devolutions-crypto-uniffi/src/lib.rs b/uniffi/devolutions-crypto-uniffi/src/lib.rs index 55c644d85..5adbf04e2 100644 --- a/uniffi/devolutions-crypto-uniffi/src/lib.rs +++ b/uniffi/devolutions-crypto-uniffi/src/lib.rs @@ -16,8 +16,7 @@ pub use signature::*; pub use signing_key::*; pub use utils::*; -pub use devolutions_crypto::Argon2Variant; -pub use devolutions_crypto::Argon2Version; +// Re-export types from devolutions_crypto pub use devolutions_crypto::CiphertextVersion; pub use devolutions_crypto::DataType; pub use devolutions_crypto::Error as DevolutionsCryptoError; @@ -29,4 +28,56 @@ pub use devolutions_crypto::SigningKeyVersion; pub use devolutions_crypto::Result; -uniffi::include_scaffolding!("devolutions_crypto"); +// Wrapper types for Argon2 enums from rust-argon2 crate +#[derive(uniffi::Enum, Clone, Copy, Debug, PartialEq, Eq)] +pub enum Argon2Version { + Version10, + Version13, +} + +impl From for argon2::Version { + fn from(version: Argon2Version) -> Self { + match version { + Argon2Version::Version10 => argon2::Version::Version10, + Argon2Version::Version13 => argon2::Version::Version13, + } + } +} + +impl From for Argon2Version { + fn from(version: argon2::Version) -> Self { + match version { + argon2::Version::Version10 => Argon2Version::Version10, + argon2::Version::Version13 => Argon2Version::Version13, + } + } +} + +#[derive(uniffi::Enum, Clone, Copy, Debug, PartialEq, Eq)] +pub enum Argon2Variant { + Argon2d, + Argon2i, + Argon2id, +} + +impl From for argon2::Variant { + fn from(variant: Argon2Variant) -> Self { + match variant { + Argon2Variant::Argon2d => argon2::Variant::Argon2d, + Argon2Variant::Argon2i => argon2::Variant::Argon2i, + Argon2Variant::Argon2id => argon2::Variant::Argon2id, + } + } +} + +impl From for Argon2Variant { + fn from(variant: argon2::Variant) -> Self { + match variant { + argon2::Variant::Argon2d => Argon2Variant::Argon2d, + argon2::Variant::Argon2i => Argon2Variant::Argon2i, + argon2::Variant::Argon2id => Argon2Variant::Argon2id, + } + } +} + +uniffi::setup_scaffolding!(); diff --git a/uniffi/devolutions-crypto-uniffi/src/password_hash.rs b/uniffi/devolutions-crypto-uniffi/src/password_hash.rs index 85b5f40dc..7bd58ad09 100644 --- a/uniffi/devolutions-crypto-uniffi/src/password_hash.rs +++ b/uniffi/devolutions-crypto-uniffi/src/password_hash.rs @@ -1,11 +1,13 @@ use crate::PasswordHashVersion; use crate::Result; +#[uniffi::export(default(iterations = 10000, version = None))] pub fn hash_password( password: &[u8], iterations: u32, - version: PasswordHashVersion, + version: Option, ) -> Result> { + let version = version.unwrap_or(PasswordHashVersion::Latest); Ok(devolutions_crypto::password_hash::hash_password(password, iterations, version)?.into()) } diff --git a/uniffi/devolutions-crypto-uniffi/src/secret_sharing.rs b/uniffi/devolutions-crypto-uniffi/src/secret_sharing.rs index 89e6ea58c..98bb0019a 100644 --- a/uniffi/devolutions-crypto-uniffi/src/secret_sharing.rs +++ b/uniffi/devolutions-crypto-uniffi/src/secret_sharing.rs @@ -1,12 +1,14 @@ use crate::Result; use crate::SecretSharingVersion; +#[uniffi::export(default(length = 32, version = None))] pub fn generate_shared_key( n_shares: u8, threshold: u8, length: u32, - version: SecretSharingVersion, + version: Option, ) -> Result>> { + let version = version.unwrap_or(SecretSharingVersion::Latest); Ok(devolutions_crypto::secret_sharing::generate_shared_key( n_shares, threshold, diff --git a/uniffi/devolutions-crypto-uniffi/src/signature.rs b/uniffi/devolutions-crypto-uniffi/src/signature.rs index c7ad08216..1635a0cc2 100644 --- a/uniffi/devolutions-crypto-uniffi/src/signature.rs +++ b/uniffi/devolutions-crypto-uniffi/src/signature.rs @@ -1,7 +1,9 @@ use crate::Result; use crate::SignatureVersion; -pub fn sign(data: &[u8], keypair: &[u8], version: SignatureVersion) -> Result> { +#[uniffi::export(default(version = None))] +pub fn sign(data: &[u8], keypair: &[u8], version: Option) -> Result> { + let version = version.unwrap_or(SignatureVersion::Latest); let keypair = keypair.try_into()?; Ok(devolutions_crypto::signature::sign(data, &keypair, version).into()) diff --git a/uniffi/devolutions-crypto-uniffi/src/signing_key.rs b/uniffi/devolutions-crypto-uniffi/src/signing_key.rs index 05a698ec8..ddcca1c81 100644 --- a/uniffi/devolutions-crypto-uniffi/src/signing_key.rs +++ b/uniffi/devolutions-crypto-uniffi/src/signing_key.rs @@ -4,11 +4,23 @@ use crate::DevolutionsCryptoError; use crate::Result; use crate::SigningKeyVersion; +#[derive(uniffi::Object)] pub struct SigningKeyPair(devolutions_crypto::signing_key::SigningKeyPair); +#[uniffi::export] impl SigningKeyPair { - pub fn new_from_bytes(data: &[u8]) -> Result { - data.try_into() + #[uniffi::constructor] + pub fn new_from_bytes(data: &[u8]) -> Result> { + let inner = data.try_into()?; + Ok(Arc::new(Self(inner))) + } + + pub fn get_public_key(&self) -> Vec { + self.0.get_public_key().into() + } + + pub fn get_private_key(&self) -> Vec { + self.0.clone().into() } } @@ -26,16 +38,8 @@ impl TryFrom<&[u8]> for SigningKeyPair { } } -impl SigningKeyPair { - pub fn get_public_key(&self) -> Vec { - self.0.get_public_key().into() - } - - pub fn get_private_key(&self) -> Vec { - self.0.clone().into() - } -} - -pub fn generate_signing_keypair(version: SigningKeyVersion) -> Arc { +#[uniffi::export(default(version = None))] +pub fn generate_signing_keypair(version: Option) -> Arc { + let version = version.unwrap_or(SigningKeyVersion::Latest); Arc::new(devolutions_crypto::signing_key::generate_signing_keypair(version).into()) } diff --git a/uniffi/devolutions-crypto-uniffi/src/utils.rs b/uniffi/devolutions-crypto-uniffi/src/utils.rs index 427de4b33..e00e0037b 100644 --- a/uniffi/devolutions-crypto-uniffi/src/utils.rs +++ b/uniffi/devolutions-crypto-uniffi/src/utils.rs @@ -24,7 +24,7 @@ pub fn derive_key_pbkdf2( #[uniffi::export] pub fn derive_key_argon2(key: &[u8], parameters: &Arc) -> Result> { - devolutions_crypto::utils::derive_key_argon2(key, ¶meters.0) + devolutions_crypto::utils::derive_key_argon2(key, ¶meters.inner) } #[uniffi::export] diff --git a/wrappers/kotlin/lib/src/main/kotlin/org/devolutions/crypto/devolutions_crypto_uniffi.kt b/wrappers/kotlin/lib/src/main/kotlin/org/devolutions/crypto/devolutions_crypto_uniffi.kt new file mode 100644 index 000000000..f47af17cb --- /dev/null +++ b/wrappers/kotlin/lib/src/main/kotlin/org/devolutions/crypto/devolutions_crypto_uniffi.kt @@ -0,0 +1,2997 @@ +// This file was autogenerated by some hot garbage in the `uniffi` crate. +// Trust me, you don't want to mess with it! + +@file:Suppress("NAME_SHADOWING") + +package org.devolutions.crypto + +// Common helper code. +// +// Ideally this would live in a separate .kt file where it can be unittested etc +// in isolation, and perhaps even published as a re-useable package. +// +// However, it's important that the details of how this helper code works (e.g. the +// way that different builtin types are passed across the FFI) exactly match what's +// expected by the Rust code on the other side of the interface. In practice right +// now that means coming from the exact some version of `uniffi` that was used to +// compile the Rust component. The easiest way to ensure this is to bundle the Kotlin +// helpers directly inline like we're doing here. + +import com.sun.jna.Library +import com.sun.jna.IntegerType +import com.sun.jna.Native +import com.sun.jna.Pointer +import com.sun.jna.Structure +import com.sun.jna.Callback +import com.sun.jna.ptr.* +import java.nio.ByteBuffer +import java.nio.ByteOrder +import java.nio.CharBuffer +import java.nio.charset.CodingErrorAction +import java.util.concurrent.atomic.AtomicLong +import java.util.concurrent.ConcurrentHashMap +import java.util.concurrent.atomic.AtomicBoolean +import uniffi.devolutions_crypto.CiphertextVersion +import uniffi.devolutions_crypto.DataType +import uniffi.devolutions_crypto.Exception +import uniffi.devolutions_crypto.FfiConverterTypeCiphertextVersion +import uniffi.devolutions_crypto.FfiConverterTypeDataType +import uniffi.devolutions_crypto.FfiConverterTypeError +import uniffi.devolutions_crypto.FfiConverterTypeKeyVersion +import uniffi.devolutions_crypto.FfiConverterTypePasswordHashVersion +import uniffi.devolutions_crypto.FfiConverterTypeSecretSharingVersion +import uniffi.devolutions_crypto.FfiConverterTypeSignatureVersion +import uniffi.devolutions_crypto.FfiConverterTypeSigningKeyVersion +import uniffi.devolutions_crypto.KeyVersion +import uniffi.devolutions_crypto.PasswordHashVersion +import uniffi.devolutions_crypto.SecretSharingVersion +import uniffi.devolutions_crypto.SignatureVersion +import uniffi.devolutions_crypto.SigningKeyVersion +import uniffi.devolutions_crypto.RustBuffer as RustBufferCiphertextVersion +import uniffi.devolutions_crypto.RustBuffer as RustBufferDataType +import uniffi.devolutions_crypto.RustBuffer as RustBufferError +import uniffi.devolutions_crypto.RustBuffer as RustBufferKeyVersion +import uniffi.devolutions_crypto.RustBuffer as RustBufferPasswordHashVersion +import uniffi.devolutions_crypto.RustBuffer as RustBufferSecretSharingVersion +import uniffi.devolutions_crypto.RustBuffer as RustBufferSignatureVersion +import uniffi.devolutions_crypto.RustBuffer as RustBufferSigningKeyVersion + +// This is a helper for safely working with byte buffers returned from the Rust code. +// A rust-owned buffer is represented by its capacity, its current length, and a +// pointer to the underlying data. + +/** + * @suppress + */ +@Structure.FieldOrder("capacity", "len", "data") +open class RustBuffer : Structure() { + // Note: `capacity` and `len` are actually `ULong` values, but JVM only supports signed values. + // When dealing with these fields, make sure to call `toULong()`. + @JvmField var capacity: Long = 0 + @JvmField var len: Long = 0 + @JvmField var data: Pointer? = null + + class ByValue: RustBuffer(), Structure.ByValue + class ByReference: RustBuffer(), Structure.ByReference + + internal fun setValue(other: RustBuffer) { + capacity = other.capacity + len = other.len + data = other.data + } + + companion object { + internal fun alloc(size: ULong = 0UL) = uniffiRustCall() { status -> + // Note: need to convert the size to a `Long` value to make this work with JVM. + UniffiLib.ffi_devolutions_crypto_uniffi_rustbuffer_alloc(size.toLong(), status) + }.also { + if(it.data == null) { + throw RuntimeException("RustBuffer.alloc() returned null data pointer (size=${size})") + } + } + + internal fun create(capacity: ULong, len: ULong, data: Pointer?): RustBuffer.ByValue { + var buf = RustBuffer.ByValue() + buf.capacity = capacity.toLong() + buf.len = len.toLong() + buf.data = data + return buf + } + + internal fun free(buf: RustBuffer.ByValue) = uniffiRustCall() { status -> + UniffiLib.ffi_devolutions_crypto_uniffi_rustbuffer_free(buf, status) + } + } + + @Suppress("TooGenericExceptionThrown") + fun asByteBuffer() = + this.data?.getByteBuffer(0, this.len.toLong())?.also { + it.order(ByteOrder.BIG_ENDIAN) + } +} + +// This is a helper for safely passing byte references into the rust code. +// It's not actually used at the moment, because there aren't many things that you +// can take a direct pointer to in the JVM, and if we're going to copy something +// then we might as well copy it into a `RustBuffer`. But it's here for API +// completeness. + +@Structure.FieldOrder("len", "data") +internal open class ForeignBytes : Structure() { + @JvmField var len: Int = 0 + @JvmField var data: Pointer? = null + + class ByValue : ForeignBytes(), Structure.ByValue +} +/** + * The FfiConverter interface handles converter types to and from the FFI + * + * All implementing objects should be public to support external types. When a + * type is external we need to import it's FfiConverter. + * + * @suppress + */ +public interface FfiConverter { + // Convert an FFI type to a Kotlin type + fun lift(value: FfiType): KotlinType + + // Convert an Kotlin type to an FFI type + fun lower(value: KotlinType): FfiType + + // Read a Kotlin type from a `ByteBuffer` + fun read(buf: ByteBuffer): KotlinType + + // Calculate bytes to allocate when creating a `RustBuffer` + // + // This must return at least as many bytes as the write() function will + // write. It can return more bytes than needed, for example when writing + // Strings we can't know the exact bytes needed until we the UTF-8 + // encoding, so we pessimistically allocate the largest size possible (3 + // bytes per codepoint). Allocating extra bytes is not really a big deal + // because the `RustBuffer` is short-lived. + fun allocationSize(value: KotlinType): ULong + + // Write a Kotlin type to a `ByteBuffer` + fun write(value: KotlinType, buf: ByteBuffer) + + // Lower a value into a `RustBuffer` + // + // This method lowers a value into a `RustBuffer` rather than the normal + // FfiType. It's used by the callback interface code. Callback interface + // returns are always serialized into a `RustBuffer` regardless of their + // normal FFI type. + fun lowerIntoRustBuffer(value: KotlinType): RustBuffer.ByValue { + val rbuf = RustBuffer.alloc(allocationSize(value)) + try { + val bbuf = rbuf.data!!.getByteBuffer(0, rbuf.capacity).also { + it.order(ByteOrder.BIG_ENDIAN) + } + write(value, bbuf) + rbuf.writeField("len", bbuf.position().toLong()) + return rbuf + } catch (e: Throwable) { + RustBuffer.free(rbuf) + throw e + } + } + + // Lift a value from a `RustBuffer`. + // + // This here mostly because of the symmetry with `lowerIntoRustBuffer()`. + // It's currently only used by the `FfiConverterRustBuffer` class below. + fun liftFromRustBuffer(rbuf: RustBuffer.ByValue): KotlinType { + val byteBuf = rbuf.asByteBuffer()!! + try { + val item = read(byteBuf) + if (byteBuf.hasRemaining()) { + throw RuntimeException("junk remaining in buffer after lifting, something is very wrong!!") + } + return item + } finally { + RustBuffer.free(rbuf) + } + } +} + +/** + * FfiConverter that uses `RustBuffer` as the FfiType + * + * @suppress + */ +public interface FfiConverterRustBuffer: FfiConverter { + override fun lift(value: RustBuffer.ByValue) = liftFromRustBuffer(value) + override fun lower(value: KotlinType) = lowerIntoRustBuffer(value) +} +// A handful of classes and functions to support the generated data structures. +// This would be a good candidate for isolating in its own ffi-support lib. + +internal const val UNIFFI_CALL_SUCCESS = 0.toByte() +internal const val UNIFFI_CALL_ERROR = 1.toByte() +internal const val UNIFFI_CALL_UNEXPECTED_ERROR = 2.toByte() + +@Structure.FieldOrder("code", "error_buf") +internal open class UniffiRustCallStatus : Structure() { + @JvmField var code: Byte = 0 + @JvmField var error_buf: RustBuffer.ByValue = RustBuffer.ByValue() + + class ByValue: UniffiRustCallStatus(), Structure.ByValue + + fun isSuccess(): Boolean { + return code == UNIFFI_CALL_SUCCESS + } + + fun isError(): Boolean { + return code == UNIFFI_CALL_ERROR + } + + fun isPanic(): Boolean { + return code == UNIFFI_CALL_UNEXPECTED_ERROR + } + + companion object { + fun create(code: Byte, errorBuf: RustBuffer.ByValue): UniffiRustCallStatus.ByValue { + val callStatus = UniffiRustCallStatus.ByValue() + callStatus.code = code + callStatus.error_buf = errorBuf + return callStatus + } + } +} + +class InternalException(message: String) : kotlin.Exception(message) + +/** + * Each top-level error class has a companion object that can lift the error from the call status's rust buffer + * + * @suppress + */ +interface UniffiRustCallStatusErrorHandler { + fun lift(error_buf: RustBuffer.ByValue): E; +} + +// Helpers for calling Rust +// In practice we usually need to be synchronized to call this safely, so it doesn't +// synchronize itself + +// Call a rust function that returns a Result<>. Pass in the Error class companion that corresponds to the Err +private inline fun uniffiRustCallWithError(errorHandler: UniffiRustCallStatusErrorHandler, callback: (UniffiRustCallStatus) -> U): U { + var status = UniffiRustCallStatus() + val return_value = callback(status) + uniffiCheckCallStatus(errorHandler, status) + return return_value +} + +// Check UniffiRustCallStatus and throw an error if the call wasn't successful +private fun uniffiCheckCallStatus(errorHandler: UniffiRustCallStatusErrorHandler, status: UniffiRustCallStatus) { + if (status.isSuccess()) { + return + } else if (status.isError()) { + throw errorHandler.lift(status.error_buf) + } else if (status.isPanic()) { + // when the rust code sees a panic, it tries to construct a rustbuffer + // with the message. but if that code panics, then it just sends back + // an empty buffer. + if (status.error_buf.len > 0) { + throw InternalException(FfiConverterString.lift(status.error_buf)) + } else { + throw InternalException("Rust panic") + } + } else { + throw InternalException("Unknown rust call status: $status.code") + } +} + +/** + * UniffiRustCallStatusErrorHandler implementation for times when we don't expect a CALL_ERROR + * + * @suppress + */ +object UniffiNullRustCallStatusErrorHandler: UniffiRustCallStatusErrorHandler { + override fun lift(error_buf: RustBuffer.ByValue): InternalException { + RustBuffer.free(error_buf) + return InternalException("Unexpected CALL_ERROR") + } +} + +// Call a rust function that returns a plain value +private inline fun uniffiRustCall(callback: (UniffiRustCallStatus) -> U): U { + return uniffiRustCallWithError(UniffiNullRustCallStatusErrorHandler, callback) +} + +internal inline fun uniffiTraitInterfaceCall( + callStatus: UniffiRustCallStatus, + makeCall: () -> T, + writeReturn: (T) -> Unit, +) { + try { + writeReturn(makeCall()) + } catch(e: kotlin.Exception) { + callStatus.code = UNIFFI_CALL_UNEXPECTED_ERROR + callStatus.error_buf = FfiConverterString.lower(e.toString()) + } +} + +internal inline fun uniffiTraitInterfaceCallWithError( + callStatus: UniffiRustCallStatus, + makeCall: () -> T, + writeReturn: (T) -> Unit, + lowerError: (E) -> RustBuffer.ByValue +) { + try { + writeReturn(makeCall()) + } catch(e: kotlin.Exception) { + if (e is E) { + callStatus.code = UNIFFI_CALL_ERROR + callStatus.error_buf = lowerError(e) + } else { + callStatus.code = UNIFFI_CALL_UNEXPECTED_ERROR + callStatus.error_buf = FfiConverterString.lower(e.toString()) + } + } +} +// Initial value and increment amount for handles. +// These ensure that Kotlin-generated handles always have the lowest bit set +private const val UNIFFI_HANDLEMAP_INITIAL = 1.toLong() +private const val UNIFFI_HANDLEMAP_DELTA = 2.toLong() + +// Map handles to objects +// +// This is used pass an opaque 64-bit handle representing a foreign object to the Rust code. +internal class UniffiHandleMap { + private val map = ConcurrentHashMap() + // Start + private val counter = java.util.concurrent.atomic.AtomicLong(UNIFFI_HANDLEMAP_INITIAL) + + val size: Int + get() = map.size + + // Insert a new object into the handle map and get a handle for it + fun insert(obj: T): Long { + val handle = counter.getAndAdd(UNIFFI_HANDLEMAP_DELTA) + map.put(handle, obj) + return handle + } + + // Clone a handle, creating a new one + fun clone(handle: Long): Long { + val obj = map.get(handle) ?: throw InternalException("UniffiHandleMap.clone: Invalid handle") + return insert(obj) + } + + // Get an object from the handle map + fun get(handle: Long): T { + return map.get(handle) ?: throw InternalException("UniffiHandleMap.get: Invalid handle") + } + + // Remove an entry from the handlemap and get the Kotlin object back + fun remove(handle: Long): T { + return map.remove(handle) ?: throw InternalException("UniffiHandleMap: Invalid handle") + } +} + +// Contains loading, initialization code, +// and the FFI Function declarations in a com.sun.jna.Library. +@Synchronized +private fun findLibraryName(componentName: String): String { + val libOverride = System.getProperty("uniffi.component.$componentName.libraryOverride") + if (libOverride != null) { + return libOverride + } + return "devolutions_crypto_uniffi" +} + +// Define FFI callback types +internal interface UniffiRustFutureContinuationCallback : com.sun.jna.Callback { + fun callback(`data`: Long,`pollResult`: Byte,) +} +internal interface UniffiForeignFutureDroppedCallback : com.sun.jna.Callback { + fun callback(`handle`: Long,) +} +internal interface UniffiCallbackInterfaceFree : com.sun.jna.Callback { + fun callback(`handle`: Long,) +} +internal interface UniffiCallbackInterfaceClone : com.sun.jna.Callback { + fun callback(`handle`: Long,) + : Long +} +@Structure.FieldOrder("handle", "free") +internal open class UniffiForeignFutureDroppedCallbackStruct( + @JvmField internal var `handle`: Long = 0.toLong(), + @JvmField internal var `free`: UniffiForeignFutureDroppedCallback? = null, +) : Structure() { + class UniffiByValue( + `handle`: Long = 0.toLong(), + `free`: UniffiForeignFutureDroppedCallback? = null, + ): UniffiForeignFutureDroppedCallbackStruct(`handle`,`free`,), Structure.ByValue + + internal fun uniffiSetValue(other: UniffiForeignFutureDroppedCallbackStruct) { + `handle` = other.`handle` + `free` = other.`free` + } + +} +@Structure.FieldOrder("returnValue", "callStatus") +internal open class UniffiForeignFutureResultU8( + @JvmField internal var `returnValue`: Byte = 0.toByte(), + @JvmField internal var `callStatus`: UniffiRustCallStatus.ByValue = UniffiRustCallStatus.ByValue(), +) : Structure() { + class UniffiByValue( + `returnValue`: Byte = 0.toByte(), + `callStatus`: UniffiRustCallStatus.ByValue = UniffiRustCallStatus.ByValue(), + ): UniffiForeignFutureResultU8(`returnValue`,`callStatus`,), Structure.ByValue + + internal fun uniffiSetValue(other: UniffiForeignFutureResultU8) { + `returnValue` = other.`returnValue` + `callStatus` = other.`callStatus` + } + +} +internal interface UniffiForeignFutureCompleteU8 : com.sun.jna.Callback { + fun callback(`callbackData`: Long,`result`: UniffiForeignFutureResultU8.UniffiByValue,) +} +@Structure.FieldOrder("returnValue", "callStatus") +internal open class UniffiForeignFutureResultI8( + @JvmField internal var `returnValue`: Byte = 0.toByte(), + @JvmField internal var `callStatus`: UniffiRustCallStatus.ByValue = UniffiRustCallStatus.ByValue(), +) : Structure() { + class UniffiByValue( + `returnValue`: Byte = 0.toByte(), + `callStatus`: UniffiRustCallStatus.ByValue = UniffiRustCallStatus.ByValue(), + ): UniffiForeignFutureResultI8(`returnValue`,`callStatus`,), Structure.ByValue + + internal fun uniffiSetValue(other: UniffiForeignFutureResultI8) { + `returnValue` = other.`returnValue` + `callStatus` = other.`callStatus` + } + +} +internal interface UniffiForeignFutureCompleteI8 : com.sun.jna.Callback { + fun callback(`callbackData`: Long,`result`: UniffiForeignFutureResultI8.UniffiByValue,) +} +@Structure.FieldOrder("returnValue", "callStatus") +internal open class UniffiForeignFutureResultU16( + @JvmField internal var `returnValue`: Short = 0.toShort(), + @JvmField internal var `callStatus`: UniffiRustCallStatus.ByValue = UniffiRustCallStatus.ByValue(), +) : Structure() { + class UniffiByValue( + `returnValue`: Short = 0.toShort(), + `callStatus`: UniffiRustCallStatus.ByValue = UniffiRustCallStatus.ByValue(), + ): UniffiForeignFutureResultU16(`returnValue`,`callStatus`,), Structure.ByValue + + internal fun uniffiSetValue(other: UniffiForeignFutureResultU16) { + `returnValue` = other.`returnValue` + `callStatus` = other.`callStatus` + } + +} +internal interface UniffiForeignFutureCompleteU16 : com.sun.jna.Callback { + fun callback(`callbackData`: Long,`result`: UniffiForeignFutureResultU16.UniffiByValue,) +} +@Structure.FieldOrder("returnValue", "callStatus") +internal open class UniffiForeignFutureResultI16( + @JvmField internal var `returnValue`: Short = 0.toShort(), + @JvmField internal var `callStatus`: UniffiRustCallStatus.ByValue = UniffiRustCallStatus.ByValue(), +) : Structure() { + class UniffiByValue( + `returnValue`: Short = 0.toShort(), + `callStatus`: UniffiRustCallStatus.ByValue = UniffiRustCallStatus.ByValue(), + ): UniffiForeignFutureResultI16(`returnValue`,`callStatus`,), Structure.ByValue + + internal fun uniffiSetValue(other: UniffiForeignFutureResultI16) { + `returnValue` = other.`returnValue` + `callStatus` = other.`callStatus` + } + +} +internal interface UniffiForeignFutureCompleteI16 : com.sun.jna.Callback { + fun callback(`callbackData`: Long,`result`: UniffiForeignFutureResultI16.UniffiByValue,) +} +@Structure.FieldOrder("returnValue", "callStatus") +internal open class UniffiForeignFutureResultU32( + @JvmField internal var `returnValue`: Int = 0, + @JvmField internal var `callStatus`: UniffiRustCallStatus.ByValue = UniffiRustCallStatus.ByValue(), +) : Structure() { + class UniffiByValue( + `returnValue`: Int = 0, + `callStatus`: UniffiRustCallStatus.ByValue = UniffiRustCallStatus.ByValue(), + ): UniffiForeignFutureResultU32(`returnValue`,`callStatus`,), Structure.ByValue + + internal fun uniffiSetValue(other: UniffiForeignFutureResultU32) { + `returnValue` = other.`returnValue` + `callStatus` = other.`callStatus` + } + +} +internal interface UniffiForeignFutureCompleteU32 : com.sun.jna.Callback { + fun callback(`callbackData`: Long,`result`: UniffiForeignFutureResultU32.UniffiByValue,) +} +@Structure.FieldOrder("returnValue", "callStatus") +internal open class UniffiForeignFutureResultI32( + @JvmField internal var `returnValue`: Int = 0, + @JvmField internal var `callStatus`: UniffiRustCallStatus.ByValue = UniffiRustCallStatus.ByValue(), +) : Structure() { + class UniffiByValue( + `returnValue`: Int = 0, + `callStatus`: UniffiRustCallStatus.ByValue = UniffiRustCallStatus.ByValue(), + ): UniffiForeignFutureResultI32(`returnValue`,`callStatus`,), Structure.ByValue + + internal fun uniffiSetValue(other: UniffiForeignFutureResultI32) { + `returnValue` = other.`returnValue` + `callStatus` = other.`callStatus` + } + +} +internal interface UniffiForeignFutureCompleteI32 : com.sun.jna.Callback { + fun callback(`callbackData`: Long,`result`: UniffiForeignFutureResultI32.UniffiByValue,) +} +@Structure.FieldOrder("returnValue", "callStatus") +internal open class UniffiForeignFutureResultU64( + @JvmField internal var `returnValue`: Long = 0.toLong(), + @JvmField internal var `callStatus`: UniffiRustCallStatus.ByValue = UniffiRustCallStatus.ByValue(), +) : Structure() { + class UniffiByValue( + `returnValue`: Long = 0.toLong(), + `callStatus`: UniffiRustCallStatus.ByValue = UniffiRustCallStatus.ByValue(), + ): UniffiForeignFutureResultU64(`returnValue`,`callStatus`,), Structure.ByValue + + internal fun uniffiSetValue(other: UniffiForeignFutureResultU64) { + `returnValue` = other.`returnValue` + `callStatus` = other.`callStatus` + } + +} +internal interface UniffiForeignFutureCompleteU64 : com.sun.jna.Callback { + fun callback(`callbackData`: Long,`result`: UniffiForeignFutureResultU64.UniffiByValue,) +} +@Structure.FieldOrder("returnValue", "callStatus") +internal open class UniffiForeignFutureResultI64( + @JvmField internal var `returnValue`: Long = 0.toLong(), + @JvmField internal var `callStatus`: UniffiRustCallStatus.ByValue = UniffiRustCallStatus.ByValue(), +) : Structure() { + class UniffiByValue( + `returnValue`: Long = 0.toLong(), + `callStatus`: UniffiRustCallStatus.ByValue = UniffiRustCallStatus.ByValue(), + ): UniffiForeignFutureResultI64(`returnValue`,`callStatus`,), Structure.ByValue + + internal fun uniffiSetValue(other: UniffiForeignFutureResultI64) { + `returnValue` = other.`returnValue` + `callStatus` = other.`callStatus` + } + +} +internal interface UniffiForeignFutureCompleteI64 : com.sun.jna.Callback { + fun callback(`callbackData`: Long,`result`: UniffiForeignFutureResultI64.UniffiByValue,) +} +@Structure.FieldOrder("returnValue", "callStatus") +internal open class UniffiForeignFutureResultF32( + @JvmField internal var `returnValue`: Float = 0.0f, + @JvmField internal var `callStatus`: UniffiRustCallStatus.ByValue = UniffiRustCallStatus.ByValue(), +) : Structure() { + class UniffiByValue( + `returnValue`: Float = 0.0f, + `callStatus`: UniffiRustCallStatus.ByValue = UniffiRustCallStatus.ByValue(), + ): UniffiForeignFutureResultF32(`returnValue`,`callStatus`,), Structure.ByValue + + internal fun uniffiSetValue(other: UniffiForeignFutureResultF32) { + `returnValue` = other.`returnValue` + `callStatus` = other.`callStatus` + } + +} +internal interface UniffiForeignFutureCompleteF32 : com.sun.jna.Callback { + fun callback(`callbackData`: Long,`result`: UniffiForeignFutureResultF32.UniffiByValue,) +} +@Structure.FieldOrder("returnValue", "callStatus") +internal open class UniffiForeignFutureResultF64( + @JvmField internal var `returnValue`: Double = 0.0, + @JvmField internal var `callStatus`: UniffiRustCallStatus.ByValue = UniffiRustCallStatus.ByValue(), +) : Structure() { + class UniffiByValue( + `returnValue`: Double = 0.0, + `callStatus`: UniffiRustCallStatus.ByValue = UniffiRustCallStatus.ByValue(), + ): UniffiForeignFutureResultF64(`returnValue`,`callStatus`,), Structure.ByValue + + internal fun uniffiSetValue(other: UniffiForeignFutureResultF64) { + `returnValue` = other.`returnValue` + `callStatus` = other.`callStatus` + } + +} +internal interface UniffiForeignFutureCompleteF64 : com.sun.jna.Callback { + fun callback(`callbackData`: Long,`result`: UniffiForeignFutureResultF64.UniffiByValue,) +} +@Structure.FieldOrder("returnValue", "callStatus") +internal open class UniffiForeignFutureResultRustBuffer( + @JvmField internal var `returnValue`: RustBuffer.ByValue = RustBuffer.ByValue(), + @JvmField internal var `callStatus`: UniffiRustCallStatus.ByValue = UniffiRustCallStatus.ByValue(), +) : Structure() { + class UniffiByValue( + `returnValue`: RustBuffer.ByValue = RustBuffer.ByValue(), + `callStatus`: UniffiRustCallStatus.ByValue = UniffiRustCallStatus.ByValue(), + ): UniffiForeignFutureResultRustBuffer(`returnValue`,`callStatus`,), Structure.ByValue + + internal fun uniffiSetValue(other: UniffiForeignFutureResultRustBuffer) { + `returnValue` = other.`returnValue` + `callStatus` = other.`callStatus` + } + +} +internal interface UniffiForeignFutureCompleteRustBuffer : com.sun.jna.Callback { + fun callback(`callbackData`: Long,`result`: UniffiForeignFutureResultRustBuffer.UniffiByValue,) +} +@Structure.FieldOrder("callStatus") +internal open class UniffiForeignFutureResultVoid( + @JvmField internal var `callStatus`: UniffiRustCallStatus.ByValue = UniffiRustCallStatus.ByValue(), +) : Structure() { + class UniffiByValue( + `callStatus`: UniffiRustCallStatus.ByValue = UniffiRustCallStatus.ByValue(), + ): UniffiForeignFutureResultVoid(`callStatus`,), Structure.ByValue + + internal fun uniffiSetValue(other: UniffiForeignFutureResultVoid) { + `callStatus` = other.`callStatus` + } + +} +internal interface UniffiForeignFutureCompleteVoid : com.sun.jna.Callback { + fun callback(`callbackData`: Long,`result`: UniffiForeignFutureResultVoid.UniffiByValue,) +} + +// A JNA Library to expose the extern-C FFI definitions. +// This is an implementation detail which will be called internally by the public API. + +// For large crates we prevent `MethodTooLargeException` (see #2340) +// N.B. the name of the extension is very misleading, since it is +// rather `InterfaceTooLargeException`, caused by too many methods +// in the interface for large crates. +// +// By splitting the otherwise huge interface into two parts +// * UniffiLib (this) +// * IntegrityCheckingUniffiLib +// And all checksum methods are put into `IntegrityCheckingUniffiLib` +// we allow for ~2x as many methods in the UniffiLib interface. +// +// Note: above all written when we used JNA's `loadIndirect` etc. +// We now use JNA's "direct mapping" - unclear if same considerations apply exactly. +internal object IntegrityCheckingUniffiLib { + init { + Native.register(IntegrityCheckingUniffiLib::class.java, findLibraryName(componentName = "devolutions_crypto_uniffi")) + uniffiCheckContractApiVersion(this) + uniffiCheckApiChecksums(this) + } + external fun uniffi_devolutions_crypto_uniffi_checksum_func_base64_decode( + ): Short + external fun uniffi_devolutions_crypto_uniffi_checksum_func_base64_decode_url( + ): Short + external fun uniffi_devolutions_crypto_uniffi_checksum_func_base64_encode( + ): Short + external fun uniffi_devolutions_crypto_uniffi_checksum_func_base64_encode_url( + ): Short + external fun uniffi_devolutions_crypto_uniffi_checksum_func_decrypt( + ): Short + external fun uniffi_devolutions_crypto_uniffi_checksum_func_decrypt_asymmetric( + ): Short + external fun uniffi_devolutions_crypto_uniffi_checksum_func_decrypt_asymmetric_with_aad( + ): Short + external fun uniffi_devolutions_crypto_uniffi_checksum_func_decrypt_with_aad( + ): Short + external fun uniffi_devolutions_crypto_uniffi_checksum_func_derive_key_argon2( + ): Short + external fun uniffi_devolutions_crypto_uniffi_checksum_func_derive_key_pbkdf2( + ): Short + external fun uniffi_devolutions_crypto_uniffi_checksum_func_encrypt( + ): Short + external fun uniffi_devolutions_crypto_uniffi_checksum_func_encrypt_asymmetric( + ): Short + external fun uniffi_devolutions_crypto_uniffi_checksum_func_encrypt_asymmetric_with_aad( + ): Short + external fun uniffi_devolutions_crypto_uniffi_checksum_func_encrypt_with_aad( + ): Short + external fun uniffi_devolutions_crypto_uniffi_checksum_func_generate_key( + ): Short + external fun uniffi_devolutions_crypto_uniffi_checksum_func_generate_keypair( + ): Short + external fun uniffi_devolutions_crypto_uniffi_checksum_func_generate_shared_key( + ): Short + external fun uniffi_devolutions_crypto_uniffi_checksum_func_generate_signing_keypair( + ): Short + external fun uniffi_devolutions_crypto_uniffi_checksum_func_hash_password( + ): Short + external fun uniffi_devolutions_crypto_uniffi_checksum_func_join_shares( + ): Short + external fun uniffi_devolutions_crypto_uniffi_checksum_func_mix_key_exchange( + ): Short + external fun uniffi_devolutions_crypto_uniffi_checksum_func_sign( + ): Short + external fun uniffi_devolutions_crypto_uniffi_checksum_func_validate_header( + ): Short + external fun uniffi_devolutions_crypto_uniffi_checksum_func_verify_password( + ): Short + external fun uniffi_devolutions_crypto_uniffi_checksum_func_verify_signature( + ): Short + external fun uniffi_devolutions_crypto_uniffi_checksum_method_argon2parameters_get_bytes( + ): Short + external fun uniffi_devolutions_crypto_uniffi_checksum_method_argon2parametersbuilder_associated_data( + ): Short + external fun uniffi_devolutions_crypto_uniffi_checksum_method_argon2parametersbuilder_build( + ): Short + external fun uniffi_devolutions_crypto_uniffi_checksum_method_argon2parametersbuilder_dc_version( + ): Short + external fun uniffi_devolutions_crypto_uniffi_checksum_method_argon2parametersbuilder_iterations( + ): Short + external fun uniffi_devolutions_crypto_uniffi_checksum_method_argon2parametersbuilder_lanes( + ): Short + external fun uniffi_devolutions_crypto_uniffi_checksum_method_argon2parametersbuilder_length( + ): Short + external fun uniffi_devolutions_crypto_uniffi_checksum_method_argon2parametersbuilder_memory( + ): Short + external fun uniffi_devolutions_crypto_uniffi_checksum_method_argon2parametersbuilder_salt( + ): Short + external fun uniffi_devolutions_crypto_uniffi_checksum_method_argon2parametersbuilder_secret_key( + ): Short + external fun uniffi_devolutions_crypto_uniffi_checksum_method_argon2parametersbuilder_variant( + ): Short + external fun uniffi_devolutions_crypto_uniffi_checksum_method_argon2parametersbuilder_version( + ): Short + external fun uniffi_devolutions_crypto_uniffi_checksum_method_signingkeypair_get_private_key( + ): Short + external fun uniffi_devolutions_crypto_uniffi_checksum_method_signingkeypair_get_public_key( + ): Short + external fun uniffi_devolutions_crypto_uniffi_checksum_constructor_argon2parameters_new_from_bytes( + ): Short + external fun uniffi_devolutions_crypto_uniffi_checksum_constructor_argon2parametersbuilder_new( + ): Short + external fun uniffi_devolutions_crypto_uniffi_checksum_constructor_signingkeypair_new_from_bytes( + ): Short + external fun ffi_devolutions_crypto_uniffi_uniffi_contract_version( + ): Int + + +} + +internal object UniffiLib { + + // The Cleaner for the whole library + internal val CLEANER: UniffiCleaner by lazy { + UniffiCleaner.create() + } + + + init { + Native.register(UniffiLib::class.java, findLibraryName(componentName = "devolutions_crypto_uniffi")) + uniffi.devolutions_crypto.uniffiEnsureInitialized() + + } + external fun uniffi_devolutions_crypto_uniffi_fn_clone_argon2parameters(`handle`: Long,uniffi_out_err: UniffiRustCallStatus, +): Long +external fun uniffi_devolutions_crypto_uniffi_fn_free_argon2parameters(`handle`: Long,uniffi_out_err: UniffiRustCallStatus, +): Unit +external fun uniffi_devolutions_crypto_uniffi_fn_constructor_argon2parameters_new_from_bytes(`data`: RustBuffer.ByValue,uniffi_out_err: UniffiRustCallStatus, +): Long +external fun uniffi_devolutions_crypto_uniffi_fn_method_argon2parameters_get_bytes(`ptr`: Long,uniffi_out_err: UniffiRustCallStatus, +): RustBuffer.ByValue +external fun uniffi_devolutions_crypto_uniffi_fn_clone_argon2parametersbuilder(`handle`: Long,uniffi_out_err: UniffiRustCallStatus, +): Long +external fun uniffi_devolutions_crypto_uniffi_fn_free_argon2parametersbuilder(`handle`: Long,uniffi_out_err: UniffiRustCallStatus, +): Unit +external fun uniffi_devolutions_crypto_uniffi_fn_constructor_argon2parametersbuilder_new(uniffi_out_err: UniffiRustCallStatus, +): Long +external fun uniffi_devolutions_crypto_uniffi_fn_method_argon2parametersbuilder_associated_data(`ptr`: Long,`value`: RustBuffer.ByValue,uniffi_out_err: UniffiRustCallStatus, +): Long +external fun uniffi_devolutions_crypto_uniffi_fn_method_argon2parametersbuilder_build(`ptr`: Long,uniffi_out_err: UniffiRustCallStatus, +): Long +external fun uniffi_devolutions_crypto_uniffi_fn_method_argon2parametersbuilder_dc_version(`ptr`: Long,`value`: Int,uniffi_out_err: UniffiRustCallStatus, +): Long +external fun uniffi_devolutions_crypto_uniffi_fn_method_argon2parametersbuilder_iterations(`ptr`: Long,`value`: Int,uniffi_out_err: UniffiRustCallStatus, +): Long +external fun uniffi_devolutions_crypto_uniffi_fn_method_argon2parametersbuilder_lanes(`ptr`: Long,`value`: Int,uniffi_out_err: UniffiRustCallStatus, +): Long +external fun uniffi_devolutions_crypto_uniffi_fn_method_argon2parametersbuilder_length(`ptr`: Long,`value`: Int,uniffi_out_err: UniffiRustCallStatus, +): Long +external fun uniffi_devolutions_crypto_uniffi_fn_method_argon2parametersbuilder_memory(`ptr`: Long,`value`: Int,uniffi_out_err: UniffiRustCallStatus, +): Long +external fun uniffi_devolutions_crypto_uniffi_fn_method_argon2parametersbuilder_salt(`ptr`: Long,`value`: RustBuffer.ByValue,uniffi_out_err: UniffiRustCallStatus, +): Long +external fun uniffi_devolutions_crypto_uniffi_fn_method_argon2parametersbuilder_secret_key(`ptr`: Long,`value`: RustBuffer.ByValue,uniffi_out_err: UniffiRustCallStatus, +): Long +external fun uniffi_devolutions_crypto_uniffi_fn_method_argon2parametersbuilder_variant(`ptr`: Long,`value`: RustBuffer.ByValue,uniffi_out_err: UniffiRustCallStatus, +): Long +external fun uniffi_devolutions_crypto_uniffi_fn_method_argon2parametersbuilder_version(`ptr`: Long,`value`: RustBuffer.ByValue,uniffi_out_err: UniffiRustCallStatus, +): Long +external fun uniffi_devolutions_crypto_uniffi_fn_clone_signingkeypair(`handle`: Long,uniffi_out_err: UniffiRustCallStatus, +): Long +external fun uniffi_devolutions_crypto_uniffi_fn_free_signingkeypair(`handle`: Long,uniffi_out_err: UniffiRustCallStatus, +): Unit +external fun uniffi_devolutions_crypto_uniffi_fn_constructor_signingkeypair_new_from_bytes(`data`: RustBuffer.ByValue,uniffi_out_err: UniffiRustCallStatus, +): Long +external fun uniffi_devolutions_crypto_uniffi_fn_method_signingkeypair_get_private_key(`ptr`: Long,uniffi_out_err: UniffiRustCallStatus, +): RustBuffer.ByValue +external fun uniffi_devolutions_crypto_uniffi_fn_method_signingkeypair_get_public_key(`ptr`: Long,uniffi_out_err: UniffiRustCallStatus, +): RustBuffer.ByValue +external fun uniffi_devolutions_crypto_uniffi_fn_func_base64_decode(`data`: RustBuffer.ByValue,uniffi_out_err: UniffiRustCallStatus, +): RustBuffer.ByValue +external fun uniffi_devolutions_crypto_uniffi_fn_func_base64_decode_url(`data`: RustBuffer.ByValue,uniffi_out_err: UniffiRustCallStatus, +): RustBuffer.ByValue +external fun uniffi_devolutions_crypto_uniffi_fn_func_base64_encode(`data`: RustBuffer.ByValue,uniffi_out_err: UniffiRustCallStatus, +): RustBuffer.ByValue +external fun uniffi_devolutions_crypto_uniffi_fn_func_base64_encode_url(`data`: RustBuffer.ByValue,uniffi_out_err: UniffiRustCallStatus, +): RustBuffer.ByValue +external fun uniffi_devolutions_crypto_uniffi_fn_func_decrypt(`data`: RustBuffer.ByValue,`key`: RustBuffer.ByValue,uniffi_out_err: UniffiRustCallStatus, +): RustBuffer.ByValue +external fun uniffi_devolutions_crypto_uniffi_fn_func_decrypt_asymmetric(`data`: RustBuffer.ByValue,`key`: RustBuffer.ByValue,uniffi_out_err: UniffiRustCallStatus, +): RustBuffer.ByValue +external fun uniffi_devolutions_crypto_uniffi_fn_func_decrypt_asymmetric_with_aad(`data`: RustBuffer.ByValue,`key`: RustBuffer.ByValue,`aad`: RustBuffer.ByValue,uniffi_out_err: UniffiRustCallStatus, +): RustBuffer.ByValue +external fun uniffi_devolutions_crypto_uniffi_fn_func_decrypt_with_aad(`data`: RustBuffer.ByValue,`key`: RustBuffer.ByValue,`aad`: RustBuffer.ByValue,uniffi_out_err: UniffiRustCallStatus, +): RustBuffer.ByValue +external fun uniffi_devolutions_crypto_uniffi_fn_func_derive_key_argon2(`key`: RustBuffer.ByValue,`parameters`: Long,uniffi_out_err: UniffiRustCallStatus, +): RustBuffer.ByValue +external fun uniffi_devolutions_crypto_uniffi_fn_func_derive_key_pbkdf2(`key`: RustBuffer.ByValue,`salt`: RustBuffer.ByValue,`iterations`: Int,`length`: Int,uniffi_out_err: UniffiRustCallStatus, +): RustBuffer.ByValue +external fun uniffi_devolutions_crypto_uniffi_fn_func_encrypt(`data`: RustBuffer.ByValue,`key`: RustBuffer.ByValue,`version`: RustBuffer.ByValue,uniffi_out_err: UniffiRustCallStatus, +): RustBuffer.ByValue +external fun uniffi_devolutions_crypto_uniffi_fn_func_encrypt_asymmetric(`data`: RustBuffer.ByValue,`key`: RustBuffer.ByValue,`version`: RustBuffer.ByValue,uniffi_out_err: UniffiRustCallStatus, +): RustBuffer.ByValue +external fun uniffi_devolutions_crypto_uniffi_fn_func_encrypt_asymmetric_with_aad(`data`: RustBuffer.ByValue,`key`: RustBuffer.ByValue,`aad`: RustBuffer.ByValue,`version`: RustBuffer.ByValue,uniffi_out_err: UniffiRustCallStatus, +): RustBuffer.ByValue +external fun uniffi_devolutions_crypto_uniffi_fn_func_encrypt_with_aad(`data`: RustBuffer.ByValue,`key`: RustBuffer.ByValue,`aad`: RustBuffer.ByValue,`version`: RustBuffer.ByValue,uniffi_out_err: UniffiRustCallStatus, +): RustBuffer.ByValue +external fun uniffi_devolutions_crypto_uniffi_fn_func_generate_key(`length`: Int,uniffi_out_err: UniffiRustCallStatus, +): RustBuffer.ByValue +external fun uniffi_devolutions_crypto_uniffi_fn_func_generate_keypair(`version`: RustBuffer.ByValue,uniffi_out_err: UniffiRustCallStatus, +): RustBuffer.ByValue +external fun uniffi_devolutions_crypto_uniffi_fn_func_generate_shared_key(`nShares`: Byte,`threshold`: Byte,`length`: Int,`version`: RustBuffer.ByValue,uniffi_out_err: UniffiRustCallStatus, +): RustBuffer.ByValue +external fun uniffi_devolutions_crypto_uniffi_fn_func_generate_signing_keypair(`version`: RustBuffer.ByValue,uniffi_out_err: UniffiRustCallStatus, +): Long +external fun uniffi_devolutions_crypto_uniffi_fn_func_hash_password(`password`: RustBuffer.ByValue,`iterations`: Int,`version`: RustBuffer.ByValue,uniffi_out_err: UniffiRustCallStatus, +): RustBuffer.ByValue +external fun uniffi_devolutions_crypto_uniffi_fn_func_join_shares(`shares`: RustBuffer.ByValue,uniffi_out_err: UniffiRustCallStatus, +): RustBuffer.ByValue +external fun uniffi_devolutions_crypto_uniffi_fn_func_mix_key_exchange(`privateKey`: RustBuffer.ByValue,`publicKey`: RustBuffer.ByValue,uniffi_out_err: UniffiRustCallStatus, +): RustBuffer.ByValue +external fun uniffi_devolutions_crypto_uniffi_fn_func_sign(`data`: RustBuffer.ByValue,`keypair`: RustBuffer.ByValue,`version`: RustBuffer.ByValue,uniffi_out_err: UniffiRustCallStatus, +): RustBuffer.ByValue +external fun uniffi_devolutions_crypto_uniffi_fn_func_validate_header(`data`: RustBuffer.ByValue,`dataType`: RustBufferDataType.ByValue,uniffi_out_err: UniffiRustCallStatus, +): Byte +external fun uniffi_devolutions_crypto_uniffi_fn_func_verify_password(`password`: RustBuffer.ByValue,`hash`: RustBuffer.ByValue,uniffi_out_err: UniffiRustCallStatus, +): Byte +external fun uniffi_devolutions_crypto_uniffi_fn_func_verify_signature(`data`: RustBuffer.ByValue,`publicKey`: RustBuffer.ByValue,`signature`: RustBuffer.ByValue,uniffi_out_err: UniffiRustCallStatus, +): Byte +external fun ffi_devolutions_crypto_uniffi_rustbuffer_alloc(`size`: Long,uniffi_out_err: UniffiRustCallStatus, +): RustBuffer.ByValue +external fun ffi_devolutions_crypto_uniffi_rustbuffer_from_bytes(`bytes`: ForeignBytes.ByValue,uniffi_out_err: UniffiRustCallStatus, +): RustBuffer.ByValue +external fun ffi_devolutions_crypto_uniffi_rustbuffer_free(`buf`: RustBuffer.ByValue,uniffi_out_err: UniffiRustCallStatus, +): Unit +external fun ffi_devolutions_crypto_uniffi_rustbuffer_reserve(`buf`: RustBuffer.ByValue,`additional`: Long,uniffi_out_err: UniffiRustCallStatus, +): RustBuffer.ByValue +external fun ffi_devolutions_crypto_uniffi_rust_future_poll_u8(`handle`: Long,`callback`: UniffiRustFutureContinuationCallback,`callbackData`: Long, +): Unit +external fun ffi_devolutions_crypto_uniffi_rust_future_cancel_u8(`handle`: Long, +): Unit +external fun ffi_devolutions_crypto_uniffi_rust_future_free_u8(`handle`: Long, +): Unit +external fun ffi_devolutions_crypto_uniffi_rust_future_complete_u8(`handle`: Long,uniffi_out_err: UniffiRustCallStatus, +): Byte +external fun ffi_devolutions_crypto_uniffi_rust_future_poll_i8(`handle`: Long,`callback`: UniffiRustFutureContinuationCallback,`callbackData`: Long, +): Unit +external fun ffi_devolutions_crypto_uniffi_rust_future_cancel_i8(`handle`: Long, +): Unit +external fun ffi_devolutions_crypto_uniffi_rust_future_free_i8(`handle`: Long, +): Unit +external fun ffi_devolutions_crypto_uniffi_rust_future_complete_i8(`handle`: Long,uniffi_out_err: UniffiRustCallStatus, +): Byte +external fun ffi_devolutions_crypto_uniffi_rust_future_poll_u16(`handle`: Long,`callback`: UniffiRustFutureContinuationCallback,`callbackData`: Long, +): Unit +external fun ffi_devolutions_crypto_uniffi_rust_future_cancel_u16(`handle`: Long, +): Unit +external fun ffi_devolutions_crypto_uniffi_rust_future_free_u16(`handle`: Long, +): Unit +external fun ffi_devolutions_crypto_uniffi_rust_future_complete_u16(`handle`: Long,uniffi_out_err: UniffiRustCallStatus, +): Short +external fun ffi_devolutions_crypto_uniffi_rust_future_poll_i16(`handle`: Long,`callback`: UniffiRustFutureContinuationCallback,`callbackData`: Long, +): Unit +external fun ffi_devolutions_crypto_uniffi_rust_future_cancel_i16(`handle`: Long, +): Unit +external fun ffi_devolutions_crypto_uniffi_rust_future_free_i16(`handle`: Long, +): Unit +external fun ffi_devolutions_crypto_uniffi_rust_future_complete_i16(`handle`: Long,uniffi_out_err: UniffiRustCallStatus, +): Short +external fun ffi_devolutions_crypto_uniffi_rust_future_poll_u32(`handle`: Long,`callback`: UniffiRustFutureContinuationCallback,`callbackData`: Long, +): Unit +external fun ffi_devolutions_crypto_uniffi_rust_future_cancel_u32(`handle`: Long, +): Unit +external fun ffi_devolutions_crypto_uniffi_rust_future_free_u32(`handle`: Long, +): Unit +external fun ffi_devolutions_crypto_uniffi_rust_future_complete_u32(`handle`: Long,uniffi_out_err: UniffiRustCallStatus, +): Int +external fun ffi_devolutions_crypto_uniffi_rust_future_poll_i32(`handle`: Long,`callback`: UniffiRustFutureContinuationCallback,`callbackData`: Long, +): Unit +external fun ffi_devolutions_crypto_uniffi_rust_future_cancel_i32(`handle`: Long, +): Unit +external fun ffi_devolutions_crypto_uniffi_rust_future_free_i32(`handle`: Long, +): Unit +external fun ffi_devolutions_crypto_uniffi_rust_future_complete_i32(`handle`: Long,uniffi_out_err: UniffiRustCallStatus, +): Int +external fun ffi_devolutions_crypto_uniffi_rust_future_poll_u64(`handle`: Long,`callback`: UniffiRustFutureContinuationCallback,`callbackData`: Long, +): Unit +external fun ffi_devolutions_crypto_uniffi_rust_future_cancel_u64(`handle`: Long, +): Unit +external fun ffi_devolutions_crypto_uniffi_rust_future_free_u64(`handle`: Long, +): Unit +external fun ffi_devolutions_crypto_uniffi_rust_future_complete_u64(`handle`: Long,uniffi_out_err: UniffiRustCallStatus, +): Long +external fun ffi_devolutions_crypto_uniffi_rust_future_poll_i64(`handle`: Long,`callback`: UniffiRustFutureContinuationCallback,`callbackData`: Long, +): Unit +external fun ffi_devolutions_crypto_uniffi_rust_future_cancel_i64(`handle`: Long, +): Unit +external fun ffi_devolutions_crypto_uniffi_rust_future_free_i64(`handle`: Long, +): Unit +external fun ffi_devolutions_crypto_uniffi_rust_future_complete_i64(`handle`: Long,uniffi_out_err: UniffiRustCallStatus, +): Long +external fun ffi_devolutions_crypto_uniffi_rust_future_poll_f32(`handle`: Long,`callback`: UniffiRustFutureContinuationCallback,`callbackData`: Long, +): Unit +external fun ffi_devolutions_crypto_uniffi_rust_future_cancel_f32(`handle`: Long, +): Unit +external fun ffi_devolutions_crypto_uniffi_rust_future_free_f32(`handle`: Long, +): Unit +external fun ffi_devolutions_crypto_uniffi_rust_future_complete_f32(`handle`: Long,uniffi_out_err: UniffiRustCallStatus, +): Float +external fun ffi_devolutions_crypto_uniffi_rust_future_poll_f64(`handle`: Long,`callback`: UniffiRustFutureContinuationCallback,`callbackData`: Long, +): Unit +external fun ffi_devolutions_crypto_uniffi_rust_future_cancel_f64(`handle`: Long, +): Unit +external fun ffi_devolutions_crypto_uniffi_rust_future_free_f64(`handle`: Long, +): Unit +external fun ffi_devolutions_crypto_uniffi_rust_future_complete_f64(`handle`: Long,uniffi_out_err: UniffiRustCallStatus, +): Double +external fun ffi_devolutions_crypto_uniffi_rust_future_poll_rust_buffer(`handle`: Long,`callback`: UniffiRustFutureContinuationCallback,`callbackData`: Long, +): Unit +external fun ffi_devolutions_crypto_uniffi_rust_future_cancel_rust_buffer(`handle`: Long, +): Unit +external fun ffi_devolutions_crypto_uniffi_rust_future_free_rust_buffer(`handle`: Long, +): Unit +external fun ffi_devolutions_crypto_uniffi_rust_future_complete_rust_buffer(`handle`: Long,uniffi_out_err: UniffiRustCallStatus, +): RustBuffer.ByValue +external fun ffi_devolutions_crypto_uniffi_rust_future_poll_void(`handle`: Long,`callback`: UniffiRustFutureContinuationCallback,`callbackData`: Long, +): Unit +external fun ffi_devolutions_crypto_uniffi_rust_future_cancel_void(`handle`: Long, +): Unit +external fun ffi_devolutions_crypto_uniffi_rust_future_free_void(`handle`: Long, +): Unit +external fun ffi_devolutions_crypto_uniffi_rust_future_complete_void(`handle`: Long,uniffi_out_err: UniffiRustCallStatus, +): Unit + + +} + +private fun uniffiCheckContractApiVersion(lib: IntegrityCheckingUniffiLib) { + // Get the bindings contract version from our ComponentInterface + val bindings_contract_version = 30 + // Get the scaffolding contract version by calling the into the dylib + val scaffolding_contract_version = lib.ffi_devolutions_crypto_uniffi_uniffi_contract_version() + if (bindings_contract_version != scaffolding_contract_version) { + throw RuntimeException("UniFFI contract version mismatch: try cleaning and rebuilding your project") + } +} +@Suppress("UNUSED_PARAMETER") +private fun uniffiCheckApiChecksums(lib: IntegrityCheckingUniffiLib) { + if (lib.uniffi_devolutions_crypto_uniffi_checksum_func_base64_decode() != 15059.toShort()) { + throw RuntimeException("UniFFI API checksum mismatch: try cleaning and rebuilding your project") + } + if (lib.uniffi_devolutions_crypto_uniffi_checksum_func_base64_decode_url() != 15429.toShort()) { + throw RuntimeException("UniFFI API checksum mismatch: try cleaning and rebuilding your project") + } + if (lib.uniffi_devolutions_crypto_uniffi_checksum_func_base64_encode() != 61134.toShort()) { + throw RuntimeException("UniFFI API checksum mismatch: try cleaning and rebuilding your project") + } + if (lib.uniffi_devolutions_crypto_uniffi_checksum_func_base64_encode_url() != 31513.toShort()) { + throw RuntimeException("UniFFI API checksum mismatch: try cleaning and rebuilding your project") + } + if (lib.uniffi_devolutions_crypto_uniffi_checksum_func_decrypt() != 39921.toShort()) { + throw RuntimeException("UniFFI API checksum mismatch: try cleaning and rebuilding your project") + } + if (lib.uniffi_devolutions_crypto_uniffi_checksum_func_decrypt_asymmetric() != 6283.toShort()) { + throw RuntimeException("UniFFI API checksum mismatch: try cleaning and rebuilding your project") + } + if (lib.uniffi_devolutions_crypto_uniffi_checksum_func_decrypt_asymmetric_with_aad() != 45166.toShort()) { + throw RuntimeException("UniFFI API checksum mismatch: try cleaning and rebuilding your project") + } + if (lib.uniffi_devolutions_crypto_uniffi_checksum_func_decrypt_with_aad() != 43775.toShort()) { + throw RuntimeException("UniFFI API checksum mismatch: try cleaning and rebuilding your project") + } + if (lib.uniffi_devolutions_crypto_uniffi_checksum_func_derive_key_argon2() != 27403.toShort()) { + throw RuntimeException("UniFFI API checksum mismatch: try cleaning and rebuilding your project") + } + if (lib.uniffi_devolutions_crypto_uniffi_checksum_func_derive_key_pbkdf2() != 32212.toShort()) { + throw RuntimeException("UniFFI API checksum mismatch: try cleaning and rebuilding your project") + } + if (lib.uniffi_devolutions_crypto_uniffi_checksum_func_encrypt() != 28651.toShort()) { + throw RuntimeException("UniFFI API checksum mismatch: try cleaning and rebuilding your project") + } + if (lib.uniffi_devolutions_crypto_uniffi_checksum_func_encrypt_asymmetric() != 17008.toShort()) { + throw RuntimeException("UniFFI API checksum mismatch: try cleaning and rebuilding your project") + } + if (lib.uniffi_devolutions_crypto_uniffi_checksum_func_encrypt_asymmetric_with_aad() != 61461.toShort()) { + throw RuntimeException("UniFFI API checksum mismatch: try cleaning and rebuilding your project") + } + if (lib.uniffi_devolutions_crypto_uniffi_checksum_func_encrypt_with_aad() != 29699.toShort()) { + throw RuntimeException("UniFFI API checksum mismatch: try cleaning and rebuilding your project") + } + if (lib.uniffi_devolutions_crypto_uniffi_checksum_func_generate_key() != 29427.toShort()) { + throw RuntimeException("UniFFI API checksum mismatch: try cleaning and rebuilding your project") + } + if (lib.uniffi_devolutions_crypto_uniffi_checksum_func_generate_keypair() != 38891.toShort()) { + throw RuntimeException("UniFFI API checksum mismatch: try cleaning and rebuilding your project") + } + if (lib.uniffi_devolutions_crypto_uniffi_checksum_func_generate_shared_key() != 57051.toShort()) { + throw RuntimeException("UniFFI API checksum mismatch: try cleaning and rebuilding your project") + } + if (lib.uniffi_devolutions_crypto_uniffi_checksum_func_generate_signing_keypair() != 51146.toShort()) { + throw RuntimeException("UniFFI API checksum mismatch: try cleaning and rebuilding your project") + } + if (lib.uniffi_devolutions_crypto_uniffi_checksum_func_hash_password() != 12769.toShort()) { + throw RuntimeException("UniFFI API checksum mismatch: try cleaning and rebuilding your project") + } + if (lib.uniffi_devolutions_crypto_uniffi_checksum_func_join_shares() != 65529.toShort()) { + throw RuntimeException("UniFFI API checksum mismatch: try cleaning and rebuilding your project") + } + if (lib.uniffi_devolutions_crypto_uniffi_checksum_func_mix_key_exchange() != 21197.toShort()) { + throw RuntimeException("UniFFI API checksum mismatch: try cleaning and rebuilding your project") + } + if (lib.uniffi_devolutions_crypto_uniffi_checksum_func_sign() != 42756.toShort()) { + throw RuntimeException("UniFFI API checksum mismatch: try cleaning and rebuilding your project") + } + if (lib.uniffi_devolutions_crypto_uniffi_checksum_func_validate_header() != 53669.toShort()) { + throw RuntimeException("UniFFI API checksum mismatch: try cleaning and rebuilding your project") + } + if (lib.uniffi_devolutions_crypto_uniffi_checksum_func_verify_password() != 7704.toShort()) { + throw RuntimeException("UniFFI API checksum mismatch: try cleaning and rebuilding your project") + } + if (lib.uniffi_devolutions_crypto_uniffi_checksum_func_verify_signature() != 51084.toShort()) { + throw RuntimeException("UniFFI API checksum mismatch: try cleaning and rebuilding your project") + } + if (lib.uniffi_devolutions_crypto_uniffi_checksum_method_argon2parameters_get_bytes() != 26758.toShort()) { + throw RuntimeException("UniFFI API checksum mismatch: try cleaning and rebuilding your project") + } + if (lib.uniffi_devolutions_crypto_uniffi_checksum_method_argon2parametersbuilder_associated_data() != 27028.toShort()) { + throw RuntimeException("UniFFI API checksum mismatch: try cleaning and rebuilding your project") + } + if (lib.uniffi_devolutions_crypto_uniffi_checksum_method_argon2parametersbuilder_build() != 8751.toShort()) { + throw RuntimeException("UniFFI API checksum mismatch: try cleaning and rebuilding your project") + } + if (lib.uniffi_devolutions_crypto_uniffi_checksum_method_argon2parametersbuilder_dc_version() != 35235.toShort()) { + throw RuntimeException("UniFFI API checksum mismatch: try cleaning and rebuilding your project") + } + if (lib.uniffi_devolutions_crypto_uniffi_checksum_method_argon2parametersbuilder_iterations() != 15990.toShort()) { + throw RuntimeException("UniFFI API checksum mismatch: try cleaning and rebuilding your project") + } + if (lib.uniffi_devolutions_crypto_uniffi_checksum_method_argon2parametersbuilder_lanes() != 57040.toShort()) { + throw RuntimeException("UniFFI API checksum mismatch: try cleaning and rebuilding your project") + } + if (lib.uniffi_devolutions_crypto_uniffi_checksum_method_argon2parametersbuilder_length() != 65258.toShort()) { + throw RuntimeException("UniFFI API checksum mismatch: try cleaning and rebuilding your project") + } + if (lib.uniffi_devolutions_crypto_uniffi_checksum_method_argon2parametersbuilder_memory() != 41617.toShort()) { + throw RuntimeException("UniFFI API checksum mismatch: try cleaning and rebuilding your project") + } + if (lib.uniffi_devolutions_crypto_uniffi_checksum_method_argon2parametersbuilder_salt() != 5080.toShort()) { + throw RuntimeException("UniFFI API checksum mismatch: try cleaning and rebuilding your project") + } + if (lib.uniffi_devolutions_crypto_uniffi_checksum_method_argon2parametersbuilder_secret_key() != 14932.toShort()) { + throw RuntimeException("UniFFI API checksum mismatch: try cleaning and rebuilding your project") + } + if (lib.uniffi_devolutions_crypto_uniffi_checksum_method_argon2parametersbuilder_variant() != 48907.toShort()) { + throw RuntimeException("UniFFI API checksum mismatch: try cleaning and rebuilding your project") + } + if (lib.uniffi_devolutions_crypto_uniffi_checksum_method_argon2parametersbuilder_version() != 31568.toShort()) { + throw RuntimeException("UniFFI API checksum mismatch: try cleaning and rebuilding your project") + } + if (lib.uniffi_devolutions_crypto_uniffi_checksum_method_signingkeypair_get_private_key() != 2977.toShort()) { + throw RuntimeException("UniFFI API checksum mismatch: try cleaning and rebuilding your project") + } + if (lib.uniffi_devolutions_crypto_uniffi_checksum_method_signingkeypair_get_public_key() != 50462.toShort()) { + throw RuntimeException("UniFFI API checksum mismatch: try cleaning and rebuilding your project") + } + if (lib.uniffi_devolutions_crypto_uniffi_checksum_constructor_argon2parameters_new_from_bytes() != 58986.toShort()) { + throw RuntimeException("UniFFI API checksum mismatch: try cleaning and rebuilding your project") + } + if (lib.uniffi_devolutions_crypto_uniffi_checksum_constructor_argon2parametersbuilder_new() != 40769.toShort()) { + throw RuntimeException("UniFFI API checksum mismatch: try cleaning and rebuilding your project") + } + if (lib.uniffi_devolutions_crypto_uniffi_checksum_constructor_signingkeypair_new_from_bytes() != 59560.toShort()) { + throw RuntimeException("UniFFI API checksum mismatch: try cleaning and rebuilding your project") + } +} + +/** + * @suppress + */ +public fun uniffiEnsureInitialized() { + IntegrityCheckingUniffiLib + // UniffiLib() initialized as objects are used, but we still need to explicitly + // reference it so initialization across crates works as expected. + UniffiLib +} + +// Async support + +// Public interface members begin here. + + +// Interface implemented by anything that can contain an object reference. +// +// Such types expose a `destroy()` method that must be called to cleanly +// dispose of the contained objects. Failure to call this method may result +// in memory leaks. +// +// The easiest way to ensure this method is called is to use the `.use` +// helper method to execute a block and destroy the object at the end. +interface Disposable { + fun destroy() + companion object { + fun destroy(vararg args: Any?) { + for (arg in args) { + when (arg) { + is Disposable -> arg.destroy() + is ArrayList<*> -> { + for (idx in arg.indices) { + val element = arg[idx] + if (element is Disposable) { + element.destroy() + } + } + } + is Map<*, *> -> { + for (element in arg.values) { + if (element is Disposable) { + element.destroy() + } + } + } + is Iterable<*> -> { + for (element in arg) { + if (element is Disposable) { + element.destroy() + } + } + } + } + } + } + } +} + +/** + * @suppress + */ +inline fun T.use(block: (T) -> R) = + try { + block(this) + } finally { + try { + // N.B. our implementation is on the nullable type `Disposable?`. + this?.destroy() + } catch (e: Throwable) { + // swallow + } + } + +/** + * Placeholder object used to signal that we're constructing an interface with a FFI handle. + * + * This is the first argument for interface constructors that input a raw handle. It exists is that + * so we can avoid signature conflicts when an interface has a regular constructor than inputs a + * Long. + * + * @suppress + * */ +object UniffiWithHandle + +/** + * Used to instantiate an interface without an actual pointer, for fakes in tests, mostly. + * + * @suppress + * */ +object NoHandle +/** + * The cleaner interface for Object finalization code to run. + * This is the entry point to any implementation that we're using. + * + * The cleaner registers objects and returns cleanables, so now we are + * defining a `UniffiCleaner` with a `UniffiClenaer.Cleanable` to abstract the + * different implmentations available at compile time. + * + * @suppress + */ +interface UniffiCleaner { + interface Cleanable { + fun clean() + } + + fun register(value: Any, cleanUpTask: Runnable): UniffiCleaner.Cleanable + + companion object +} + +// The fallback Jna cleaner, which is available for both Android, and the JVM. +private class UniffiJnaCleaner : UniffiCleaner { + private val cleaner = com.sun.jna.internal.Cleaner.getCleaner() + + override fun register(value: Any, cleanUpTask: Runnable): UniffiCleaner.Cleanable = + UniffiJnaCleanable(cleaner.register(value, cleanUpTask)) +} + +private class UniffiJnaCleanable( + private val cleanable: com.sun.jna.internal.Cleaner.Cleanable, +) : UniffiCleaner.Cleanable { + override fun clean() = cleanable.clean() +} + + +// We decide at uniffi binding generation time whether we were +// using Android or not. +// There are further runtime checks to chose the correct implementation +// of the cleaner. +private fun UniffiCleaner.Companion.create(): UniffiCleaner = + try { + // For safety's sake: if the library hasn't been run in android_cleaner = true + // mode, but is being run on Android, then we still need to think about + // Android API versions. + // So we check if java.lang.ref.Cleaner is there, and use that… + java.lang.Class.forName("java.lang.ref.Cleaner") + JavaLangRefCleaner() + } catch (e: ClassNotFoundException) { + // … otherwise, fallback to the JNA cleaner. + UniffiJnaCleaner() + } + +private class JavaLangRefCleaner : UniffiCleaner { + val cleaner = java.lang.ref.Cleaner.create() + + override fun register(value: Any, cleanUpTask: Runnable): UniffiCleaner.Cleanable = + JavaLangRefCleanable(cleaner.register(value, cleanUpTask)) +} + +private class JavaLangRefCleanable( + val cleanable: java.lang.ref.Cleaner.Cleanable +) : UniffiCleaner.Cleanable { + override fun clean() = cleanable.clean() +} + +/** + * @suppress + */ +public object FfiConverterUByte: FfiConverter { + override fun lift(value: Byte): UByte { + return value.toUByte() + } + + override fun read(buf: ByteBuffer): UByte { + return lift(buf.get()) + } + + override fun lower(value: UByte): Byte { + return value.toByte() + } + + override fun allocationSize(value: UByte) = 1UL + + override fun write(value: UByte, buf: ByteBuffer) { + buf.put(value.toByte()) + } +} + +/** + * @suppress + */ +public object FfiConverterUInt: FfiConverter { + override fun lift(value: Int): UInt { + return value.toUInt() + } + + override fun read(buf: ByteBuffer): UInt { + return lift(buf.getInt()) + } + + override fun lower(value: UInt): Int { + return value.toInt() + } + + override fun allocationSize(value: UInt) = 4UL + + override fun write(value: UInt, buf: ByteBuffer) { + buf.putInt(value.toInt()) + } +} + +/** + * @suppress + */ +public object FfiConverterBoolean: FfiConverter { + override fun lift(value: Byte): Boolean { + return value.toInt() != 0 + } + + override fun read(buf: ByteBuffer): Boolean { + return lift(buf.get()) + } + + override fun lower(value: Boolean): Byte { + return if (value) 1.toByte() else 0.toByte() + } + + override fun allocationSize(value: Boolean) = 1UL + + override fun write(value: Boolean, buf: ByteBuffer) { + buf.put(lower(value)) + } +} + +/** + * @suppress + */ +public object FfiConverterString: FfiConverter { + // Note: we don't inherit from FfiConverterRustBuffer, because we use a + // special encoding when lowering/lifting. We can use `RustBuffer.len` to + // store our length and avoid writing it out to the buffer. + override fun lift(value: RustBuffer.ByValue): String { + try { + val byteArr = ByteArray(value.len.toInt()) + value.asByteBuffer()!!.get(byteArr) + return byteArr.toString(Charsets.UTF_8) + } finally { + RustBuffer.free(value) + } + } + + override fun read(buf: ByteBuffer): String { + val len = buf.getInt() + val byteArr = ByteArray(len) + buf.get(byteArr) + return byteArr.toString(Charsets.UTF_8) + } + + fun toUtf8(value: String): ByteBuffer { + // Make sure we don't have invalid UTF-16, check for lone surrogates. + return Charsets.UTF_8.newEncoder().run { + onMalformedInput(CodingErrorAction.REPORT) + encode(CharBuffer.wrap(value)) + } + } + + override fun lower(value: String): RustBuffer.ByValue { + val byteBuf = toUtf8(value) + // Ideally we'd pass these bytes to `ffi_bytebuffer_from_bytes`, but doing so would require us + // to copy them into a JNA `Memory`. So we might as well directly copy them into a `RustBuffer`. + val rbuf = RustBuffer.alloc(byteBuf.limit().toULong()) + rbuf.asByteBuffer()!!.put(byteBuf) + return rbuf + } + + // We aren't sure exactly how many bytes our string will be once it's UTF-8 + // encoded. Allocate 3 bytes per UTF-16 code unit which will always be + // enough. + override fun allocationSize(value: String): ULong { + val sizeForLength = 4UL + val sizeForString = value.length.toULong() * 3UL + return sizeForLength + sizeForString + } + + override fun write(value: String, buf: ByteBuffer) { + val byteBuf = toUtf8(value) + buf.putInt(byteBuf.limit()) + buf.put(byteBuf) + } +} + +/** + * @suppress + */ +public object FfiConverterByteArray: FfiConverterRustBuffer { + override fun read(buf: ByteBuffer): ByteArray { + val len = buf.getInt() + val byteArr = ByteArray(len) + buf.get(byteArr) + return byteArr + } + override fun allocationSize(value: ByteArray): ULong { + return 4UL + value.size.toULong() + } + override fun write(value: ByteArray, buf: ByteBuffer) { + buf.putInt(value.size) + buf.put(value) + } +} + + +// This template implements a class for working with a Rust struct via a handle +// to the live Rust struct on the other side of the FFI. +// +// There's some subtlety here, because we have to be careful not to operate on a Rust +// struct after it has been dropped, and because we must expose a public API for freeing +// theq Kotlin wrapper object in lieu of reliable finalizers. The core requirements are: +// +// * Each instance holds an opaque handle to the underlying Rust struct. +// Method calls need to read this handle from the object's state and pass it in to +// the Rust FFI. +// +// * When an instance is no longer needed, its handle should be passed to a +// special destructor function provided by the Rust FFI, which will drop the +// underlying Rust struct. +// +// * Given an instance, calling code is expected to call the special +// `destroy` method in order to free it after use, either by calling it explicitly +// or by using a higher-level helper like the `use` method. Failing to do so risks +// leaking the underlying Rust struct. +// +// * We can't assume that calling code will do the right thing, and must be prepared +// to handle Kotlin method calls executing concurrently with or even after a call to +// `destroy`, and to handle multiple (possibly concurrent!) calls to `destroy`. +// +// * We must never allow Rust code to operate on the underlying Rust struct after +// the destructor has been called, and must never call the destructor more than once. +// Doing so may trigger memory unsafety. +// +// * To mitigate many of the risks of leaking memory and use-after-free unsafety, a `Cleaner` +// is implemented to call the destructor when the Kotlin object becomes unreachable. +// This is done in a background thread. This is not a panacea, and client code should be aware that +// 1. the thread may starve if some there are objects that have poorly performing +// `drop` methods or do significant work in their `drop` methods. +// 2. the thread is shared across the whole library. This can be tuned by using `android_cleaner = true`, +// or `android = true` in the [`kotlin` section of the `uniffi.toml` file](https://mozilla.github.io/uniffi-rs/kotlin/configuration.html). +// +// If we try to implement this with mutual exclusion on access to the handle, there is the +// possibility of a race between a method call and a concurrent call to `destroy`: +// +// * Thread A starts a method call, reads the value of the handle, but is interrupted +// before it can pass the handle over the FFI to Rust. +// * Thread B calls `destroy` and frees the underlying Rust struct. +// * Thread A resumes, passing the already-read handle value to Rust and triggering +// a use-after-free. +// +// One possible solution would be to use a `ReadWriteLock`, with each method call taking +// a read lock (and thus allowed to run concurrently) and the special `destroy` method +// taking a write lock (and thus blocking on live method calls). However, we aim not to +// generate methods with any hidden blocking semantics, and a `destroy` method that might +// block if called incorrectly seems to meet that bar. +// +// So, we achieve our goals by giving each instance an associated `AtomicLong` counter to track +// the number of in-flight method calls, and an `AtomicBoolean` flag to indicate whether `destroy` +// has been called. These are updated according to the following rules: +// +// * The initial value of the counter is 1, indicating a live object with no in-flight calls. +// The initial value for the flag is false. +// +// * At the start of each method call, we atomically check the counter. +// If it is 0 then the underlying Rust struct has already been destroyed and the call is aborted. +// If it is nonzero them we atomically increment it by 1 and proceed with the method call. +// +// * At the end of each method call, we atomically decrement and check the counter. +// If it has reached zero then we destroy the underlying Rust struct. +// +// * When `destroy` is called, we atomically flip the flag from false to true. +// If the flag was already true we silently fail. +// Otherwise we atomically decrement and check the counter. +// If it has reached zero then we destroy the underlying Rust struct. +// +// Astute readers may observe that this all sounds very similar to the way that Rust's `Arc` works, +// and indeed it is, with the addition of a flag to guard against multiple calls to `destroy`. +// +// The overall effect is that the underlying Rust struct is destroyed only when `destroy` has been +// called *and* all in-flight method calls have completed, avoiding violating any of the expectations +// of the underlying Rust code. +// +// This makes a cleaner a better alternative to _not_ calling `destroy()` as +// and when the object is finished with, but the abstraction is not perfect: if the Rust object's `drop` +// method is slow, and/or there are many objects to cleanup, and it's on a low end Android device, then the cleaner +// thread may be starved, and the app will leak memory. +// +// In this case, `destroy`ing manually may be a better solution. +// +// The cleaner can live side by side with the manual calling of `destroy`. In the order of responsiveness, uniffi objects +// with Rust peers are reclaimed: +// +// 1. By calling the `destroy` method of the object, which calls `rustObject.free()`. If that doesn't happen: +// 2. When the object becomes unreachable, AND the Cleaner thread gets to call `rustObject.free()`. If the thread is starved then: +// 3. The memory is reclaimed when the process terminates. +// +// [1] https://stackoverflow.com/questions/24376768/can-java-finalize-an-object-when-it-is-still-in-scope/24380219 +// + + +// +public interface Argon2ParametersInterface { + + fun `getBytes`(): kotlin.ByteArray + + companion object +} + +open class Argon2Parameters: Disposable, AutoCloseable, Argon2ParametersInterface +{ + + @Suppress("UNUSED_PARAMETER") + /** + * @suppress + */ + constructor(withHandle: UniffiWithHandle, handle: Long) { + this.handle = handle + this.cleanable = UniffiLib.CLEANER.register(this, UniffiCleanAction(handle)) + } + + /** + * @suppress + * + * This constructor can be used to instantiate a fake object. Only used for tests. Any + * attempt to actually use an object constructed this way will fail as there is no + * connected Rust object. + */ + @Suppress("UNUSED_PARAMETER") + constructor(noHandle: NoHandle) { + this.handle = 0 + this.cleanable = UniffiLib.CLEANER.register(this, UniffiCleanAction(handle)) + } + + protected val handle: Long + protected val cleanable: UniffiCleaner.Cleanable + + private val wasDestroyed = AtomicBoolean(false) + private val callCounter = AtomicLong(1) + + override fun destroy() { + // Only allow a single call to this method. + // TODO: maybe we should log a warning if called more than once? + if (this.wasDestroyed.compareAndSet(false, true)) { + // This decrement always matches the initial count of 1 given at creation time. + if (this.callCounter.decrementAndGet() == 0L) { + cleanable.clean() + } + } + } + + @Synchronized + override fun close() { + this.destroy() + } + + internal inline fun callWithHandle(block: (handle: Long) -> R): R { + // Check and increment the call counter, to keep the object alive. + // This needs a compare-and-set retry loop in case of concurrent updates. + do { + val c = this.callCounter.get() + if (c == 0L) { + throw IllegalStateException("${this.javaClass.simpleName} object has already been destroyed") + } + if (c == Long.MAX_VALUE) { + throw IllegalStateException("${this.javaClass.simpleName} call counter would overflow") + } + } while (! this.callCounter.compareAndSet(c, c + 1L)) + // Now we can safely do the method call without the handle being freed concurrently. + try { + return block(this.uniffiCloneHandle()) + } finally { + // This decrement always matches the increment we performed above. + if (this.callCounter.decrementAndGet() == 0L) { + cleanable.clean() + } + } + } + + // Use a static inner class instead of a closure so as not to accidentally + // capture `this` as part of the cleanable's action. + private class UniffiCleanAction(private val handle: Long) : Runnable { + override fun run() { + if (handle == 0.toLong()) { + // Fake object created with `NoHandle`, don't try to free. + return; + } + uniffiRustCall { status -> + UniffiLib.uniffi_devolutions_crypto_uniffi_fn_free_argon2parameters(handle, status) + } + } + } + + /** + * @suppress + */ + fun uniffiCloneHandle(): Long { + if (handle == 0.toLong()) { + throw InternalException("uniffiCloneHandle() called on NoHandle object"); + } + return uniffiRustCall() { status -> + UniffiLib.uniffi_devolutions_crypto_uniffi_fn_clone_argon2parameters(handle, status) + } + } + + override fun `getBytes`(): kotlin.ByteArray { + return FfiConverterByteArray.lift( + callWithHandle { + uniffiRustCall() { _status -> + UniffiLib.uniffi_devolutions_crypto_uniffi_fn_method_argon2parameters_get_bytes( + it, + _status) +} + } + ) + } + + + + + + + + + companion object { + + @Throws(Exception::class) fun `newFromBytes`(`data`: kotlin.ByteArray): Argon2Parameters { + return FfiConverterTypeArgon2Parameters.lift( + uniffiRustCallWithError(ExceptionExternalErrorHandler) { _status -> + UniffiLib.uniffi_devolutions_crypto_uniffi_fn_constructor_argon2parameters_new_from_bytes( + + FfiConverterByteArray.lower(`data`),_status) +} + ) + } + + + + } + +} + + +/** + * @suppress + */ +public object FfiConverterTypeArgon2Parameters: FfiConverter { + override fun lower(value: Argon2Parameters): Long { + return value.uniffiCloneHandle() + } + + override fun lift(value: Long): Argon2Parameters { + return Argon2Parameters(UniffiWithHandle, value) + } + + override fun read(buf: ByteBuffer): Argon2Parameters { + return lift(buf.getLong()) + } + + override fun allocationSize(value: Argon2Parameters) = 8UL + + override fun write(value: Argon2Parameters, buf: ByteBuffer) { + buf.putLong(lower(value)) + } +} + + +// This template implements a class for working with a Rust struct via a handle +// to the live Rust struct on the other side of the FFI. +// +// There's some subtlety here, because we have to be careful not to operate on a Rust +// struct after it has been dropped, and because we must expose a public API for freeing +// theq Kotlin wrapper object in lieu of reliable finalizers. The core requirements are: +// +// * Each instance holds an opaque handle to the underlying Rust struct. +// Method calls need to read this handle from the object's state and pass it in to +// the Rust FFI. +// +// * When an instance is no longer needed, its handle should be passed to a +// special destructor function provided by the Rust FFI, which will drop the +// underlying Rust struct. +// +// * Given an instance, calling code is expected to call the special +// `destroy` method in order to free it after use, either by calling it explicitly +// or by using a higher-level helper like the `use` method. Failing to do so risks +// leaking the underlying Rust struct. +// +// * We can't assume that calling code will do the right thing, and must be prepared +// to handle Kotlin method calls executing concurrently with or even after a call to +// `destroy`, and to handle multiple (possibly concurrent!) calls to `destroy`. +// +// * We must never allow Rust code to operate on the underlying Rust struct after +// the destructor has been called, and must never call the destructor more than once. +// Doing so may trigger memory unsafety. +// +// * To mitigate many of the risks of leaking memory and use-after-free unsafety, a `Cleaner` +// is implemented to call the destructor when the Kotlin object becomes unreachable. +// This is done in a background thread. This is not a panacea, and client code should be aware that +// 1. the thread may starve if some there are objects that have poorly performing +// `drop` methods or do significant work in their `drop` methods. +// 2. the thread is shared across the whole library. This can be tuned by using `android_cleaner = true`, +// or `android = true` in the [`kotlin` section of the `uniffi.toml` file](https://mozilla.github.io/uniffi-rs/kotlin/configuration.html). +// +// If we try to implement this with mutual exclusion on access to the handle, there is the +// possibility of a race between a method call and a concurrent call to `destroy`: +// +// * Thread A starts a method call, reads the value of the handle, but is interrupted +// before it can pass the handle over the FFI to Rust. +// * Thread B calls `destroy` and frees the underlying Rust struct. +// * Thread A resumes, passing the already-read handle value to Rust and triggering +// a use-after-free. +// +// One possible solution would be to use a `ReadWriteLock`, with each method call taking +// a read lock (and thus allowed to run concurrently) and the special `destroy` method +// taking a write lock (and thus blocking on live method calls). However, we aim not to +// generate methods with any hidden blocking semantics, and a `destroy` method that might +// block if called incorrectly seems to meet that bar. +// +// So, we achieve our goals by giving each instance an associated `AtomicLong` counter to track +// the number of in-flight method calls, and an `AtomicBoolean` flag to indicate whether `destroy` +// has been called. These are updated according to the following rules: +// +// * The initial value of the counter is 1, indicating a live object with no in-flight calls. +// The initial value for the flag is false. +// +// * At the start of each method call, we atomically check the counter. +// If it is 0 then the underlying Rust struct has already been destroyed and the call is aborted. +// If it is nonzero them we atomically increment it by 1 and proceed with the method call. +// +// * At the end of each method call, we atomically decrement and check the counter. +// If it has reached zero then we destroy the underlying Rust struct. +// +// * When `destroy` is called, we atomically flip the flag from false to true. +// If the flag was already true we silently fail. +// Otherwise we atomically decrement and check the counter. +// If it has reached zero then we destroy the underlying Rust struct. +// +// Astute readers may observe that this all sounds very similar to the way that Rust's `Arc` works, +// and indeed it is, with the addition of a flag to guard against multiple calls to `destroy`. +// +// The overall effect is that the underlying Rust struct is destroyed only when `destroy` has been +// called *and* all in-flight method calls have completed, avoiding violating any of the expectations +// of the underlying Rust code. +// +// This makes a cleaner a better alternative to _not_ calling `destroy()` as +// and when the object is finished with, but the abstraction is not perfect: if the Rust object's `drop` +// method is slow, and/or there are many objects to cleanup, and it's on a low end Android device, then the cleaner +// thread may be starved, and the app will leak memory. +// +// In this case, `destroy`ing manually may be a better solution. +// +// The cleaner can live side by side with the manual calling of `destroy`. In the order of responsiveness, uniffi objects +// with Rust peers are reclaimed: +// +// 1. By calling the `destroy` method of the object, which calls `rustObject.free()`. If that doesn't happen: +// 2. When the object becomes unreachable, AND the Cleaner thread gets to call `rustObject.free()`. If the thread is starved then: +// 3. The memory is reclaimed when the process terminates. +// +// [1] https://stackoverflow.com/questions/24376768/can-java-finalize-an-object-when-it-is-still-in-scope/24380219 +// + + +// +public interface Argon2ParametersBuilderInterface { + + fun `associatedData`(`value`: kotlin.ByteArray): Argon2ParametersBuilder + + fun `build`(): Argon2Parameters + + fun `dcVersion`(`value`: kotlin.UInt): Argon2ParametersBuilder + + fun `iterations`(`value`: kotlin.UInt): Argon2ParametersBuilder + + fun `lanes`(`value`: kotlin.UInt): Argon2ParametersBuilder + + fun `length`(`value`: kotlin.UInt): Argon2ParametersBuilder + + fun `memory`(`value`: kotlin.UInt): Argon2ParametersBuilder + + fun `salt`(`value`: kotlin.ByteArray): Argon2ParametersBuilder + + fun `secretKey`(`value`: kotlin.ByteArray): Argon2ParametersBuilder + + fun `variant`(`value`: Argon2Variant): Argon2ParametersBuilder + + fun `version`(`value`: Argon2Version): Argon2ParametersBuilder + + companion object +} + +open class Argon2ParametersBuilder: Disposable, AutoCloseable, Argon2ParametersBuilderInterface +{ + + @Suppress("UNUSED_PARAMETER") + /** + * @suppress + */ + constructor(withHandle: UniffiWithHandle, handle: Long) { + this.handle = handle + this.cleanable = UniffiLib.CLEANER.register(this, UniffiCleanAction(handle)) + } + + /** + * @suppress + * + * This constructor can be used to instantiate a fake object. Only used for tests. Any + * attempt to actually use an object constructed this way will fail as there is no + * connected Rust object. + */ + @Suppress("UNUSED_PARAMETER") + constructor(noHandle: NoHandle) { + this.handle = 0 + this.cleanable = UniffiLib.CLEANER.register(this, UniffiCleanAction(handle)) + } + constructor() : + this(UniffiWithHandle, + uniffiRustCall() { _status -> + UniffiLib.uniffi_devolutions_crypto_uniffi_fn_constructor_argon2parametersbuilder_new( + + _status) +} + ) + + protected val handle: Long + protected val cleanable: UniffiCleaner.Cleanable + + private val wasDestroyed = AtomicBoolean(false) + private val callCounter = AtomicLong(1) + + override fun destroy() { + // Only allow a single call to this method. + // TODO: maybe we should log a warning if called more than once? + if (this.wasDestroyed.compareAndSet(false, true)) { + // This decrement always matches the initial count of 1 given at creation time. + if (this.callCounter.decrementAndGet() == 0L) { + cleanable.clean() + } + } + } + + @Synchronized + override fun close() { + this.destroy() + } + + internal inline fun callWithHandle(block: (handle: Long) -> R): R { + // Check and increment the call counter, to keep the object alive. + // This needs a compare-and-set retry loop in case of concurrent updates. + do { + val c = this.callCounter.get() + if (c == 0L) { + throw IllegalStateException("${this.javaClass.simpleName} object has already been destroyed") + } + if (c == Long.MAX_VALUE) { + throw IllegalStateException("${this.javaClass.simpleName} call counter would overflow") + } + } while (! this.callCounter.compareAndSet(c, c + 1L)) + // Now we can safely do the method call without the handle being freed concurrently. + try { + return block(this.uniffiCloneHandle()) + } finally { + // This decrement always matches the increment we performed above. + if (this.callCounter.decrementAndGet() == 0L) { + cleanable.clean() + } + } + } + + // Use a static inner class instead of a closure so as not to accidentally + // capture `this` as part of the cleanable's action. + private class UniffiCleanAction(private val handle: Long) : Runnable { + override fun run() { + if (handle == 0.toLong()) { + // Fake object created with `NoHandle`, don't try to free. + return; + } + uniffiRustCall { status -> + UniffiLib.uniffi_devolutions_crypto_uniffi_fn_free_argon2parametersbuilder(handle, status) + } + } + } + + /** + * @suppress + */ + fun uniffiCloneHandle(): Long { + if (handle == 0.toLong()) { + throw InternalException("uniffiCloneHandle() called on NoHandle object"); + } + return uniffiRustCall() { status -> + UniffiLib.uniffi_devolutions_crypto_uniffi_fn_clone_argon2parametersbuilder(handle, status) + } + } + + override fun `associatedData`(`value`: kotlin.ByteArray): Argon2ParametersBuilder { + return FfiConverterTypeArgon2ParametersBuilder.lift( + callWithHandle { + uniffiRustCall() { _status -> + UniffiLib.uniffi_devolutions_crypto_uniffi_fn_method_argon2parametersbuilder_associated_data( + it, + FfiConverterByteArray.lower(`value`),_status) +} + } + ) + } + + + override fun `build`(): Argon2Parameters { + return FfiConverterTypeArgon2Parameters.lift( + callWithHandle { + uniffiRustCall() { _status -> + UniffiLib.uniffi_devolutions_crypto_uniffi_fn_method_argon2parametersbuilder_build( + it, + _status) +} + } + ) + } + + + override fun `dcVersion`(`value`: kotlin.UInt): Argon2ParametersBuilder { + return FfiConverterTypeArgon2ParametersBuilder.lift( + callWithHandle { + uniffiRustCall() { _status -> + UniffiLib.uniffi_devolutions_crypto_uniffi_fn_method_argon2parametersbuilder_dc_version( + it, + FfiConverterUInt.lower(`value`),_status) +} + } + ) + } + + + override fun `iterations`(`value`: kotlin.UInt): Argon2ParametersBuilder { + return FfiConverterTypeArgon2ParametersBuilder.lift( + callWithHandle { + uniffiRustCall() { _status -> + UniffiLib.uniffi_devolutions_crypto_uniffi_fn_method_argon2parametersbuilder_iterations( + it, + FfiConverterUInt.lower(`value`),_status) +} + } + ) + } + + + override fun `lanes`(`value`: kotlin.UInt): Argon2ParametersBuilder { + return FfiConverterTypeArgon2ParametersBuilder.lift( + callWithHandle { + uniffiRustCall() { _status -> + UniffiLib.uniffi_devolutions_crypto_uniffi_fn_method_argon2parametersbuilder_lanes( + it, + FfiConverterUInt.lower(`value`),_status) +} + } + ) + } + + + override fun `length`(`value`: kotlin.UInt): Argon2ParametersBuilder { + return FfiConverterTypeArgon2ParametersBuilder.lift( + callWithHandle { + uniffiRustCall() { _status -> + UniffiLib.uniffi_devolutions_crypto_uniffi_fn_method_argon2parametersbuilder_length( + it, + FfiConverterUInt.lower(`value`),_status) +} + } + ) + } + + + override fun `memory`(`value`: kotlin.UInt): Argon2ParametersBuilder { + return FfiConverterTypeArgon2ParametersBuilder.lift( + callWithHandle { + uniffiRustCall() { _status -> + UniffiLib.uniffi_devolutions_crypto_uniffi_fn_method_argon2parametersbuilder_memory( + it, + FfiConverterUInt.lower(`value`),_status) +} + } + ) + } + + + override fun `salt`(`value`: kotlin.ByteArray): Argon2ParametersBuilder { + return FfiConverterTypeArgon2ParametersBuilder.lift( + callWithHandle { + uniffiRustCall() { _status -> + UniffiLib.uniffi_devolutions_crypto_uniffi_fn_method_argon2parametersbuilder_salt( + it, + FfiConverterByteArray.lower(`value`),_status) +} + } + ) + } + + + override fun `secretKey`(`value`: kotlin.ByteArray): Argon2ParametersBuilder { + return FfiConverterTypeArgon2ParametersBuilder.lift( + callWithHandle { + uniffiRustCall() { _status -> + UniffiLib.uniffi_devolutions_crypto_uniffi_fn_method_argon2parametersbuilder_secret_key( + it, + FfiConverterByteArray.lower(`value`),_status) +} + } + ) + } + + + override fun `variant`(`value`: Argon2Variant): Argon2ParametersBuilder { + return FfiConverterTypeArgon2ParametersBuilder.lift( + callWithHandle { + uniffiRustCall() { _status -> + UniffiLib.uniffi_devolutions_crypto_uniffi_fn_method_argon2parametersbuilder_variant( + it, + FfiConverterTypeArgon2Variant.lower(`value`),_status) +} + } + ) + } + + + override fun `version`(`value`: Argon2Version): Argon2ParametersBuilder { + return FfiConverterTypeArgon2ParametersBuilder.lift( + callWithHandle { + uniffiRustCall() { _status -> + UniffiLib.uniffi_devolutions_crypto_uniffi_fn_method_argon2parametersbuilder_version( + it, + FfiConverterTypeArgon2Version.lower(`value`),_status) +} + } + ) + } + + + + + + + + + + /** + * @suppress + */ + companion object + +} + + +/** + * @suppress + */ +public object FfiConverterTypeArgon2ParametersBuilder: FfiConverter { + override fun lower(value: Argon2ParametersBuilder): Long { + return value.uniffiCloneHandle() + } + + override fun lift(value: Long): Argon2ParametersBuilder { + return Argon2ParametersBuilder(UniffiWithHandle, value) + } + + override fun read(buf: ByteBuffer): Argon2ParametersBuilder { + return lift(buf.getLong()) + } + + override fun allocationSize(value: Argon2ParametersBuilder) = 8UL + + override fun write(value: Argon2ParametersBuilder, buf: ByteBuffer) { + buf.putLong(lower(value)) + } +} + + +// This template implements a class for working with a Rust struct via a handle +// to the live Rust struct on the other side of the FFI. +// +// There's some subtlety here, because we have to be careful not to operate on a Rust +// struct after it has been dropped, and because we must expose a public API for freeing +// theq Kotlin wrapper object in lieu of reliable finalizers. The core requirements are: +// +// * Each instance holds an opaque handle to the underlying Rust struct. +// Method calls need to read this handle from the object's state and pass it in to +// the Rust FFI. +// +// * When an instance is no longer needed, its handle should be passed to a +// special destructor function provided by the Rust FFI, which will drop the +// underlying Rust struct. +// +// * Given an instance, calling code is expected to call the special +// `destroy` method in order to free it after use, either by calling it explicitly +// or by using a higher-level helper like the `use` method. Failing to do so risks +// leaking the underlying Rust struct. +// +// * We can't assume that calling code will do the right thing, and must be prepared +// to handle Kotlin method calls executing concurrently with or even after a call to +// `destroy`, and to handle multiple (possibly concurrent!) calls to `destroy`. +// +// * We must never allow Rust code to operate on the underlying Rust struct after +// the destructor has been called, and must never call the destructor more than once. +// Doing so may trigger memory unsafety. +// +// * To mitigate many of the risks of leaking memory and use-after-free unsafety, a `Cleaner` +// is implemented to call the destructor when the Kotlin object becomes unreachable. +// This is done in a background thread. This is not a panacea, and client code should be aware that +// 1. the thread may starve if some there are objects that have poorly performing +// `drop` methods or do significant work in their `drop` methods. +// 2. the thread is shared across the whole library. This can be tuned by using `android_cleaner = true`, +// or `android = true` in the [`kotlin` section of the `uniffi.toml` file](https://mozilla.github.io/uniffi-rs/kotlin/configuration.html). +// +// If we try to implement this with mutual exclusion on access to the handle, there is the +// possibility of a race between a method call and a concurrent call to `destroy`: +// +// * Thread A starts a method call, reads the value of the handle, but is interrupted +// before it can pass the handle over the FFI to Rust. +// * Thread B calls `destroy` and frees the underlying Rust struct. +// * Thread A resumes, passing the already-read handle value to Rust and triggering +// a use-after-free. +// +// One possible solution would be to use a `ReadWriteLock`, with each method call taking +// a read lock (and thus allowed to run concurrently) and the special `destroy` method +// taking a write lock (and thus blocking on live method calls). However, we aim not to +// generate methods with any hidden blocking semantics, and a `destroy` method that might +// block if called incorrectly seems to meet that bar. +// +// So, we achieve our goals by giving each instance an associated `AtomicLong` counter to track +// the number of in-flight method calls, and an `AtomicBoolean` flag to indicate whether `destroy` +// has been called. These are updated according to the following rules: +// +// * The initial value of the counter is 1, indicating a live object with no in-flight calls. +// The initial value for the flag is false. +// +// * At the start of each method call, we atomically check the counter. +// If it is 0 then the underlying Rust struct has already been destroyed and the call is aborted. +// If it is nonzero them we atomically increment it by 1 and proceed with the method call. +// +// * At the end of each method call, we atomically decrement and check the counter. +// If it has reached zero then we destroy the underlying Rust struct. +// +// * When `destroy` is called, we atomically flip the flag from false to true. +// If the flag was already true we silently fail. +// Otherwise we atomically decrement and check the counter. +// If it has reached zero then we destroy the underlying Rust struct. +// +// Astute readers may observe that this all sounds very similar to the way that Rust's `Arc` works, +// and indeed it is, with the addition of a flag to guard against multiple calls to `destroy`. +// +// The overall effect is that the underlying Rust struct is destroyed only when `destroy` has been +// called *and* all in-flight method calls have completed, avoiding violating any of the expectations +// of the underlying Rust code. +// +// This makes a cleaner a better alternative to _not_ calling `destroy()` as +// and when the object is finished with, but the abstraction is not perfect: if the Rust object's `drop` +// method is slow, and/or there are many objects to cleanup, and it's on a low end Android device, then the cleaner +// thread may be starved, and the app will leak memory. +// +// In this case, `destroy`ing manually may be a better solution. +// +// The cleaner can live side by side with the manual calling of `destroy`. In the order of responsiveness, uniffi objects +// with Rust peers are reclaimed: +// +// 1. By calling the `destroy` method of the object, which calls `rustObject.free()`. If that doesn't happen: +// 2. When the object becomes unreachable, AND the Cleaner thread gets to call `rustObject.free()`. If the thread is starved then: +// 3. The memory is reclaimed when the process terminates. +// +// [1] https://stackoverflow.com/questions/24376768/can-java-finalize-an-object-when-it-is-still-in-scope/24380219 +// + + +// +public interface SigningKeyPairInterface { + + fun `getPrivateKey`(): kotlin.ByteArray + + fun `getPublicKey`(): kotlin.ByteArray + + companion object +} + +open class SigningKeyPair: Disposable, AutoCloseable, SigningKeyPairInterface +{ + + @Suppress("UNUSED_PARAMETER") + /** + * @suppress + */ + constructor(withHandle: UniffiWithHandle, handle: Long) { + this.handle = handle + this.cleanable = UniffiLib.CLEANER.register(this, UniffiCleanAction(handle)) + } + + /** + * @suppress + * + * This constructor can be used to instantiate a fake object. Only used for tests. Any + * attempt to actually use an object constructed this way will fail as there is no + * connected Rust object. + */ + @Suppress("UNUSED_PARAMETER") + constructor(noHandle: NoHandle) { + this.handle = 0 + this.cleanable = UniffiLib.CLEANER.register(this, UniffiCleanAction(handle)) + } + + protected val handle: Long + protected val cleanable: UniffiCleaner.Cleanable + + private val wasDestroyed = AtomicBoolean(false) + private val callCounter = AtomicLong(1) + + override fun destroy() { + // Only allow a single call to this method. + // TODO: maybe we should log a warning if called more than once? + if (this.wasDestroyed.compareAndSet(false, true)) { + // This decrement always matches the initial count of 1 given at creation time. + if (this.callCounter.decrementAndGet() == 0L) { + cleanable.clean() + } + } + } + + @Synchronized + override fun close() { + this.destroy() + } + + internal inline fun callWithHandle(block: (handle: Long) -> R): R { + // Check and increment the call counter, to keep the object alive. + // This needs a compare-and-set retry loop in case of concurrent updates. + do { + val c = this.callCounter.get() + if (c == 0L) { + throw IllegalStateException("${this.javaClass.simpleName} object has already been destroyed") + } + if (c == Long.MAX_VALUE) { + throw IllegalStateException("${this.javaClass.simpleName} call counter would overflow") + } + } while (! this.callCounter.compareAndSet(c, c + 1L)) + // Now we can safely do the method call without the handle being freed concurrently. + try { + return block(this.uniffiCloneHandle()) + } finally { + // This decrement always matches the increment we performed above. + if (this.callCounter.decrementAndGet() == 0L) { + cleanable.clean() + } + } + } + + // Use a static inner class instead of a closure so as not to accidentally + // capture `this` as part of the cleanable's action. + private class UniffiCleanAction(private val handle: Long) : Runnable { + override fun run() { + if (handle == 0.toLong()) { + // Fake object created with `NoHandle`, don't try to free. + return; + } + uniffiRustCall { status -> + UniffiLib.uniffi_devolutions_crypto_uniffi_fn_free_signingkeypair(handle, status) + } + } + } + + /** + * @suppress + */ + fun uniffiCloneHandle(): Long { + if (handle == 0.toLong()) { + throw InternalException("uniffiCloneHandle() called on NoHandle object"); + } + return uniffiRustCall() { status -> + UniffiLib.uniffi_devolutions_crypto_uniffi_fn_clone_signingkeypair(handle, status) + } + } + + override fun `getPrivateKey`(): kotlin.ByteArray { + return FfiConverterByteArray.lift( + callWithHandle { + uniffiRustCall() { _status -> + UniffiLib.uniffi_devolutions_crypto_uniffi_fn_method_signingkeypair_get_private_key( + it, + _status) +} + } + ) + } + + + override fun `getPublicKey`(): kotlin.ByteArray { + return FfiConverterByteArray.lift( + callWithHandle { + uniffiRustCall() { _status -> + UniffiLib.uniffi_devolutions_crypto_uniffi_fn_method_signingkeypair_get_public_key( + it, + _status) +} + } + ) + } + + + + + + + + + companion object { + + @Throws(Exception::class) fun `newFromBytes`(`data`: kotlin.ByteArray): SigningKeyPair { + return FfiConverterTypeSigningKeyPair.lift( + uniffiRustCallWithError(ExceptionExternalErrorHandler) { _status -> + UniffiLib.uniffi_devolutions_crypto_uniffi_fn_constructor_signingkeypair_new_from_bytes( + + FfiConverterByteArray.lower(`data`),_status) +} + ) + } + + + + } + +} + + +/** + * @suppress + */ +public object FfiConverterTypeSigningKeyPair: FfiConverter { + override fun lower(value: SigningKeyPair): Long { + return value.uniffiCloneHandle() + } + + override fun lift(value: Long): SigningKeyPair { + return SigningKeyPair(UniffiWithHandle, value) + } + + override fun read(buf: ByteBuffer): SigningKeyPair { + return lift(buf.getLong()) + } + + override fun allocationSize(value: SigningKeyPair) = 8UL + + override fun write(value: SigningKeyPair, buf: ByteBuffer) { + buf.putLong(lower(value)) + } +} + + + +data class KeyPair ( + var `privateKey`: kotlin.ByteArray + , + var `publicKey`: kotlin.ByteArray + +){ + + + + companion object +} + +/** + * @suppress + */ +public object FfiConverterTypeKeyPair: FfiConverterRustBuffer { + override fun read(buf: ByteBuffer): KeyPair { + return KeyPair( + FfiConverterByteArray.read(buf), + FfiConverterByteArray.read(buf), + ) + } + + override fun allocationSize(value: KeyPair) = ( + FfiConverterByteArray.allocationSize(value.`privateKey`) + + FfiConverterByteArray.allocationSize(value.`publicKey`) + ) + + override fun write(value: KeyPair, buf: ByteBuffer) { + FfiConverterByteArray.write(value.`privateKey`, buf) + FfiConverterByteArray.write(value.`publicKey`, buf) + } +} + + + + +enum class Argon2Variant { + + ARGON2D, + ARGON2I, + ARGON2ID; + companion object +} + + +/** + * @suppress + */ +public object FfiConverterTypeArgon2Variant: FfiConverterRustBuffer { + override fun read(buf: ByteBuffer) = try { + Argon2Variant.values()[buf.getInt() - 1] + } catch (e: IndexOutOfBoundsException) { + throw RuntimeException("invalid enum value, something is very wrong!!", e) + } + + override fun allocationSize(value: Argon2Variant) = 4UL + + override fun write(value: Argon2Variant, buf: ByteBuffer) { + buf.putInt(value.ordinal + 1) + } +} + + + + + + +enum class Argon2Version { + + VERSION10, + VERSION13; + companion object +} + + +/** + * @suppress + */ +public object FfiConverterTypeArgon2Version: FfiConverterRustBuffer { + override fun read(buf: ByteBuffer) = try { + Argon2Version.values()[buf.getInt() - 1] + } catch (e: IndexOutOfBoundsException) { + throw RuntimeException("invalid enum value, something is very wrong!!", e) + } + + override fun allocationSize(value: Argon2Version) = 4UL + + override fun write(value: Argon2Version, buf: ByteBuffer) { + buf.putInt(value.ordinal + 1) + } +} + + + + + + +/** + * @suppress + */ +public object FfiConverterOptionalByteArray: FfiConverterRustBuffer { + override fun read(buf: ByteBuffer): kotlin.ByteArray? { + if (buf.get().toInt() == 0) { + return null + } + return FfiConverterByteArray.read(buf) + } + + override fun allocationSize(value: kotlin.ByteArray?): ULong { + if (value == null) { + return 1UL + } else { + return 1UL + FfiConverterByteArray.allocationSize(value) + } + } + + override fun write(value: kotlin.ByteArray?, buf: ByteBuffer) { + if (value == null) { + buf.put(0) + } else { + buf.put(1) + FfiConverterByteArray.write(value, buf) + } + } +} + + + + +/** + * @suppress + */ +public object FfiConverterOptionalTypeCiphertextVersion: FfiConverterRustBuffer { + override fun read(buf: ByteBuffer): CiphertextVersion? { + if (buf.get().toInt() == 0) { + return null + } + return FfiConverterTypeCiphertextVersion.read(buf) + } + + override fun allocationSize(value: CiphertextVersion?): ULong { + if (value == null) { + return 1UL + } else { + return 1UL + FfiConverterTypeCiphertextVersion.allocationSize(value) + } + } + + override fun write(value: CiphertextVersion?, buf: ByteBuffer) { + if (value == null) { + buf.put(0) + } else { + buf.put(1) + FfiConverterTypeCiphertextVersion.write(value, buf) + } + } +} + + + + +/** + * @suppress + */ +public object FfiConverterOptionalTypeKeyVersion: FfiConverterRustBuffer { + override fun read(buf: ByteBuffer): KeyVersion? { + if (buf.get().toInt() == 0) { + return null + } + return FfiConverterTypeKeyVersion.read(buf) + } + + override fun allocationSize(value: KeyVersion?): ULong { + if (value == null) { + return 1UL + } else { + return 1UL + FfiConverterTypeKeyVersion.allocationSize(value) + } + } + + override fun write(value: KeyVersion?, buf: ByteBuffer) { + if (value == null) { + buf.put(0) + } else { + buf.put(1) + FfiConverterTypeKeyVersion.write(value, buf) + } + } +} + + + + +/** + * @suppress + */ +public object FfiConverterOptionalTypePasswordHashVersion: FfiConverterRustBuffer { + override fun read(buf: ByteBuffer): PasswordHashVersion? { + if (buf.get().toInt() == 0) { + return null + } + return FfiConverterTypePasswordHashVersion.read(buf) + } + + override fun allocationSize(value: PasswordHashVersion?): ULong { + if (value == null) { + return 1UL + } else { + return 1UL + FfiConverterTypePasswordHashVersion.allocationSize(value) + } + } + + override fun write(value: PasswordHashVersion?, buf: ByteBuffer) { + if (value == null) { + buf.put(0) + } else { + buf.put(1) + FfiConverterTypePasswordHashVersion.write(value, buf) + } + } +} + + + + +/** + * @suppress + */ +public object FfiConverterOptionalTypeSecretSharingVersion: FfiConverterRustBuffer { + override fun read(buf: ByteBuffer): SecretSharingVersion? { + if (buf.get().toInt() == 0) { + return null + } + return FfiConverterTypeSecretSharingVersion.read(buf) + } + + override fun allocationSize(value: SecretSharingVersion?): ULong { + if (value == null) { + return 1UL + } else { + return 1UL + FfiConverterTypeSecretSharingVersion.allocationSize(value) + } + } + + override fun write(value: SecretSharingVersion?, buf: ByteBuffer) { + if (value == null) { + buf.put(0) + } else { + buf.put(1) + FfiConverterTypeSecretSharingVersion.write(value, buf) + } + } +} + + + + +/** + * @suppress + */ +public object FfiConverterOptionalTypeSignatureVersion: FfiConverterRustBuffer { + override fun read(buf: ByteBuffer): SignatureVersion? { + if (buf.get().toInt() == 0) { + return null + } + return FfiConverterTypeSignatureVersion.read(buf) + } + + override fun allocationSize(value: SignatureVersion?): ULong { + if (value == null) { + return 1UL + } else { + return 1UL + FfiConverterTypeSignatureVersion.allocationSize(value) + } + } + + override fun write(value: SignatureVersion?, buf: ByteBuffer) { + if (value == null) { + buf.put(0) + } else { + buf.put(1) + FfiConverterTypeSignatureVersion.write(value, buf) + } + } +} + + + + +/** + * @suppress + */ +public object FfiConverterOptionalTypeSigningKeyVersion: FfiConverterRustBuffer { + override fun read(buf: ByteBuffer): SigningKeyVersion? { + if (buf.get().toInt() == 0) { + return null + } + return FfiConverterTypeSigningKeyVersion.read(buf) + } + + override fun allocationSize(value: SigningKeyVersion?): ULong { + if (value == null) { + return 1UL + } else { + return 1UL + FfiConverterTypeSigningKeyVersion.allocationSize(value) + } + } + + override fun write(value: SigningKeyVersion?, buf: ByteBuffer) { + if (value == null) { + buf.put(0) + } else { + buf.put(1) + FfiConverterTypeSigningKeyVersion.write(value, buf) + } + } +} + + + + +/** + * @suppress + */ +public object FfiConverterSequenceByteArray: FfiConverterRustBuffer> { + override fun read(buf: ByteBuffer): List { + val len = buf.getInt() + return List(len) { + FfiConverterByteArray.read(buf) + } + } + + override fun allocationSize(value: List): ULong { + val sizeForLength = 4UL + val sizeForItems = value.map { FfiConverterByteArray.allocationSize(it) }.sum() + return sizeForLength + sizeForItems + } + + override fun write(value: List, buf: ByteBuffer) { + buf.putInt(value.size) + value.iterator().forEach { + FfiConverterByteArray.write(it, buf) + } + } +} + + + + + + + +object ExceptionExternalErrorHandler : UniffiRustCallStatusErrorHandler { + override fun lift(error_buf: RustBuffer.ByValue): Exception = + uniffi.devolutions_crypto.Exception.ErrorHandler.lift( + RustBufferError.ByValue().apply { + capacity = error_buf.capacity + len = error_buf.len + data = error_buf.data + } + ) +} + + + + + + + + + + + @Throws(Exception::class) fun `base64Decode`(`data`: kotlin.String): kotlin.ByteArray { + return FfiConverterByteArray.lift( + uniffiRustCallWithError(ExceptionExternalErrorHandler) { _status -> + UniffiLib.uniffi_devolutions_crypto_uniffi_fn_func_base64_decode( + + FfiConverterString.lower(`data`),_status) +} + ) + } + + + @Throws(Exception::class) fun `base64DecodeUrl`(`data`: kotlin.String): kotlin.ByteArray { + return FfiConverterByteArray.lift( + uniffiRustCallWithError(ExceptionExternalErrorHandler) { _status -> + UniffiLib.uniffi_devolutions_crypto_uniffi_fn_func_base64_decode_url( + + FfiConverterString.lower(`data`),_status) +} + ) + } + + fun `base64Encode`(`data`: kotlin.ByteArray): kotlin.String { + return FfiConverterString.lift( + uniffiRustCall() { _status -> + UniffiLib.uniffi_devolutions_crypto_uniffi_fn_func_base64_encode( + + FfiConverterByteArray.lower(`data`),_status) +} + ) + } + + fun `base64EncodeUrl`(`data`: kotlin.ByteArray): kotlin.String { + return FfiConverterString.lift( + uniffiRustCall() { _status -> + UniffiLib.uniffi_devolutions_crypto_uniffi_fn_func_base64_encode_url( + + FfiConverterByteArray.lower(`data`),_status) +} + ) + } + + + @Throws(Exception::class) fun `decrypt`(`data`: kotlin.ByteArray, `key`: kotlin.ByteArray): kotlin.ByteArray { + return FfiConverterByteArray.lift( + uniffiRustCallWithError(ExceptionExternalErrorHandler) { _status -> + UniffiLib.uniffi_devolutions_crypto_uniffi_fn_func_decrypt( + + FfiConverterByteArray.lower(`data`),FfiConverterByteArray.lower(`key`),_status) +} + ) + } + + + @Throws(Exception::class) fun `decryptAsymmetric`(`data`: kotlin.ByteArray, `key`: kotlin.ByteArray): kotlin.ByteArray { + return FfiConverterByteArray.lift( + uniffiRustCallWithError(ExceptionExternalErrorHandler) { _status -> + UniffiLib.uniffi_devolutions_crypto_uniffi_fn_func_decrypt_asymmetric( + + FfiConverterByteArray.lower(`data`),FfiConverterByteArray.lower(`key`),_status) +} + ) + } + + + @Throws(Exception::class) fun `decryptAsymmetricWithAad`(`data`: kotlin.ByteArray, `key`: kotlin.ByteArray, `aad`: kotlin.ByteArray): kotlin.ByteArray { + return FfiConverterByteArray.lift( + uniffiRustCallWithError(ExceptionExternalErrorHandler) { _status -> + UniffiLib.uniffi_devolutions_crypto_uniffi_fn_func_decrypt_asymmetric_with_aad( + + FfiConverterByteArray.lower(`data`),FfiConverterByteArray.lower(`key`),FfiConverterByteArray.lower(`aad`),_status) +} + ) + } + + + @Throws(Exception::class) fun `decryptWithAad`(`data`: kotlin.ByteArray, `key`: kotlin.ByteArray, `aad`: kotlin.ByteArray): kotlin.ByteArray { + return FfiConverterByteArray.lift( + uniffiRustCallWithError(ExceptionExternalErrorHandler) { _status -> + UniffiLib.uniffi_devolutions_crypto_uniffi_fn_func_decrypt_with_aad( + + FfiConverterByteArray.lower(`data`),FfiConverterByteArray.lower(`key`),FfiConverterByteArray.lower(`aad`),_status) +} + ) + } + + + @Throws(Exception::class) fun `deriveKeyArgon2`(`key`: kotlin.ByteArray, `parameters`: Argon2Parameters): kotlin.ByteArray { + return FfiConverterByteArray.lift( + uniffiRustCallWithError(ExceptionExternalErrorHandler) { _status -> + UniffiLib.uniffi_devolutions_crypto_uniffi_fn_func_derive_key_argon2( + + FfiConverterByteArray.lower(`key`),FfiConverterTypeArgon2Parameters.lower(`parameters`),_status) +} + ) + } + + fun `deriveKeyPbkdf2`(`key`: kotlin.ByteArray, `salt`: kotlin.ByteArray?, `iterations`: kotlin.UInt = 10000u, `length`: kotlin.UInt = 32u): kotlin.ByteArray { + return FfiConverterByteArray.lift( + uniffiRustCall() { _status -> + UniffiLib.uniffi_devolutions_crypto_uniffi_fn_func_derive_key_pbkdf2( + + FfiConverterByteArray.lower(`key`),FfiConverterOptionalByteArray.lower(`salt`),FfiConverterUInt.lower(`iterations`),FfiConverterUInt.lower(`length`),_status) +} + ) + } + + + @Throws(Exception::class) fun `encrypt`(`data`: kotlin.ByteArray, `key`: kotlin.ByteArray, `version`: CiphertextVersion? = null): kotlin.ByteArray { + return FfiConverterByteArray.lift( + uniffiRustCallWithError(ExceptionExternalErrorHandler) { _status -> + UniffiLib.uniffi_devolutions_crypto_uniffi_fn_func_encrypt( + + FfiConverterByteArray.lower(`data`),FfiConverterByteArray.lower(`key`),FfiConverterOptionalTypeCiphertextVersion.lower(`version`),_status) +} + ) + } + + + @Throws(Exception::class) fun `encryptAsymmetric`(`data`: kotlin.ByteArray, `key`: kotlin.ByteArray, `version`: CiphertextVersion? = null): kotlin.ByteArray { + return FfiConverterByteArray.lift( + uniffiRustCallWithError(ExceptionExternalErrorHandler) { _status -> + UniffiLib.uniffi_devolutions_crypto_uniffi_fn_func_encrypt_asymmetric( + + FfiConverterByteArray.lower(`data`),FfiConverterByteArray.lower(`key`),FfiConverterOptionalTypeCiphertextVersion.lower(`version`),_status) +} + ) + } + + + @Throws(Exception::class) fun `encryptAsymmetricWithAad`(`data`: kotlin.ByteArray, `key`: kotlin.ByteArray, `aad`: kotlin.ByteArray, `version`: CiphertextVersion? = null): kotlin.ByteArray { + return FfiConverterByteArray.lift( + uniffiRustCallWithError(ExceptionExternalErrorHandler) { _status -> + UniffiLib.uniffi_devolutions_crypto_uniffi_fn_func_encrypt_asymmetric_with_aad( + + FfiConverterByteArray.lower(`data`),FfiConverterByteArray.lower(`key`),FfiConverterByteArray.lower(`aad`),FfiConverterOptionalTypeCiphertextVersion.lower(`version`),_status) +} + ) + } + + + @Throws(Exception::class) fun `encryptWithAad`(`data`: kotlin.ByteArray, `key`: kotlin.ByteArray, `aad`: kotlin.ByteArray, `version`: CiphertextVersion? = null): kotlin.ByteArray { + return FfiConverterByteArray.lift( + uniffiRustCallWithError(ExceptionExternalErrorHandler) { _status -> + UniffiLib.uniffi_devolutions_crypto_uniffi_fn_func_encrypt_with_aad( + + FfiConverterByteArray.lower(`data`),FfiConverterByteArray.lower(`key`),FfiConverterByteArray.lower(`aad`),FfiConverterOptionalTypeCiphertextVersion.lower(`version`),_status) +} + ) + } + + + @Throws(Exception::class) fun `generateKey`(`length`: kotlin.UInt = 32u): kotlin.ByteArray { + return FfiConverterByteArray.lift( + uniffiRustCallWithError(ExceptionExternalErrorHandler) { _status -> + UniffiLib.uniffi_devolutions_crypto_uniffi_fn_func_generate_key( + + FfiConverterUInt.lower(`length`),_status) +} + ) + } + + fun `generateKeypair`(`version`: KeyVersion? = null): KeyPair { + return FfiConverterTypeKeyPair.lift( + uniffiRustCall() { _status -> + UniffiLib.uniffi_devolutions_crypto_uniffi_fn_func_generate_keypair( + + FfiConverterOptionalTypeKeyVersion.lower(`version`),_status) +} + ) + } + + + @Throws(Exception::class) fun `generateSharedKey`(`nShares`: kotlin.UByte, `threshold`: kotlin.UByte, `length`: kotlin.UInt = 32u, `version`: SecretSharingVersion? = null): List { + return FfiConverterSequenceByteArray.lift( + uniffiRustCallWithError(ExceptionExternalErrorHandler) { _status -> + UniffiLib.uniffi_devolutions_crypto_uniffi_fn_func_generate_shared_key( + + FfiConverterUByte.lower(`nShares`),FfiConverterUByte.lower(`threshold`),FfiConverterUInt.lower(`length`),FfiConverterOptionalTypeSecretSharingVersion.lower(`version`),_status) +} + ) + } + + fun `generateSigningKeypair`(`version`: SigningKeyVersion? = null): SigningKeyPair { + return FfiConverterTypeSigningKeyPair.lift( + uniffiRustCall() { _status -> + UniffiLib.uniffi_devolutions_crypto_uniffi_fn_func_generate_signing_keypair( + + FfiConverterOptionalTypeSigningKeyVersion.lower(`version`),_status) +} + ) + } + + + @Throws(Exception::class) fun `hashPassword`(`password`: kotlin.ByteArray, `iterations`: kotlin.UInt = 10000u, `version`: PasswordHashVersion? = null): kotlin.ByteArray { + return FfiConverterByteArray.lift( + uniffiRustCallWithError(ExceptionExternalErrorHandler) { _status -> + UniffiLib.uniffi_devolutions_crypto_uniffi_fn_func_hash_password( + + FfiConverterByteArray.lower(`password`),FfiConverterUInt.lower(`iterations`),FfiConverterOptionalTypePasswordHashVersion.lower(`version`),_status) +} + ) + } + + + @Throws(Exception::class) fun `joinShares`(`shares`: List): kotlin.ByteArray { + return FfiConverterByteArray.lift( + uniffiRustCallWithError(ExceptionExternalErrorHandler) { _status -> + UniffiLib.uniffi_devolutions_crypto_uniffi_fn_func_join_shares( + + FfiConverterSequenceByteArray.lower(`shares`),_status) +} + ) + } + + + @Throws(Exception::class) fun `mixKeyExchange`(`privateKey`: kotlin.ByteArray, `publicKey`: kotlin.ByteArray): kotlin.ByteArray { + return FfiConverterByteArray.lift( + uniffiRustCallWithError(ExceptionExternalErrorHandler) { _status -> + UniffiLib.uniffi_devolutions_crypto_uniffi_fn_func_mix_key_exchange( + + FfiConverterByteArray.lower(`privateKey`),FfiConverterByteArray.lower(`publicKey`),_status) +} + ) + } + + + @Throws(Exception::class) fun `sign`(`data`: kotlin.ByteArray, `keypair`: kotlin.ByteArray, `version`: SignatureVersion? = null): kotlin.ByteArray { + return FfiConverterByteArray.lift( + uniffiRustCallWithError(ExceptionExternalErrorHandler) { _status -> + UniffiLib.uniffi_devolutions_crypto_uniffi_fn_func_sign( + + FfiConverterByteArray.lower(`data`),FfiConverterByteArray.lower(`keypair`),FfiConverterOptionalTypeSignatureVersion.lower(`version`),_status) +} + ) + } + + fun `validateHeader`(`data`: kotlin.ByteArray, `dataType`: DataType): kotlin.Boolean { + return FfiConverterBoolean.lift( + uniffiRustCall() { _status -> + UniffiLib.uniffi_devolutions_crypto_uniffi_fn_func_validate_header( + + FfiConverterByteArray.lower(`data`),FfiConverterTypeDataType.lower(`dataType`),_status) +} + ) + } + + + @Throws(Exception::class) fun `verifyPassword`(`password`: kotlin.ByteArray, `hash`: kotlin.ByteArray): kotlin.Boolean { + return FfiConverterBoolean.lift( + uniffiRustCallWithError(ExceptionExternalErrorHandler) { _status -> + UniffiLib.uniffi_devolutions_crypto_uniffi_fn_func_verify_password( + + FfiConverterByteArray.lower(`password`),FfiConverterByteArray.lower(`hash`),_status) +} + ) + } + + + @Throws(Exception::class) fun `verifySignature`(`data`: kotlin.ByteArray, `publicKey`: kotlin.ByteArray, `signature`: kotlin.ByteArray): kotlin.Boolean { + return FfiConverterBoolean.lift( + uniffiRustCallWithError(ExceptionExternalErrorHandler) { _status -> + UniffiLib.uniffi_devolutions_crypto_uniffi_fn_func_verify_signature( + + FfiConverterByteArray.lower(`data`),FfiConverterByteArray.lower(`publicKey`),FfiConverterByteArray.lower(`signature`),_status) +} + ) + } + + + diff --git a/wrappers/kotlin/lib/src/test/kotlin/org/devolutions/crypto/AsymmetricTest.kt b/wrappers/kotlin/lib/src/test/kotlin/org/devolutions/crypto/AsymmetricTest.kt index e49b216cf..50b24a2ad 100644 --- a/wrappers/kotlin/lib/src/test/kotlin/org/devolutions/crypto/AsymmetricTest.kt +++ b/wrappers/kotlin/lib/src/test/kotlin/org/devolutions/crypto/AsymmetricTest.kt @@ -7,6 +7,7 @@ import kotlin.test.Test import kotlin.test.assertContentEquals import kotlin.test.assertEquals import kotlin.test.assertFailsWith +import uniffi.devolutions_crypto.Exception class AsymmetricTest { @Test @@ -55,15 +56,15 @@ class AsymmetricTest { val encrypted = encryptAsymmetricWithAad(data, keypair.publicKey, aad) - assertFailsWith { + assertFailsWith { decryptAsymmetricWithAad(encrypted, keypair.privateKey, wrongAad) } } @Test fun mixKeyExchangeTest() { - val bobKeypair = generateKeypair() - val aliceKeypair = generateKeypair() + val bobKeypair = generateKeypair(null) + val aliceKeypair = generateKeypair(null) val bobShared = mixKeyExchange(bobKeypair.privateKey, aliceKeypair.publicKey) val aliceShared = mixKeyExchange(aliceKeypair.privateKey, bobKeypair.publicKey) @@ -75,9 +76,9 @@ class AsymmetricTest { @Test fun mixKeyExchangeNotEqualsTest() { - val bobKeypair = generateKeypair() - val aliceKeypair = generateKeypair() - val eveKeypair = generateKeypair() + val bobKeypair = generateKeypair(null) + val aliceKeypair = generateKeypair(null) + val eveKeypair = generateKeypair(null) val bobAliceShared = mixKeyExchange(bobKeypair.privateKey, aliceKeypair.publicKey) val aliceBobShared = mixKeyExchange(aliceKeypair.privateKey, bobKeypair.publicKey) diff --git a/wrappers/kotlin/lib/src/test/kotlin/org/devolutions/crypto/SecretSharingTest.kt b/wrappers/kotlin/lib/src/test/kotlin/org/devolutions/crypto/SecretSharingTest.kt index 003c81be9..0edcb8ecb 100644 --- a/wrappers/kotlin/lib/src/test/kotlin/org/devolutions/crypto/SecretSharingTest.kt +++ b/wrappers/kotlin/lib/src/test/kotlin/org/devolutions/crypto/SecretSharingTest.kt @@ -7,6 +7,7 @@ import org.junit.jupiter.api.assertThrows import kotlin.test.Test import kotlin.test.assertContentEquals import kotlin.test.assertEquals +import uniffi.devolutions_crypto.Exception class SecretSharingTest { @Test @@ -47,7 +48,7 @@ class SecretSharingTest { @Test fun sharedSecretWrongParamsTest() { - assertThrows { + assertThrows { generateSharedKey(3u, 5u) } } @@ -56,7 +57,7 @@ class SecretSharingTest { fun sharedSecrectNotEnoughShare() { val shares = generateSharedKey(5u, 3u) val sharesGroup = shares.slice(0..1) - assertThrows { + assertThrows { joinShares(sharesGroup) } } diff --git a/wrappers/kotlin/lib/src/test/kotlin/org/devolutions/crypto/SymmetricTest.kt b/wrappers/kotlin/lib/src/test/kotlin/org/devolutions/crypto/SymmetricTest.kt index 8c38d60ce..8c5c95e4f 100644 --- a/wrappers/kotlin/lib/src/test/kotlin/org/devolutions/crypto/SymmetricTest.kt +++ b/wrappers/kotlin/lib/src/test/kotlin/org/devolutions/crypto/SymmetricTest.kt @@ -6,6 +6,7 @@ package org.devolutions.crypto import kotlin.test.Test import kotlin.test.assertContentEquals import kotlin.test.assertFailsWith +import uniffi.devolutions_crypto.Exception class SymmetricTest { @Test @@ -44,7 +45,7 @@ class SymmetricTest { val encrypted = encryptWithAad(data, key, aad) - assertFailsWith { + assertFailsWith { decryptWithAad(encrypted, key, wrongAad) } } diff --git a/wrappers/kotlin/lib/src/test/kotlin/org/devolutions/crypto/UtilsTest.kt b/wrappers/kotlin/lib/src/test/kotlin/org/devolutions/crypto/UtilsTest.kt index c545844f7..1685fd663 100644 --- a/wrappers/kotlin/lib/src/test/kotlin/org/devolutions/crypto/UtilsTest.kt +++ b/wrappers/kotlin/lib/src/test/kotlin/org/devolutions/crypto/UtilsTest.kt @@ -6,6 +6,7 @@ package org.devolutions.crypto import kotlin.test.Test import kotlin.test.assertContentEquals import kotlin.test.assertEquals +import uniffi.devolutions_crypto.DataType class UtilsTest { @Test diff --git a/wrappers/swift/DevolutionsCryptoSwift/Sources/DevolutionsCryptoSwift/DevolutionsCryptoSwift.swift b/wrappers/swift/DevolutionsCryptoSwift/Sources/DevolutionsCryptoSwift/DevolutionsCryptoSwift.swift index b16664787..0a94570d5 100644 --- a/wrappers/swift/DevolutionsCryptoSwift/Sources/DevolutionsCryptoSwift/DevolutionsCryptoSwift.swift +++ b/wrappers/swift/DevolutionsCryptoSwift/Sources/DevolutionsCryptoSwift/DevolutionsCryptoSwift.swift @@ -7,8 +7,8 @@ import Foundation // Depending on the consumer's build setup, the low-level FFI code // might be in a separate module, or it might be compiled inline into // this module. This is a bit of light hackery to work with both. -#if canImport(devolutions_cryptoFFI) -import devolutions_cryptoFFI +#if canImport(devolutions_crypto_uniffiFFI) +import devolutions_crypto_uniffiFFI #endif fileprivate extension RustBuffer { @@ -352,21 +352,31 @@ private func uniffiTraitInterfaceCallWithError( callStatus.pointee.errorBuf = FfiConverterString.lower(String(describing: error)) } } +// Initial value and increment amount for handles. +// These ensure that SWIFT handles always have the lowest bit set +fileprivate let UNIFFI_HANDLEMAP_INITIAL: UInt64 = 1 +fileprivate let UNIFFI_HANDLEMAP_DELTA: UInt64 = 2 + fileprivate final class UniffiHandleMap: @unchecked Sendable { // All mutation happens with this lock held, which is why we implement @unchecked Sendable. private let lock = NSLock() private var map: [UInt64: T] = [:] - private var currentHandle: UInt64 = 1 + private var currentHandle: UInt64 = UNIFFI_HANDLEMAP_INITIAL func insert(obj: T) -> UInt64 { lock.withLock { - let handle = currentHandle - currentHandle += 1 - map[handle] = obj - return handle + return doInsert(obj) } } + // Low-level insert function, this assumes `lock` is held. + private func doInsert(_ obj: T) -> UInt64 { + let handle = currentHandle + currentHandle += UNIFFI_HANDLEMAP_DELTA + map[handle] = obj + return handle + } + func get(handle: UInt64) throws -> T { try lock.withLock { guard let obj = map[handle] else { @@ -376,6 +386,15 @@ fileprivate final class UniffiHandleMap: @unchecked Sendable { } } + func clone(handle: UInt64) throws -> UInt64 { + try lock.withLock { + guard let obj = map[handle] else { + throw UniffiInternalError.unexpectedStaleHandle + } + return doInsert(obj) + } + } + @discardableResult func remove(handle: UInt64) throws -> T { try lock.withLock { @@ -521,13 +540,13 @@ public protocol Argon2ParametersProtocol: AnyObject, Sendable { } open class Argon2Parameters: Argon2ParametersProtocol, @unchecked Sendable { - fileprivate let pointer: UnsafeMutableRawPointer! + fileprivate let handle: UInt64 - /// Used to instantiate a [FFIObject] without an actual pointer, for fakes in tests, mostly. + /// Used to instantiate a [FFIObject] without an actual handle, for fakes in tests, mostly. #if swift(>=5.8) @_documentation(visibility: private) #endif - public struct NoPointer { + public struct NoHandle { public init() {} } @@ -537,41 +556,37 @@ open class Argon2Parameters: Argon2ParametersProtocol, @unchecked Sendable { #if swift(>=5.8) @_documentation(visibility: private) #endif - required public init(unsafeFromRawPointer pointer: UnsafeMutableRawPointer) { - self.pointer = pointer + required public init(unsafeFromHandle handle: UInt64) { + self.handle = handle } // This constructor can be used to instantiate a fake object. - // - Parameter noPointer: Placeholder value so we can have a constructor separate from the default empty one that may be implemented for classes extending [FFIObject]. + // - Parameter noHandle: Placeholder value so we can have a constructor separate from the default empty one that may be implemented for classes extending [FFIObject]. // // - Warning: - // Any object instantiated with this constructor cannot be passed to an actual Rust-backed object. Since there isn't a backing [Pointer] the FFI lower functions will crash. + // Any object instantiated with this constructor cannot be passed to an actual Rust-backed object. Since there isn't a backing handle the FFI lower functions will crash. #if swift(>=5.8) @_documentation(visibility: private) #endif - public init(noPointer: NoPointer) { - self.pointer = nil + public init(noHandle: NoHandle) { + self.handle = 0 } #if swift(>=5.8) @_documentation(visibility: private) #endif - public func uniffiClonePointer() -> UnsafeMutableRawPointer { - return try! rustCall { uniffi_devolutions_crypto_uniffi_fn_clone_argon2parameters(self.pointer, $0) } + public func uniffiCloneHandle() -> UInt64 { + return try! rustCall { uniffi_devolutions_crypto_uniffi_fn_clone_argon2parameters(self.handle, $0) } } // No primary constructor declared for this class. deinit { - guard let pointer = pointer else { - return - } - - try! rustCall { uniffi_devolutions_crypto_uniffi_fn_free_argon2parameters(pointer, $0) } + try! rustCall { uniffi_devolutions_crypto_uniffi_fn_free_argon2parameters(handle, $0) } } public static func newFromBytes(data: Data)throws -> Argon2Parameters { - return try FfiConverterTypeArgon2Parameters_lift(try rustCallWithError(FfiConverterTypeDevolutionsCryptoError_lift) { + return try FfiConverterTypeArgon2Parameters_lift(try rustCallWithError(FfiConverterTypeError_lift) { uniffi_devolutions_crypto_uniffi_fn_constructor_argon2parameters_new_from_bytes( FfiConverterData.lower(data),$0 ) @@ -582,12 +597,14 @@ public static func newFromBytes(data: Data)throws -> Argon2Parameters { open func getBytes() -> Data { return try! FfiConverterData.lift(try! rustCall() { - uniffi_devolutions_crypto_uniffi_fn_method_argon2parameters_get_bytes(self.uniffiClonePointer(),$0 + uniffi_devolutions_crypto_uniffi_fn_method_argon2parameters_get_bytes( + self.uniffiCloneHandle(),$0 ) }) } + } @@ -595,33 +612,24 @@ open func getBytes() -> Data { @_documentation(visibility: private) #endif public struct FfiConverterTypeArgon2Parameters: FfiConverter { - - typealias FfiType = UnsafeMutableRawPointer + typealias FfiType = UInt64 typealias SwiftType = Argon2Parameters - public static func lift(_ pointer: UnsafeMutableRawPointer) throws -> Argon2Parameters { - return Argon2Parameters(unsafeFromRawPointer: pointer) + public static func lift(_ handle: UInt64) throws -> Argon2Parameters { + return Argon2Parameters(unsafeFromHandle: handle) } - public static func lower(_ value: Argon2Parameters) -> UnsafeMutableRawPointer { - return value.uniffiClonePointer() + public static func lower(_ value: Argon2Parameters) -> UInt64 { + return value.uniffiCloneHandle() } public static func read(from buf: inout (data: Data, offset: Data.Index)) throws -> Argon2Parameters { - let v: UInt64 = try readInt(&buf) - // The Rust code won't compile if a pointer won't fit in a UInt64. - // We have to go via `UInt` because that's the thing that's the size of a pointer. - let ptr = UnsafeMutableRawPointer(bitPattern: UInt(truncatingIfNeeded: v)) - if (ptr == nil) { - throw UniffiInternalError.unexpectedNullPointer - } - return try lift(ptr!) + let handle: UInt64 = try readInt(&buf) + return try lift(handle) } public static func write(_ value: Argon2Parameters, into buf: inout [UInt8]) { - // This fiddling is because `Int` is the thing that's the same size as a pointer. - // The Rust code won't compile if a pointer won't fit in a `UInt64`. - writeInt(&buf, UInt64(bitPattern: Int64(Int(bitPattern: lower(value))))) + writeInt(&buf, lower(value)) } } @@ -629,14 +637,14 @@ public struct FfiConverterTypeArgon2Parameters: FfiConverter { #if swift(>=5.8) @_documentation(visibility: private) #endif -public func FfiConverterTypeArgon2Parameters_lift(_ pointer: UnsafeMutableRawPointer) throws -> Argon2Parameters { - return try FfiConverterTypeArgon2Parameters.lift(pointer) +public func FfiConverterTypeArgon2Parameters_lift(_ handle: UInt64) throws -> Argon2Parameters { + return try FfiConverterTypeArgon2Parameters.lift(handle) } #if swift(>=5.8) @_documentation(visibility: private) #endif -public func FfiConverterTypeArgon2Parameters_lower(_ value: Argon2Parameters) -> UnsafeMutableRawPointer { +public func FfiConverterTypeArgon2Parameters_lower(_ value: Argon2Parameters) -> UInt64 { return FfiConverterTypeArgon2Parameters.lower(value) } @@ -671,13 +679,13 @@ public protocol Argon2ParametersBuilderProtocol: AnyObject, Sendable { } open class Argon2ParametersBuilder: Argon2ParametersBuilderProtocol, @unchecked Sendable { - fileprivate let pointer: UnsafeMutableRawPointer! + fileprivate let handle: UInt64 - /// Used to instantiate a [FFIObject] without an actual pointer, for fakes in tests, mostly. + /// Used to instantiate a [FFIObject] without an actual handle, for fakes in tests, mostly. #if swift(>=5.8) @_documentation(visibility: private) #endif - public struct NoPointer { + public struct NoHandle { public init() {} } @@ -687,43 +695,39 @@ open class Argon2ParametersBuilder: Argon2ParametersBuilderProtocol, @unchecked #if swift(>=5.8) @_documentation(visibility: private) #endif - required public init(unsafeFromRawPointer pointer: UnsafeMutableRawPointer) { - self.pointer = pointer + required public init(unsafeFromHandle handle: UInt64) { + self.handle = handle } // This constructor can be used to instantiate a fake object. - // - Parameter noPointer: Placeholder value so we can have a constructor separate from the default empty one that may be implemented for classes extending [FFIObject]. + // - Parameter noHandle: Placeholder value so we can have a constructor separate from the default empty one that may be implemented for classes extending [FFIObject]. // // - Warning: - // Any object instantiated with this constructor cannot be passed to an actual Rust-backed object. Since there isn't a backing [Pointer] the FFI lower functions will crash. + // Any object instantiated with this constructor cannot be passed to an actual Rust-backed object. Since there isn't a backing handle the FFI lower functions will crash. #if swift(>=5.8) @_documentation(visibility: private) #endif - public init(noPointer: NoPointer) { - self.pointer = nil + public init(noHandle: NoHandle) { + self.handle = 0 } #if swift(>=5.8) @_documentation(visibility: private) #endif - public func uniffiClonePointer() -> UnsafeMutableRawPointer { - return try! rustCall { uniffi_devolutions_crypto_uniffi_fn_clone_argon2parametersbuilder(self.pointer, $0) } + public func uniffiCloneHandle() -> UInt64 { + return try! rustCall { uniffi_devolutions_crypto_uniffi_fn_clone_argon2parametersbuilder(self.handle, $0) } } public convenience init() { - let pointer = + let handle = try! rustCall() { uniffi_devolutions_crypto_uniffi_fn_constructor_argon2parametersbuilder_new($0 ) } - self.init(unsafeFromRawPointer: pointer) + self.init(unsafeFromHandle: handle) } deinit { - guard let pointer = pointer else { - return - } - - try! rustCall { uniffi_devolutions_crypto_uniffi_fn_free_argon2parametersbuilder(pointer, $0) } + try! rustCall { uniffi_devolutions_crypto_uniffi_fn_free_argon2parametersbuilder(handle, $0) } } @@ -731,7 +735,8 @@ public convenience init() { open func associatedData(value: Data) -> Argon2ParametersBuilder { return try! FfiConverterTypeArgon2ParametersBuilder_lift(try! rustCall() { - uniffi_devolutions_crypto_uniffi_fn_method_argon2parametersbuilder_associated_data(self.uniffiClonePointer(), + uniffi_devolutions_crypto_uniffi_fn_method_argon2parametersbuilder_associated_data( + self.uniffiCloneHandle(), FfiConverterData.lower(value),$0 ) }) @@ -739,14 +744,16 @@ open func associatedData(value: Data) -> Argon2ParametersBuilder { open func build() -> Argon2Parameters { return try! FfiConverterTypeArgon2Parameters_lift(try! rustCall() { - uniffi_devolutions_crypto_uniffi_fn_method_argon2parametersbuilder_build(self.uniffiClonePointer(),$0 + uniffi_devolutions_crypto_uniffi_fn_method_argon2parametersbuilder_build( + self.uniffiCloneHandle(),$0 ) }) } open func dcVersion(value: UInt32) -> Argon2ParametersBuilder { return try! FfiConverterTypeArgon2ParametersBuilder_lift(try! rustCall() { - uniffi_devolutions_crypto_uniffi_fn_method_argon2parametersbuilder_dc_version(self.uniffiClonePointer(), + uniffi_devolutions_crypto_uniffi_fn_method_argon2parametersbuilder_dc_version( + self.uniffiCloneHandle(), FfiConverterUInt32.lower(value),$0 ) }) @@ -754,7 +761,8 @@ open func dcVersion(value: UInt32) -> Argon2ParametersBuilder { open func iterations(value: UInt32) -> Argon2ParametersBuilder { return try! FfiConverterTypeArgon2ParametersBuilder_lift(try! rustCall() { - uniffi_devolutions_crypto_uniffi_fn_method_argon2parametersbuilder_iterations(self.uniffiClonePointer(), + uniffi_devolutions_crypto_uniffi_fn_method_argon2parametersbuilder_iterations( + self.uniffiCloneHandle(), FfiConverterUInt32.lower(value),$0 ) }) @@ -762,7 +770,8 @@ open func iterations(value: UInt32) -> Argon2ParametersBuilder { open func lanes(value: UInt32) -> Argon2ParametersBuilder { return try! FfiConverterTypeArgon2ParametersBuilder_lift(try! rustCall() { - uniffi_devolutions_crypto_uniffi_fn_method_argon2parametersbuilder_lanes(self.uniffiClonePointer(), + uniffi_devolutions_crypto_uniffi_fn_method_argon2parametersbuilder_lanes( + self.uniffiCloneHandle(), FfiConverterUInt32.lower(value),$0 ) }) @@ -770,7 +779,8 @@ open func lanes(value: UInt32) -> Argon2ParametersBuilder { open func length(value: UInt32) -> Argon2ParametersBuilder { return try! FfiConverterTypeArgon2ParametersBuilder_lift(try! rustCall() { - uniffi_devolutions_crypto_uniffi_fn_method_argon2parametersbuilder_length(self.uniffiClonePointer(), + uniffi_devolutions_crypto_uniffi_fn_method_argon2parametersbuilder_length( + self.uniffiCloneHandle(), FfiConverterUInt32.lower(value),$0 ) }) @@ -778,7 +788,8 @@ open func length(value: UInt32) -> Argon2ParametersBuilder { open func memory(value: UInt32) -> Argon2ParametersBuilder { return try! FfiConverterTypeArgon2ParametersBuilder_lift(try! rustCall() { - uniffi_devolutions_crypto_uniffi_fn_method_argon2parametersbuilder_memory(self.uniffiClonePointer(), + uniffi_devolutions_crypto_uniffi_fn_method_argon2parametersbuilder_memory( + self.uniffiCloneHandle(), FfiConverterUInt32.lower(value),$0 ) }) @@ -786,7 +797,8 @@ open func memory(value: UInt32) -> Argon2ParametersBuilder { open func salt(value: Data) -> Argon2ParametersBuilder { return try! FfiConverterTypeArgon2ParametersBuilder_lift(try! rustCall() { - uniffi_devolutions_crypto_uniffi_fn_method_argon2parametersbuilder_salt(self.uniffiClonePointer(), + uniffi_devolutions_crypto_uniffi_fn_method_argon2parametersbuilder_salt( + self.uniffiCloneHandle(), FfiConverterData.lower(value),$0 ) }) @@ -794,7 +806,8 @@ open func salt(value: Data) -> Argon2ParametersBuilder { open func secretKey(value: Data) -> Argon2ParametersBuilder { return try! FfiConverterTypeArgon2ParametersBuilder_lift(try! rustCall() { - uniffi_devolutions_crypto_uniffi_fn_method_argon2parametersbuilder_secret_key(self.uniffiClonePointer(), + uniffi_devolutions_crypto_uniffi_fn_method_argon2parametersbuilder_secret_key( + self.uniffiCloneHandle(), FfiConverterData.lower(value),$0 ) }) @@ -802,7 +815,8 @@ open func secretKey(value: Data) -> Argon2ParametersBuilder { open func variant(value: Argon2Variant) -> Argon2ParametersBuilder { return try! FfiConverterTypeArgon2ParametersBuilder_lift(try! rustCall() { - uniffi_devolutions_crypto_uniffi_fn_method_argon2parametersbuilder_variant(self.uniffiClonePointer(), + uniffi_devolutions_crypto_uniffi_fn_method_argon2parametersbuilder_variant( + self.uniffiCloneHandle(), FfiConverterTypeArgon2Variant_lower(value),$0 ) }) @@ -810,13 +824,15 @@ open func variant(value: Argon2Variant) -> Argon2ParametersBuilder { open func version(value: Argon2Version) -> Argon2ParametersBuilder { return try! FfiConverterTypeArgon2ParametersBuilder_lift(try! rustCall() { - uniffi_devolutions_crypto_uniffi_fn_method_argon2parametersbuilder_version(self.uniffiClonePointer(), + uniffi_devolutions_crypto_uniffi_fn_method_argon2parametersbuilder_version( + self.uniffiCloneHandle(), FfiConverterTypeArgon2Version_lower(value),$0 ) }) } + } @@ -824,33 +840,24 @@ open func version(value: Argon2Version) -> Argon2ParametersBuilder { @_documentation(visibility: private) #endif public struct FfiConverterTypeArgon2ParametersBuilder: FfiConverter { - - typealias FfiType = UnsafeMutableRawPointer + typealias FfiType = UInt64 typealias SwiftType = Argon2ParametersBuilder - public static func lift(_ pointer: UnsafeMutableRawPointer) throws -> Argon2ParametersBuilder { - return Argon2ParametersBuilder(unsafeFromRawPointer: pointer) + public static func lift(_ handle: UInt64) throws -> Argon2ParametersBuilder { + return Argon2ParametersBuilder(unsafeFromHandle: handle) } - public static func lower(_ value: Argon2ParametersBuilder) -> UnsafeMutableRawPointer { - return value.uniffiClonePointer() + public static func lower(_ value: Argon2ParametersBuilder) -> UInt64 { + return value.uniffiCloneHandle() } public static func read(from buf: inout (data: Data, offset: Data.Index)) throws -> Argon2ParametersBuilder { - let v: UInt64 = try readInt(&buf) - // The Rust code won't compile if a pointer won't fit in a UInt64. - // We have to go via `UInt` because that's the thing that's the size of a pointer. - let ptr = UnsafeMutableRawPointer(bitPattern: UInt(truncatingIfNeeded: v)) - if (ptr == nil) { - throw UniffiInternalError.unexpectedNullPointer - } - return try lift(ptr!) + let handle: UInt64 = try readInt(&buf) + return try lift(handle) } public static func write(_ value: Argon2ParametersBuilder, into buf: inout [UInt8]) { - // This fiddling is because `Int` is the thing that's the same size as a pointer. - // The Rust code won't compile if a pointer won't fit in a `UInt64`. - writeInt(&buf, UInt64(bitPattern: Int64(Int(bitPattern: lower(value))))) + writeInt(&buf, lower(value)) } } @@ -858,14 +865,14 @@ public struct FfiConverterTypeArgon2ParametersBuilder: FfiConverter { #if swift(>=5.8) @_documentation(visibility: private) #endif -public func FfiConverterTypeArgon2ParametersBuilder_lift(_ pointer: UnsafeMutableRawPointer) throws -> Argon2ParametersBuilder { - return try FfiConverterTypeArgon2ParametersBuilder.lift(pointer) +public func FfiConverterTypeArgon2ParametersBuilder_lift(_ handle: UInt64) throws -> Argon2ParametersBuilder { + return try FfiConverterTypeArgon2ParametersBuilder.lift(handle) } #if swift(>=5.8) @_documentation(visibility: private) #endif -public func FfiConverterTypeArgon2ParametersBuilder_lower(_ value: Argon2ParametersBuilder) -> UnsafeMutableRawPointer { +public func FfiConverterTypeArgon2ParametersBuilder_lower(_ value: Argon2ParametersBuilder) -> UInt64 { return FfiConverterTypeArgon2ParametersBuilder.lower(value) } @@ -882,13 +889,13 @@ public protocol SigningKeyPairProtocol: AnyObject, Sendable { } open class SigningKeyPair: SigningKeyPairProtocol, @unchecked Sendable { - fileprivate let pointer: UnsafeMutableRawPointer! + fileprivate let handle: UInt64 - /// Used to instantiate a [FFIObject] without an actual pointer, for fakes in tests, mostly. + /// Used to instantiate a [FFIObject] without an actual handle, for fakes in tests, mostly. #if swift(>=5.8) @_documentation(visibility: private) #endif - public struct NoPointer { + public struct NoHandle { public init() {} } @@ -898,41 +905,37 @@ open class SigningKeyPair: SigningKeyPairProtocol, @unchecked Sendable { #if swift(>=5.8) @_documentation(visibility: private) #endif - required public init(unsafeFromRawPointer pointer: UnsafeMutableRawPointer) { - self.pointer = pointer + required public init(unsafeFromHandle handle: UInt64) { + self.handle = handle } // This constructor can be used to instantiate a fake object. - // - Parameter noPointer: Placeholder value so we can have a constructor separate from the default empty one that may be implemented for classes extending [FFIObject]. + // - Parameter noHandle: Placeholder value so we can have a constructor separate from the default empty one that may be implemented for classes extending [FFIObject]. // // - Warning: - // Any object instantiated with this constructor cannot be passed to an actual Rust-backed object. Since there isn't a backing [Pointer] the FFI lower functions will crash. + // Any object instantiated with this constructor cannot be passed to an actual Rust-backed object. Since there isn't a backing handle the FFI lower functions will crash. #if swift(>=5.8) @_documentation(visibility: private) #endif - public init(noPointer: NoPointer) { - self.pointer = nil + public init(noHandle: NoHandle) { + self.handle = 0 } #if swift(>=5.8) @_documentation(visibility: private) #endif - public func uniffiClonePointer() -> UnsafeMutableRawPointer { - return try! rustCall { uniffi_devolutions_crypto_uniffi_fn_clone_signingkeypair(self.pointer, $0) } + public func uniffiCloneHandle() -> UInt64 { + return try! rustCall { uniffi_devolutions_crypto_uniffi_fn_clone_signingkeypair(self.handle, $0) } } // No primary constructor declared for this class. deinit { - guard let pointer = pointer else { - return - } - - try! rustCall { uniffi_devolutions_crypto_uniffi_fn_free_signingkeypair(pointer, $0) } + try! rustCall { uniffi_devolutions_crypto_uniffi_fn_free_signingkeypair(handle, $0) } } public static func newFromBytes(data: Data)throws -> SigningKeyPair { - return try FfiConverterTypeSigningKeyPair_lift(try rustCallWithError(FfiConverterTypeDevolutionsCryptoError_lift) { + return try FfiConverterTypeSigningKeyPair_lift(try rustCallWithError(FfiConverterTypeError_lift) { uniffi_devolutions_crypto_uniffi_fn_constructor_signingkeypair_new_from_bytes( FfiConverterData.lower(data),$0 ) @@ -943,19 +946,22 @@ public static func newFromBytes(data: Data)throws -> SigningKeyPair { open func getPrivateKey() -> Data { return try! FfiConverterData.lift(try! rustCall() { - uniffi_devolutions_crypto_uniffi_fn_method_signingkeypair_get_private_key(self.uniffiClonePointer(),$0 + uniffi_devolutions_crypto_uniffi_fn_method_signingkeypair_get_private_key( + self.uniffiCloneHandle(),$0 ) }) } open func getPublicKey() -> Data { return try! FfiConverterData.lift(try! rustCall() { - uniffi_devolutions_crypto_uniffi_fn_method_signingkeypair_get_public_key(self.uniffiClonePointer(),$0 + uniffi_devolutions_crypto_uniffi_fn_method_signingkeypair_get_public_key( + self.uniffiCloneHandle(),$0 ) }) } + } @@ -963,33 +969,24 @@ open func getPublicKey() -> Data { @_documentation(visibility: private) #endif public struct FfiConverterTypeSigningKeyPair: FfiConverter { - - typealias FfiType = UnsafeMutableRawPointer + typealias FfiType = UInt64 typealias SwiftType = SigningKeyPair - public static func lift(_ pointer: UnsafeMutableRawPointer) throws -> SigningKeyPair { - return SigningKeyPair(unsafeFromRawPointer: pointer) + public static func lift(_ handle: UInt64) throws -> SigningKeyPair { + return SigningKeyPair(unsafeFromHandle: handle) } - public static func lower(_ value: SigningKeyPair) -> UnsafeMutableRawPointer { - return value.uniffiClonePointer() + public static func lower(_ value: SigningKeyPair) -> UInt64 { + return value.uniffiCloneHandle() } public static func read(from buf: inout (data: Data, offset: Data.Index)) throws -> SigningKeyPair { - let v: UInt64 = try readInt(&buf) - // The Rust code won't compile if a pointer won't fit in a UInt64. - // We have to go via `UInt` because that's the thing that's the size of a pointer. - let ptr = UnsafeMutableRawPointer(bitPattern: UInt(truncatingIfNeeded: v)) - if (ptr == nil) { - throw UniffiInternalError.unexpectedNullPointer - } - return try lift(ptr!) + let handle: UInt64 = try readInt(&buf) + return try lift(handle) } public static func write(_ value: SigningKeyPair, into buf: inout [UInt8]) { - // This fiddling is because `Int` is the thing that's the same size as a pointer. - // The Rust code won't compile if a pointer won't fit in a `UInt64`. - writeInt(&buf, UInt64(bitPattern: Int64(Int(bitPattern: lower(value))))) + writeInt(&buf, lower(value)) } } @@ -997,56 +994,38 @@ public struct FfiConverterTypeSigningKeyPair: FfiConverter { #if swift(>=5.8) @_documentation(visibility: private) #endif -public func FfiConverterTypeSigningKeyPair_lift(_ pointer: UnsafeMutableRawPointer) throws -> SigningKeyPair { - return try FfiConverterTypeSigningKeyPair.lift(pointer) +public func FfiConverterTypeSigningKeyPair_lift(_ handle: UInt64) throws -> SigningKeyPair { + return try FfiConverterTypeSigningKeyPair.lift(handle) } #if swift(>=5.8) @_documentation(visibility: private) #endif -public func FfiConverterTypeSigningKeyPair_lower(_ value: SigningKeyPair) -> UnsafeMutableRawPointer { +public func FfiConverterTypeSigningKeyPair_lower(_ value: SigningKeyPair) -> UInt64 { return FfiConverterTypeSigningKeyPair.lower(value) } -public struct KeyPair { - public var publicKey: Data +public struct KeyPair: Equatable, Hashable { public var privateKey: Data + public var publicKey: Data // Default memberwise initializers are never public by default, so we // declare one manually. - public init(publicKey: Data, privateKey: Data) { - self.publicKey = publicKey + public init(privateKey: Data, publicKey: Data) { self.privateKey = privateKey + self.publicKey = publicKey } + + } #if compiler(>=6) extension KeyPair: Sendable {} #endif - -extension KeyPair: Equatable, Hashable { - public static func ==(lhs: KeyPair, rhs: KeyPair) -> Bool { - if lhs.publicKey != rhs.publicKey { - return false - } - if lhs.privateKey != rhs.privateKey { - return false - } - return true - } - - public func hash(into hasher: inout Hasher) { - hasher.combine(publicKey) - hasher.combine(privateKey) - } -} - - - #if swift(>=5.8) @_documentation(visibility: private) #endif @@ -1054,14 +1033,14 @@ public struct FfiConverterTypeKeyPair: FfiConverterRustBuffer { public static func read(from buf: inout (data: Data, offset: Data.Index)) throws -> KeyPair { return try KeyPair( - publicKey: FfiConverterData.read(from: &buf), - privateKey: FfiConverterData.read(from: &buf) + privateKey: FfiConverterData.read(from: &buf), + publicKey: FfiConverterData.read(from: &buf) ) } public static func write(_ value: KeyPair, into buf: inout [UInt8]) { - FfiConverterData.write(value.publicKey, into: &buf) FfiConverterData.write(value.privateKey, into: &buf) + FfiConverterData.write(value.publicKey, into: &buf) } } @@ -1083,14 +1062,16 @@ public func FfiConverterTypeKeyPair_lower(_ value: KeyPair) -> RustBuffer { // Note that we don't yet support `indirect` for enums. // See https://github.com/mozilla/uniffi-rs/issues/396 for further discussion. -public enum Argon2Variant { +public enum Argon2Variant: Equatable, Hashable { case argon2d case argon2i case argon2id -} + +} + #if compiler(>=6) extension Argon2Variant: Sendable {} #endif @@ -1150,20 +1131,18 @@ public func FfiConverterTypeArgon2Variant_lower(_ value: Argon2Variant) -> RustB } -extension Argon2Variant: Equatable, Hashable {} - - - // Note that we don't yet support `indirect` for enums. // See https://github.com/mozilla/uniffi-rs/issues/396 for further discussion. -public enum Argon2Version { +public enum Argon2Version: Equatable, Hashable { case version10 case version13 -} + +} + #if compiler(>=6) extension Argon2Version: Sendable {} #endif @@ -1217,756 +1196,169 @@ public func FfiConverterTypeArgon2Version_lower(_ value: Argon2Version) -> RustB } -extension Argon2Version: Equatable, Hashable {} - - - -// Note that we don't yet support `indirect` for enums. -// See https://github.com/mozilla/uniffi-rs/issues/396 for further discussion. - -public enum CiphertextVersion { - - case latest - case v1 - case v2 -} - - -#if compiler(>=6) -extension CiphertextVersion: Sendable {} -#endif - #if swift(>=5.8) @_documentation(visibility: private) #endif -public struct FfiConverterTypeCiphertextVersion: FfiConverterRustBuffer { - typealias SwiftType = CiphertextVersion +fileprivate struct FfiConverterOptionData: FfiConverterRustBuffer { + typealias SwiftType = Data? - public static func read(from buf: inout (data: Data, offset: Data.Index)) throws -> CiphertextVersion { - let variant: Int32 = try readInt(&buf) - switch variant { - - case 1: return .latest - - case 2: return .v1 - - case 3: return .v2 - - default: throw UniffiInternalError.unexpectedEnumCase + public static func write(_ value: SwiftType, into buf: inout [UInt8]) { + guard let value = value else { + writeInt(&buf, Int8(0)) + return } + writeInt(&buf, Int8(1)) + FfiConverterData.write(value, into: &buf) } - public static func write(_ value: CiphertextVersion, into buf: inout [UInt8]) { - switch value { - - - case .latest: - writeInt(&buf, Int32(1)) - - - case .v1: - writeInt(&buf, Int32(2)) - - - case .v2: - writeInt(&buf, Int32(3)) - + public static func read(from buf: inout (data: Data, offset: Data.Index)) throws -> SwiftType { + switch try readInt(&buf) as Int8 { + case 0: return nil + case 1: return try FfiConverterData.read(from: &buf) + default: throw UniffiInternalError.unexpectedOptionalTag } } } - #if swift(>=5.8) @_documentation(visibility: private) #endif -public func FfiConverterTypeCiphertextVersion_lift(_ buf: RustBuffer) throws -> CiphertextVersion { - return try FfiConverterTypeCiphertextVersion.lift(buf) +fileprivate struct FfiConverterOptionTypeCiphertextVersion: FfiConverterRustBuffer { + typealias SwiftType = CiphertextVersion? + + public static func write(_ value: SwiftType, into buf: inout [UInt8]) { + guard let value = value else { + writeInt(&buf, Int8(0)) + return + } + writeInt(&buf, Int8(1)) + FfiConverterTypeCiphertextVersion.write(value, into: &buf) + } + + public static func read(from buf: inout (data: Data, offset: Data.Index)) throws -> SwiftType { + switch try readInt(&buf) as Int8 { + case 0: return nil + case 1: return try FfiConverterTypeCiphertextVersion.read(from: &buf) + default: throw UniffiInternalError.unexpectedOptionalTag + } + } } #if swift(>=5.8) @_documentation(visibility: private) #endif -public func FfiConverterTypeCiphertextVersion_lower(_ value: CiphertextVersion) -> RustBuffer { - return FfiConverterTypeCiphertextVersion.lower(value) -} - - -extension CiphertextVersion: Equatable, Hashable {} - +fileprivate struct FfiConverterOptionTypeKeyVersion: FfiConverterRustBuffer { + typealias SwiftType = KeyVersion? + public static func write(_ value: SwiftType, into buf: inout [UInt8]) { + guard let value = value else { + writeInt(&buf, Int8(0)) + return + } + writeInt(&buf, Int8(1)) + FfiConverterTypeKeyVersion.write(value, into: &buf) + } -// Note that we don't yet support `indirect` for enums. -// See https://github.com/mozilla/uniffi-rs/issues/396 for further discussion. - -public enum DataType { - - case none - case key - case ciphertext - case passwordHash - case share - case signingKey - case signature - case onlineCiphertext + public static func read(from buf: inout (data: Data, offset: Data.Index)) throws -> SwiftType { + switch try readInt(&buf) as Int8 { + case 0: return nil + case 1: return try FfiConverterTypeKeyVersion.read(from: &buf) + default: throw UniffiInternalError.unexpectedOptionalTag + } + } } - -#if compiler(>=6) -extension DataType: Sendable {} -#endif - #if swift(>=5.8) @_documentation(visibility: private) #endif -public struct FfiConverterTypeDataType: FfiConverterRustBuffer { - typealias SwiftType = DataType +fileprivate struct FfiConverterOptionTypePasswordHashVersion: FfiConverterRustBuffer { + typealias SwiftType = PasswordHashVersion? - public static func read(from buf: inout (data: Data, offset: Data.Index)) throws -> DataType { - let variant: Int32 = try readInt(&buf) - switch variant { - - case 1: return .none - - case 2: return .key - - case 3: return .ciphertext - - case 4: return .passwordHash - - case 5: return .share - - case 6: return .signingKey - - case 7: return .signature - - case 8: return .onlineCiphertext - - default: throw UniffiInternalError.unexpectedEnumCase + public static func write(_ value: SwiftType, into buf: inout [UInt8]) { + guard let value = value else { + writeInt(&buf, Int8(0)) + return } + writeInt(&buf, Int8(1)) + FfiConverterTypePasswordHashVersion.write(value, into: &buf) } - public static func write(_ value: DataType, into buf: inout [UInt8]) { - switch value { - - - case .none: - writeInt(&buf, Int32(1)) - - - case .key: - writeInt(&buf, Int32(2)) - - - case .ciphertext: - writeInt(&buf, Int32(3)) - - - case .passwordHash: - writeInt(&buf, Int32(4)) - - - case .share: - writeInt(&buf, Int32(5)) - - - case .signingKey: - writeInt(&buf, Int32(6)) - - - case .signature: - writeInt(&buf, Int32(7)) - - - case .onlineCiphertext: - writeInt(&buf, Int32(8)) - + public static func read(from buf: inout (data: Data, offset: Data.Index)) throws -> SwiftType { + switch try readInt(&buf) as Int8 { + case 0: return nil + case 1: return try FfiConverterTypePasswordHashVersion.read(from: &buf) + default: throw UniffiInternalError.unexpectedOptionalTag } } } - #if swift(>=5.8) @_documentation(visibility: private) #endif -public func FfiConverterTypeDataType_lift(_ buf: RustBuffer) throws -> DataType { - return try FfiConverterTypeDataType.lift(buf) +fileprivate struct FfiConverterOptionTypeSecretSharingVersion: FfiConverterRustBuffer { + typealias SwiftType = SecretSharingVersion? + + public static func write(_ value: SwiftType, into buf: inout [UInt8]) { + guard let value = value else { + writeInt(&buf, Int8(0)) + return + } + writeInt(&buf, Int8(1)) + FfiConverterTypeSecretSharingVersion.write(value, into: &buf) + } + + public static func read(from buf: inout (data: Data, offset: Data.Index)) throws -> SwiftType { + switch try readInt(&buf) as Int8 { + case 0: return nil + case 1: return try FfiConverterTypeSecretSharingVersion.read(from: &buf) + default: throw UniffiInternalError.unexpectedOptionalTag + } + } } #if swift(>=5.8) @_documentation(visibility: private) #endif -public func FfiConverterTypeDataType_lower(_ value: DataType) -> RustBuffer { - return FfiConverterTypeDataType.lower(value) -} - - -extension DataType: Equatable, Hashable {} - - +fileprivate struct FfiConverterOptionTypeSignatureVersion: FfiConverterRustBuffer { + typealias SwiftType = SignatureVersion? + public static func write(_ value: SwiftType, into buf: inout [UInt8]) { + guard let value = value else { + writeInt(&buf, Int8(0)) + return + } + writeInt(&buf, Int8(1)) + FfiConverterTypeSignatureVersion.write(value, into: &buf) + } -public enum DevolutionsCryptoError: Swift.Error { - - - - case InvalidLength(message: String) - - case InvalidKeyLength(message: String) - - case InvalidOutputLength(message: String) - - case InvalidSignature(message: String) - - case InvalidMac(message: String) - - case InvalidDataType(message: String) - - case UnknownType(message: String) - - case UnknownSubtype(message: String) - - case UnknownVersion(message: String) - - case InvalidData(message: String) - - case NullPointer(message: String) - - case CryptoError(message: String) - - case RandomError(message: String) - - case IoError(message: String) - - case NotEnoughShares(message: String) - - case InconsistentVersion(message: String) - - case InvalidChunkLength(message: String) - - case PoisonedMutex(message: String) - + public static func read(from buf: inout (data: Data, offset: Data.Index)) throws -> SwiftType { + switch try readInt(&buf) as Int8 { + case 0: return nil + case 1: return try FfiConverterTypeSignatureVersion.read(from: &buf) + default: throw UniffiInternalError.unexpectedOptionalTag + } + } } - #if swift(>=5.8) @_documentation(visibility: private) #endif -public struct FfiConverterTypeDevolutionsCryptoError: FfiConverterRustBuffer { - typealias SwiftType = DevolutionsCryptoError - - public static func read(from buf: inout (data: Data, offset: Data.Index)) throws -> DevolutionsCryptoError { - let variant: Int32 = try readInt(&buf) - switch variant { +fileprivate struct FfiConverterOptionTypeSigningKeyVersion: FfiConverterRustBuffer { + typealias SwiftType = SigningKeyVersion? - - - - case 1: return .InvalidLength( - message: try FfiConverterString.read(from: &buf) - ) - - case 2: return .InvalidKeyLength( - message: try FfiConverterString.read(from: &buf) - ) - - case 3: return .InvalidOutputLength( - message: try FfiConverterString.read(from: &buf) - ) - - case 4: return .InvalidSignature( - message: try FfiConverterString.read(from: &buf) - ) - - case 5: return .InvalidMac( - message: try FfiConverterString.read(from: &buf) - ) - - case 6: return .InvalidDataType( - message: try FfiConverterString.read(from: &buf) - ) - - case 7: return .UnknownType( - message: try FfiConverterString.read(from: &buf) - ) - - case 8: return .UnknownSubtype( - message: try FfiConverterString.read(from: &buf) - ) - - case 9: return .UnknownVersion( - message: try FfiConverterString.read(from: &buf) - ) - - case 10: return .InvalidData( - message: try FfiConverterString.read(from: &buf) - ) - - case 11: return .NullPointer( - message: try FfiConverterString.read(from: &buf) - ) - - case 12: return .CryptoError( - message: try FfiConverterString.read(from: &buf) - ) - - case 13: return .RandomError( - message: try FfiConverterString.read(from: &buf) - ) - - case 14: return .IoError( - message: try FfiConverterString.read(from: &buf) - ) - - case 15: return .NotEnoughShares( - message: try FfiConverterString.read(from: &buf) - ) - - case 16: return .InconsistentVersion( - message: try FfiConverterString.read(from: &buf) - ) - - case 17: return .InvalidChunkLength( - message: try FfiConverterString.read(from: &buf) - ) - - case 18: return .PoisonedMutex( - message: try FfiConverterString.read(from: &buf) - ) - - - default: throw UniffiInternalError.unexpectedEnumCase - } - } - - public static func write(_ value: DevolutionsCryptoError, into buf: inout [UInt8]) { - switch value { - - - - - case .InvalidLength(_ /* message is ignored*/): - writeInt(&buf, Int32(1)) - case .InvalidKeyLength(_ /* message is ignored*/): - writeInt(&buf, Int32(2)) - case .InvalidOutputLength(_ /* message is ignored*/): - writeInt(&buf, Int32(3)) - case .InvalidSignature(_ /* message is ignored*/): - writeInt(&buf, Int32(4)) - case .InvalidMac(_ /* message is ignored*/): - writeInt(&buf, Int32(5)) - case .InvalidDataType(_ /* message is ignored*/): - writeInt(&buf, Int32(6)) - case .UnknownType(_ /* message is ignored*/): - writeInt(&buf, Int32(7)) - case .UnknownSubtype(_ /* message is ignored*/): - writeInt(&buf, Int32(8)) - case .UnknownVersion(_ /* message is ignored*/): - writeInt(&buf, Int32(9)) - case .InvalidData(_ /* message is ignored*/): - writeInt(&buf, Int32(10)) - case .NullPointer(_ /* message is ignored*/): - writeInt(&buf, Int32(11)) - case .CryptoError(_ /* message is ignored*/): - writeInt(&buf, Int32(12)) - case .RandomError(_ /* message is ignored*/): - writeInt(&buf, Int32(13)) - case .IoError(_ /* message is ignored*/): - writeInt(&buf, Int32(14)) - case .NotEnoughShares(_ /* message is ignored*/): - writeInt(&buf, Int32(15)) - case .InconsistentVersion(_ /* message is ignored*/): - writeInt(&buf, Int32(16)) - case .InvalidChunkLength(_ /* message is ignored*/): - writeInt(&buf, Int32(17)) - case .PoisonedMutex(_ /* message is ignored*/): - writeInt(&buf, Int32(18)) - - - } - } -} - - -#if swift(>=5.8) -@_documentation(visibility: private) -#endif -public func FfiConverterTypeDevolutionsCryptoError_lift(_ buf: RustBuffer) throws -> DevolutionsCryptoError { - return try FfiConverterTypeDevolutionsCryptoError.lift(buf) -} - -#if swift(>=5.8) -@_documentation(visibility: private) -#endif -public func FfiConverterTypeDevolutionsCryptoError_lower(_ value: DevolutionsCryptoError) -> RustBuffer { - return FfiConverterTypeDevolutionsCryptoError.lower(value) -} - - -extension DevolutionsCryptoError: Equatable, Hashable {} - - - -extension DevolutionsCryptoError: Foundation.LocalizedError { - public var errorDescription: String? { - String(reflecting: self) - } -} - - -// Note that we don't yet support `indirect` for enums. -// See https://github.com/mozilla/uniffi-rs/issues/396 for further discussion. - -public enum KeyVersion { - - case latest - case v1 -} - - -#if compiler(>=6) -extension KeyVersion: Sendable {} -#endif - -#if swift(>=5.8) -@_documentation(visibility: private) -#endif -public struct FfiConverterTypeKeyVersion: FfiConverterRustBuffer { - typealias SwiftType = KeyVersion - - public static func read(from buf: inout (data: Data, offset: Data.Index)) throws -> KeyVersion { - let variant: Int32 = try readInt(&buf) - switch variant { - - case 1: return .latest - - case 2: return .v1 - - default: throw UniffiInternalError.unexpectedEnumCase - } - } - - public static func write(_ value: KeyVersion, into buf: inout [UInt8]) { - switch value { - - - case .latest: - writeInt(&buf, Int32(1)) - - - case .v1: - writeInt(&buf, Int32(2)) - - } - } -} - - -#if swift(>=5.8) -@_documentation(visibility: private) -#endif -public func FfiConverterTypeKeyVersion_lift(_ buf: RustBuffer) throws -> KeyVersion { - return try FfiConverterTypeKeyVersion.lift(buf) -} - -#if swift(>=5.8) -@_documentation(visibility: private) -#endif -public func FfiConverterTypeKeyVersion_lower(_ value: KeyVersion) -> RustBuffer { - return FfiConverterTypeKeyVersion.lower(value) -} - - -extension KeyVersion: Equatable, Hashable {} - - - -// Note that we don't yet support `indirect` for enums. -// See https://github.com/mozilla/uniffi-rs/issues/396 for further discussion. - -public enum PasswordHashVersion { - - case latest - case v1 -} - - -#if compiler(>=6) -extension PasswordHashVersion: Sendable {} -#endif - -#if swift(>=5.8) -@_documentation(visibility: private) -#endif -public struct FfiConverterTypePasswordHashVersion: FfiConverterRustBuffer { - typealias SwiftType = PasswordHashVersion - - public static func read(from buf: inout (data: Data, offset: Data.Index)) throws -> PasswordHashVersion { - let variant: Int32 = try readInt(&buf) - switch variant { - - case 1: return .latest - - case 2: return .v1 - - default: throw UniffiInternalError.unexpectedEnumCase - } - } - - public static func write(_ value: PasswordHashVersion, into buf: inout [UInt8]) { - switch value { - - - case .latest: - writeInt(&buf, Int32(1)) - - - case .v1: - writeInt(&buf, Int32(2)) - - } - } -} - - -#if swift(>=5.8) -@_documentation(visibility: private) -#endif -public func FfiConverterTypePasswordHashVersion_lift(_ buf: RustBuffer) throws -> PasswordHashVersion { - return try FfiConverterTypePasswordHashVersion.lift(buf) -} - -#if swift(>=5.8) -@_documentation(visibility: private) -#endif -public func FfiConverterTypePasswordHashVersion_lower(_ value: PasswordHashVersion) -> RustBuffer { - return FfiConverterTypePasswordHashVersion.lower(value) -} - - -extension PasswordHashVersion: Equatable, Hashable {} - - - -// Note that we don't yet support `indirect` for enums. -// See https://github.com/mozilla/uniffi-rs/issues/396 for further discussion. - -public enum SecretSharingVersion { - - case latest - case v1 -} - - -#if compiler(>=6) -extension SecretSharingVersion: Sendable {} -#endif - -#if swift(>=5.8) -@_documentation(visibility: private) -#endif -public struct FfiConverterTypeSecretSharingVersion: FfiConverterRustBuffer { - typealias SwiftType = SecretSharingVersion - - public static func read(from buf: inout (data: Data, offset: Data.Index)) throws -> SecretSharingVersion { - let variant: Int32 = try readInt(&buf) - switch variant { - - case 1: return .latest - - case 2: return .v1 - - default: throw UniffiInternalError.unexpectedEnumCase - } - } - - public static func write(_ value: SecretSharingVersion, into buf: inout [UInt8]) { - switch value { - - - case .latest: - writeInt(&buf, Int32(1)) - - - case .v1: - writeInt(&buf, Int32(2)) - - } - } -} - - -#if swift(>=5.8) -@_documentation(visibility: private) -#endif -public func FfiConverterTypeSecretSharingVersion_lift(_ buf: RustBuffer) throws -> SecretSharingVersion { - return try FfiConverterTypeSecretSharingVersion.lift(buf) -} - -#if swift(>=5.8) -@_documentation(visibility: private) -#endif -public func FfiConverterTypeSecretSharingVersion_lower(_ value: SecretSharingVersion) -> RustBuffer { - return FfiConverterTypeSecretSharingVersion.lower(value) -} - - -extension SecretSharingVersion: Equatable, Hashable {} - - - -// Note that we don't yet support `indirect` for enums. -// See https://github.com/mozilla/uniffi-rs/issues/396 for further discussion. - -public enum SignatureVersion { - - case latest - case v1 -} - - -#if compiler(>=6) -extension SignatureVersion: Sendable {} -#endif - -#if swift(>=5.8) -@_documentation(visibility: private) -#endif -public struct FfiConverterTypeSignatureVersion: FfiConverterRustBuffer { - typealias SwiftType = SignatureVersion - - public static func read(from buf: inout (data: Data, offset: Data.Index)) throws -> SignatureVersion { - let variant: Int32 = try readInt(&buf) - switch variant { - - case 1: return .latest - - case 2: return .v1 - - default: throw UniffiInternalError.unexpectedEnumCase - } - } - - public static func write(_ value: SignatureVersion, into buf: inout [UInt8]) { - switch value { - - - case .latest: - writeInt(&buf, Int32(1)) - - - case .v1: - writeInt(&buf, Int32(2)) - - } - } -} - - -#if swift(>=5.8) -@_documentation(visibility: private) -#endif -public func FfiConverterTypeSignatureVersion_lift(_ buf: RustBuffer) throws -> SignatureVersion { - return try FfiConverterTypeSignatureVersion.lift(buf) -} - -#if swift(>=5.8) -@_documentation(visibility: private) -#endif -public func FfiConverterTypeSignatureVersion_lower(_ value: SignatureVersion) -> RustBuffer { - return FfiConverterTypeSignatureVersion.lower(value) -} - - -extension SignatureVersion: Equatable, Hashable {} - - - -// Note that we don't yet support `indirect` for enums. -// See https://github.com/mozilla/uniffi-rs/issues/396 for further discussion. - -public enum SigningKeyVersion { - - case latest - case v1 -} - - -#if compiler(>=6) -extension SigningKeyVersion: Sendable {} -#endif - -#if swift(>=5.8) -@_documentation(visibility: private) -#endif -public struct FfiConverterTypeSigningKeyVersion: FfiConverterRustBuffer { - typealias SwiftType = SigningKeyVersion - - public static func read(from buf: inout (data: Data, offset: Data.Index)) throws -> SigningKeyVersion { - let variant: Int32 = try readInt(&buf) - switch variant { - - case 1: return .latest - - case 2: return .v1 - - default: throw UniffiInternalError.unexpectedEnumCase - } - } - - public static func write(_ value: SigningKeyVersion, into buf: inout [UInt8]) { - switch value { - - - case .latest: - writeInt(&buf, Int32(1)) - - - case .v1: - writeInt(&buf, Int32(2)) - - } - } -} - - -#if swift(>=5.8) -@_documentation(visibility: private) -#endif -public func FfiConverterTypeSigningKeyVersion_lift(_ buf: RustBuffer) throws -> SigningKeyVersion { - return try FfiConverterTypeSigningKeyVersion.lift(buf) -} - -#if swift(>=5.8) -@_documentation(visibility: private) -#endif -public func FfiConverterTypeSigningKeyVersion_lower(_ value: SigningKeyVersion) -> RustBuffer { - return FfiConverterTypeSigningKeyVersion.lower(value) -} - - -extension SigningKeyVersion: Equatable, Hashable {} - - - -#if swift(>=5.8) -@_documentation(visibility: private) -#endif -fileprivate struct FfiConverterOptionData: FfiConverterRustBuffer { - typealias SwiftType = Data? - - public static func write(_ value: SwiftType, into buf: inout [UInt8]) { - guard let value = value else { - writeInt(&buf, Int8(0)) - return - } - writeInt(&buf, Int8(1)) - FfiConverterData.write(value, into: &buf) - } + public static func write(_ value: SwiftType, into buf: inout [UInt8]) { + guard let value = value else { + writeInt(&buf, Int8(0)) + return + } + writeInt(&buf, Int8(1)) + FfiConverterTypeSigningKeyVersion.write(value, into: &buf) + } public static func read(from buf: inout (data: Data, offset: Data.Index)) throws -> SwiftType { switch try readInt(&buf) as Int8 { case 0: return nil - case 1: return try FfiConverterData.read(from: &buf) + case 1: return try FfiConverterTypeSigningKeyVersion.read(from: &buf) default: throw UniffiInternalError.unexpectedOptionalTag } } @@ -1997,14 +1389,14 @@ fileprivate struct FfiConverterSequenceData: FfiConverterRustBuffer { } } public func base64Decode(data: String)throws -> Data { - return try FfiConverterData.lift(try rustCallWithError(FfiConverterTypeDevolutionsCryptoError_lift) { + return try FfiConverterData.lift(try rustCallWithError(FfiConverterTypeError_lift) { uniffi_devolutions_crypto_uniffi_fn_func_base64_decode( FfiConverterString.lower(data),$0 ) }) } public func base64DecodeUrl(data: String)throws -> Data { - return try FfiConverterData.lift(try rustCallWithError(FfiConverterTypeDevolutionsCryptoError_lift) { + return try FfiConverterData.lift(try rustCallWithError(FfiConverterTypeError_lift) { uniffi_devolutions_crypto_uniffi_fn_func_base64_decode_url( FfiConverterString.lower(data),$0 ) @@ -2025,7 +1417,7 @@ public func base64EncodeUrl(data: Data) -> String { }) } public func decrypt(data: Data, key: Data)throws -> Data { - return try FfiConverterData.lift(try rustCallWithError(FfiConverterTypeDevolutionsCryptoError_lift) { + return try FfiConverterData.lift(try rustCallWithError(FfiConverterTypeError_lift) { uniffi_devolutions_crypto_uniffi_fn_func_decrypt( FfiConverterData.lower(data), FfiConverterData.lower(key),$0 @@ -2033,7 +1425,7 @@ public func decrypt(data: Data, key: Data)throws -> Data { }) } public func decryptAsymmetric(data: Data, key: Data)throws -> Data { - return try FfiConverterData.lift(try rustCallWithError(FfiConverterTypeDevolutionsCryptoError_lift) { + return try FfiConverterData.lift(try rustCallWithError(FfiConverterTypeError_lift) { uniffi_devolutions_crypto_uniffi_fn_func_decrypt_asymmetric( FfiConverterData.lower(data), FfiConverterData.lower(key),$0 @@ -2041,7 +1433,7 @@ public func decryptAsymmetric(data: Data, key: Data)throws -> Data { }) } public func decryptAsymmetricWithAad(data: Data, key: Data, aad: Data)throws -> Data { - return try FfiConverterData.lift(try rustCallWithError(FfiConverterTypeDevolutionsCryptoError_lift) { + return try FfiConverterData.lift(try rustCallWithError(FfiConverterTypeError_lift) { uniffi_devolutions_crypto_uniffi_fn_func_decrypt_asymmetric_with_aad( FfiConverterData.lower(data), FfiConverterData.lower(key), @@ -2050,7 +1442,7 @@ public func decryptAsymmetricWithAad(data: Data, key: Data, aad: Data)throws -> }) } public func decryptWithAad(data: Data, key: Data, aad: Data)throws -> Data { - return try FfiConverterData.lift(try rustCallWithError(FfiConverterTypeDevolutionsCryptoError_lift) { + return try FfiConverterData.lift(try rustCallWithError(FfiConverterTypeError_lift) { uniffi_devolutions_crypto_uniffi_fn_func_decrypt_with_aad( FfiConverterData.lower(data), FfiConverterData.lower(key), @@ -2059,7 +1451,7 @@ public func decryptWithAad(data: Data, key: Data, aad: Data)throws -> Data { }) } public func deriveKeyArgon2(key: Data, parameters: Argon2Parameters)throws -> Data { - return try FfiConverterData.lift(try rustCallWithError(FfiConverterTypeDevolutionsCryptoError_lift) { + return try FfiConverterData.lift(try rustCallWithError(FfiConverterTypeError_lift) { uniffi_devolutions_crypto_uniffi_fn_func_derive_key_argon2( FfiConverterData.lower(key), FfiConverterTypeArgon2Parameters_lower(parameters),$0 @@ -2076,105 +1468,105 @@ public func deriveKeyPbkdf2(key: Data, salt: Data?, iterations: UInt32 = UInt32( ) }) } -public func encrypt(data: Data, key: Data, version: CiphertextVersion = .latest)throws -> Data { - return try FfiConverterData.lift(try rustCallWithError(FfiConverterTypeDevolutionsCryptoError_lift) { +public func encrypt(data: Data, key: Data, version: CiphertextVersion? = nil)throws -> Data { + return try FfiConverterData.lift(try rustCallWithError(FfiConverterTypeError_lift) { uniffi_devolutions_crypto_uniffi_fn_func_encrypt( FfiConverterData.lower(data), FfiConverterData.lower(key), - FfiConverterTypeCiphertextVersion_lower(version),$0 + FfiConverterOptionTypeCiphertextVersion.lower(version),$0 ) }) } -public func encryptAsymmetric(data: Data, key: Data, version: CiphertextVersion = .latest)throws -> Data { - return try FfiConverterData.lift(try rustCallWithError(FfiConverterTypeDevolutionsCryptoError_lift) { +public func encryptAsymmetric(data: Data, key: Data, version: CiphertextVersion? = nil)throws -> Data { + return try FfiConverterData.lift(try rustCallWithError(FfiConverterTypeError_lift) { uniffi_devolutions_crypto_uniffi_fn_func_encrypt_asymmetric( FfiConverterData.lower(data), FfiConverterData.lower(key), - FfiConverterTypeCiphertextVersion_lower(version),$0 + FfiConverterOptionTypeCiphertextVersion.lower(version),$0 ) }) } -public func encryptAsymmetricWithAad(data: Data, key: Data, aad: Data, version: CiphertextVersion = .latest)throws -> Data { - return try FfiConverterData.lift(try rustCallWithError(FfiConverterTypeDevolutionsCryptoError_lift) { +public func encryptAsymmetricWithAad(data: Data, key: Data, aad: Data, version: CiphertextVersion? = nil)throws -> Data { + return try FfiConverterData.lift(try rustCallWithError(FfiConverterTypeError_lift) { uniffi_devolutions_crypto_uniffi_fn_func_encrypt_asymmetric_with_aad( FfiConverterData.lower(data), FfiConverterData.lower(key), FfiConverterData.lower(aad), - FfiConverterTypeCiphertextVersion_lower(version),$0 + FfiConverterOptionTypeCiphertextVersion.lower(version),$0 ) }) } -public func encryptWithAad(data: Data, key: Data, aad: Data, version: CiphertextVersion = .latest)throws -> Data { - return try FfiConverterData.lift(try rustCallWithError(FfiConverterTypeDevolutionsCryptoError_lift) { +public func encryptWithAad(data: Data, key: Data, aad: Data, version: CiphertextVersion? = nil)throws -> Data { + return try FfiConverterData.lift(try rustCallWithError(FfiConverterTypeError_lift) { uniffi_devolutions_crypto_uniffi_fn_func_encrypt_with_aad( FfiConverterData.lower(data), FfiConverterData.lower(key), FfiConverterData.lower(aad), - FfiConverterTypeCiphertextVersion_lower(version),$0 + FfiConverterOptionTypeCiphertextVersion.lower(version),$0 ) }) } public func generateKey(length: UInt32 = UInt32(32))throws -> Data { - return try FfiConverterData.lift(try rustCallWithError(FfiConverterTypeDevolutionsCryptoError_lift) { + return try FfiConverterData.lift(try rustCallWithError(FfiConverterTypeError_lift) { uniffi_devolutions_crypto_uniffi_fn_func_generate_key( FfiConverterUInt32.lower(length),$0 ) }) } -public func generateKeypair(version: KeyVersion = .latest) -> KeyPair { +public func generateKeypair(version: KeyVersion? = nil) -> KeyPair { return try! FfiConverterTypeKeyPair_lift(try! rustCall() { uniffi_devolutions_crypto_uniffi_fn_func_generate_keypair( - FfiConverterTypeKeyVersion_lower(version),$0 + FfiConverterOptionTypeKeyVersion.lower(version),$0 ) }) } -public func generateSharedKey(nShares: UInt8, threshold: UInt8, length: UInt32 = UInt32(32), version: SecretSharingVersion = .latest)throws -> [Data] { - return try FfiConverterSequenceData.lift(try rustCallWithError(FfiConverterTypeDevolutionsCryptoError_lift) { +public func generateSharedKey(nShares: UInt8, threshold: UInt8, length: UInt32 = UInt32(32), version: SecretSharingVersion? = nil)throws -> [Data] { + return try FfiConverterSequenceData.lift(try rustCallWithError(FfiConverterTypeError_lift) { uniffi_devolutions_crypto_uniffi_fn_func_generate_shared_key( FfiConverterUInt8.lower(nShares), FfiConverterUInt8.lower(threshold), FfiConverterUInt32.lower(length), - FfiConverterTypeSecretSharingVersion_lower(version),$0 + FfiConverterOptionTypeSecretSharingVersion.lower(version),$0 ) }) } -public func generateSigningKeypair(version: SigningKeyVersion = .latest) -> SigningKeyPair { +public func generateSigningKeypair(version: SigningKeyVersion? = nil) -> SigningKeyPair { return try! FfiConverterTypeSigningKeyPair_lift(try! rustCall() { uniffi_devolutions_crypto_uniffi_fn_func_generate_signing_keypair( - FfiConverterTypeSigningKeyVersion_lower(version),$0 + FfiConverterOptionTypeSigningKeyVersion.lower(version),$0 ) }) } -public func hashPassword(password: Data, iterations: UInt32 = UInt32(10000), version: PasswordHashVersion = .latest)throws -> Data { - return try FfiConverterData.lift(try rustCallWithError(FfiConverterTypeDevolutionsCryptoError_lift) { +public func hashPassword(password: Data, iterations: UInt32 = UInt32(10000), version: PasswordHashVersion? = nil)throws -> Data { + return try FfiConverterData.lift(try rustCallWithError(FfiConverterTypeError_lift) { uniffi_devolutions_crypto_uniffi_fn_func_hash_password( FfiConverterData.lower(password), FfiConverterUInt32.lower(iterations), - FfiConverterTypePasswordHashVersion_lower(version),$0 + FfiConverterOptionTypePasswordHashVersion.lower(version),$0 ) }) } public func joinShares(shares: [Data])throws -> Data { - return try FfiConverterData.lift(try rustCallWithError(FfiConverterTypeDevolutionsCryptoError_lift) { + return try FfiConverterData.lift(try rustCallWithError(FfiConverterTypeError_lift) { uniffi_devolutions_crypto_uniffi_fn_func_join_shares( FfiConverterSequenceData.lower(shares),$0 ) }) } public func mixKeyExchange(privateKey: Data, publicKey: Data)throws -> Data { - return try FfiConverterData.lift(try rustCallWithError(FfiConverterTypeDevolutionsCryptoError_lift) { + return try FfiConverterData.lift(try rustCallWithError(FfiConverterTypeError_lift) { uniffi_devolutions_crypto_uniffi_fn_func_mix_key_exchange( FfiConverterData.lower(privateKey), FfiConverterData.lower(publicKey),$0 ) }) } -public func sign(data: Data, keypair: Data, version: SignatureVersion = .latest)throws -> Data { - return try FfiConverterData.lift(try rustCallWithError(FfiConverterTypeDevolutionsCryptoError_lift) { +public func sign(data: Data, keypair: Data, version: SignatureVersion? = nil)throws -> Data { + return try FfiConverterData.lift(try rustCallWithError(FfiConverterTypeError_lift) { uniffi_devolutions_crypto_uniffi_fn_func_sign( FfiConverterData.lower(data), FfiConverterData.lower(keypair), - FfiConverterTypeSignatureVersion_lower(version),$0 + FfiConverterOptionTypeSignatureVersion.lower(version),$0 ) }) } @@ -2187,7 +1579,7 @@ public func validateHeader(data: Data, dataType: DataType) -> Bool { }) } public func verifyPassword(password: Data, hash: Data)throws -> Bool { - return try FfiConverterBool.lift(try rustCallWithError(FfiConverterTypeDevolutionsCryptoError_lift) { + return try FfiConverterBool.lift(try rustCallWithError(FfiConverterTypeError_lift) { uniffi_devolutions_crypto_uniffi_fn_func_verify_password( FfiConverterData.lower(password), FfiConverterData.lower(hash),$0 @@ -2195,7 +1587,7 @@ public func verifyPassword(password: Data, hash: Data)throws -> Bool { }) } public func verifySignature(data: Data, publicKey: Data, signature: Data)throws -> Bool { - return try FfiConverterBool.lift(try rustCallWithError(FfiConverterTypeDevolutionsCryptoError_lift) { + return try FfiConverterBool.lift(try rustCallWithError(FfiConverterTypeError_lift) { uniffi_devolutions_crypto_uniffi_fn_func_verify_signature( FfiConverterData.lower(data), FfiConverterData.lower(publicKey), @@ -2213,16 +1605,16 @@ private enum InitializationResult { // the code inside is only computed once. private let initializationResult: InitializationResult = { // Get the bindings contract version from our ComponentInterface - let bindings_contract_version = 29 + let bindings_contract_version = 30 // Get the scaffolding contract version by calling the into the dylib let scaffolding_contract_version = ffi_devolutions_crypto_uniffi_uniffi_contract_version() if bindings_contract_version != scaffolding_contract_version { return InitializationResult.contractVersionMismatch } - if (uniffi_devolutions_crypto_uniffi_checksum_func_base64_decode() != 64610) { + if (uniffi_devolutions_crypto_uniffi_checksum_func_base64_decode() != 15059) { return InitializationResult.apiChecksumMismatch } - if (uniffi_devolutions_crypto_uniffi_checksum_func_base64_decode_url() != 15029) { + if (uniffi_devolutions_crypto_uniffi_checksum_func_base64_decode_url() != 15429) { return InitializationResult.apiChecksumMismatch } if (uniffi_devolutions_crypto_uniffi_checksum_func_base64_encode() != 61134) { @@ -2231,121 +1623,122 @@ private let initializationResult: InitializationResult = { if (uniffi_devolutions_crypto_uniffi_checksum_func_base64_encode_url() != 31513) { return InitializationResult.apiChecksumMismatch } - if (uniffi_devolutions_crypto_uniffi_checksum_func_decrypt() != 41817) { + if (uniffi_devolutions_crypto_uniffi_checksum_func_decrypt() != 39921) { return InitializationResult.apiChecksumMismatch } - if (uniffi_devolutions_crypto_uniffi_checksum_func_decrypt_asymmetric() != 47124) { + if (uniffi_devolutions_crypto_uniffi_checksum_func_decrypt_asymmetric() != 6283) { return InitializationResult.apiChecksumMismatch } - if (uniffi_devolutions_crypto_uniffi_checksum_func_decrypt_asymmetric_with_aad() != 9987) { + if (uniffi_devolutions_crypto_uniffi_checksum_func_decrypt_asymmetric_with_aad() != 45166) { return InitializationResult.apiChecksumMismatch } - if (uniffi_devolutions_crypto_uniffi_checksum_func_decrypt_with_aad() != 59734) { + if (uniffi_devolutions_crypto_uniffi_checksum_func_decrypt_with_aad() != 43775) { return InitializationResult.apiChecksumMismatch } - if (uniffi_devolutions_crypto_uniffi_checksum_func_derive_key_argon2() != 60451) { + if (uniffi_devolutions_crypto_uniffi_checksum_func_derive_key_argon2() != 27403) { return InitializationResult.apiChecksumMismatch } - if (uniffi_devolutions_crypto_uniffi_checksum_func_derive_key_pbkdf2() != 12853) { + if (uniffi_devolutions_crypto_uniffi_checksum_func_derive_key_pbkdf2() != 32212) { return InitializationResult.apiChecksumMismatch } - if (uniffi_devolutions_crypto_uniffi_checksum_func_encrypt() != 21235) { + if (uniffi_devolutions_crypto_uniffi_checksum_func_encrypt() != 28651) { return InitializationResult.apiChecksumMismatch } - if (uniffi_devolutions_crypto_uniffi_checksum_func_encrypt_asymmetric() != 16258) { + if (uniffi_devolutions_crypto_uniffi_checksum_func_encrypt_asymmetric() != 17008) { return InitializationResult.apiChecksumMismatch } - if (uniffi_devolutions_crypto_uniffi_checksum_func_encrypt_asymmetric_with_aad() != 34280) { + if (uniffi_devolutions_crypto_uniffi_checksum_func_encrypt_asymmetric_with_aad() != 61461) { return InitializationResult.apiChecksumMismatch } - if (uniffi_devolutions_crypto_uniffi_checksum_func_encrypt_with_aad() != 56466) { + if (uniffi_devolutions_crypto_uniffi_checksum_func_encrypt_with_aad() != 29699) { return InitializationResult.apiChecksumMismatch } - if (uniffi_devolutions_crypto_uniffi_checksum_func_generate_key() != 6364) { + if (uniffi_devolutions_crypto_uniffi_checksum_func_generate_key() != 29427) { return InitializationResult.apiChecksumMismatch } - if (uniffi_devolutions_crypto_uniffi_checksum_func_generate_keypair() != 13437) { + if (uniffi_devolutions_crypto_uniffi_checksum_func_generate_keypair() != 38891) { return InitializationResult.apiChecksumMismatch } - if (uniffi_devolutions_crypto_uniffi_checksum_func_generate_shared_key() != 9340) { + if (uniffi_devolutions_crypto_uniffi_checksum_func_generate_shared_key() != 57051) { return InitializationResult.apiChecksumMismatch } - if (uniffi_devolutions_crypto_uniffi_checksum_func_generate_signing_keypair() != 33572) { + if (uniffi_devolutions_crypto_uniffi_checksum_func_generate_signing_keypair() != 51146) { return InitializationResult.apiChecksumMismatch } - if (uniffi_devolutions_crypto_uniffi_checksum_func_hash_password() != 41934) { + if (uniffi_devolutions_crypto_uniffi_checksum_func_hash_password() != 12769) { return InitializationResult.apiChecksumMismatch } - if (uniffi_devolutions_crypto_uniffi_checksum_func_join_shares() != 64867) { + if (uniffi_devolutions_crypto_uniffi_checksum_func_join_shares() != 65529) { return InitializationResult.apiChecksumMismatch } - if (uniffi_devolutions_crypto_uniffi_checksum_func_mix_key_exchange() != 52615) { + if (uniffi_devolutions_crypto_uniffi_checksum_func_mix_key_exchange() != 21197) { return InitializationResult.apiChecksumMismatch } - if (uniffi_devolutions_crypto_uniffi_checksum_func_sign() != 54825) { + if (uniffi_devolutions_crypto_uniffi_checksum_func_sign() != 42756) { return InitializationResult.apiChecksumMismatch } - if (uniffi_devolutions_crypto_uniffi_checksum_func_validate_header() != 50316) { + if (uniffi_devolutions_crypto_uniffi_checksum_func_validate_header() != 53669) { return InitializationResult.apiChecksumMismatch } - if (uniffi_devolutions_crypto_uniffi_checksum_func_verify_password() != 39819) { + if (uniffi_devolutions_crypto_uniffi_checksum_func_verify_password() != 7704) { return InitializationResult.apiChecksumMismatch } - if (uniffi_devolutions_crypto_uniffi_checksum_func_verify_signature() != 35870) { + if (uniffi_devolutions_crypto_uniffi_checksum_func_verify_signature() != 51084) { return InitializationResult.apiChecksumMismatch } - if (uniffi_devolutions_crypto_uniffi_checksum_method_argon2parameters_get_bytes() != 51334) { + if (uniffi_devolutions_crypto_uniffi_checksum_method_argon2parameters_get_bytes() != 26758) { return InitializationResult.apiChecksumMismatch } - if (uniffi_devolutions_crypto_uniffi_checksum_method_argon2parametersbuilder_associated_data() != 20223) { + if (uniffi_devolutions_crypto_uniffi_checksum_method_argon2parametersbuilder_associated_data() != 27028) { return InitializationResult.apiChecksumMismatch } - if (uniffi_devolutions_crypto_uniffi_checksum_method_argon2parametersbuilder_build() != 6812) { + if (uniffi_devolutions_crypto_uniffi_checksum_method_argon2parametersbuilder_build() != 8751) { return InitializationResult.apiChecksumMismatch } - if (uniffi_devolutions_crypto_uniffi_checksum_method_argon2parametersbuilder_dc_version() != 40712) { + if (uniffi_devolutions_crypto_uniffi_checksum_method_argon2parametersbuilder_dc_version() != 35235) { return InitializationResult.apiChecksumMismatch } - if (uniffi_devolutions_crypto_uniffi_checksum_method_argon2parametersbuilder_iterations() != 28254) { + if (uniffi_devolutions_crypto_uniffi_checksum_method_argon2parametersbuilder_iterations() != 15990) { return InitializationResult.apiChecksumMismatch } - if (uniffi_devolutions_crypto_uniffi_checksum_method_argon2parametersbuilder_lanes() != 3637) { + if (uniffi_devolutions_crypto_uniffi_checksum_method_argon2parametersbuilder_lanes() != 57040) { return InitializationResult.apiChecksumMismatch } - if (uniffi_devolutions_crypto_uniffi_checksum_method_argon2parametersbuilder_length() != 791) { + if (uniffi_devolutions_crypto_uniffi_checksum_method_argon2parametersbuilder_length() != 65258) { return InitializationResult.apiChecksumMismatch } - if (uniffi_devolutions_crypto_uniffi_checksum_method_argon2parametersbuilder_memory() != 14913) { + if (uniffi_devolutions_crypto_uniffi_checksum_method_argon2parametersbuilder_memory() != 41617) { return InitializationResult.apiChecksumMismatch } - if (uniffi_devolutions_crypto_uniffi_checksum_method_argon2parametersbuilder_salt() != 59352) { + if (uniffi_devolutions_crypto_uniffi_checksum_method_argon2parametersbuilder_salt() != 5080) { return InitializationResult.apiChecksumMismatch } - if (uniffi_devolutions_crypto_uniffi_checksum_method_argon2parametersbuilder_secret_key() != 38451) { + if (uniffi_devolutions_crypto_uniffi_checksum_method_argon2parametersbuilder_secret_key() != 14932) { return InitializationResult.apiChecksumMismatch } - if (uniffi_devolutions_crypto_uniffi_checksum_method_argon2parametersbuilder_variant() != 50137) { + if (uniffi_devolutions_crypto_uniffi_checksum_method_argon2parametersbuilder_variant() != 48907) { return InitializationResult.apiChecksumMismatch } - if (uniffi_devolutions_crypto_uniffi_checksum_method_argon2parametersbuilder_version() != 39743) { + if (uniffi_devolutions_crypto_uniffi_checksum_method_argon2parametersbuilder_version() != 31568) { return InitializationResult.apiChecksumMismatch } - if (uniffi_devolutions_crypto_uniffi_checksum_method_signingkeypair_get_private_key() != 10265) { + if (uniffi_devolutions_crypto_uniffi_checksum_method_signingkeypair_get_private_key() != 2977) { return InitializationResult.apiChecksumMismatch } - if (uniffi_devolutions_crypto_uniffi_checksum_method_signingkeypair_get_public_key() != 47363) { + if (uniffi_devolutions_crypto_uniffi_checksum_method_signingkeypair_get_public_key() != 50462) { return InitializationResult.apiChecksumMismatch } - if (uniffi_devolutions_crypto_uniffi_checksum_constructor_argon2parameters_new_from_bytes() != 3781) { + if (uniffi_devolutions_crypto_uniffi_checksum_constructor_argon2parameters_new_from_bytes() != 58986) { return InitializationResult.apiChecksumMismatch } - if (uniffi_devolutions_crypto_uniffi_checksum_constructor_argon2parametersbuilder_new() != 19859) { + if (uniffi_devolutions_crypto_uniffi_checksum_constructor_argon2parametersbuilder_new() != 40769) { return InitializationResult.apiChecksumMismatch } - if (uniffi_devolutions_crypto_uniffi_checksum_constructor_signingkeypair_new_from_bytes() != 17809) { + if (uniffi_devolutions_crypto_uniffi_checksum_constructor_signingkeypair_new_from_bytes() != 59560) { return InitializationResult.apiChecksumMismatch } + uniffiEnsureDevolutionsCryptoInitialized() return InitializationResult.ok }() diff --git a/wrappers/swift/DevolutionsCryptoSwift/Sources/devolutions_cryptoFFI/devolutions_cryptoFFI.h b/wrappers/swift/DevolutionsCryptoSwift/Sources/devolutions_cryptoFFI/devolutions_cryptoFFI.h index 53a69b897..fb08a2ef3 100644 --- a/wrappers/swift/DevolutionsCryptoSwift/Sources/devolutions_cryptoFFI/devolutions_cryptoFFI.h +++ b/wrappers/swift/DevolutionsCryptoSwift/Sources/devolutions_cryptoFFI/devolutions_cryptoFFI.h @@ -50,9 +50,9 @@ typedef void (*UniffiRustFutureContinuationCallback)(uint64_t, int8_t ); #endif -#ifndef UNIFFI_FFIDEF_FOREIGN_FUTURE_FREE -#define UNIFFI_FFIDEF_FOREIGN_FUTURE_FREE -typedef void (*UniffiForeignFutureFree)(uint64_t +#ifndef UNIFFI_FFIDEF_FOREIGN_FUTURE_DROPPED_CALLBACK +#define UNIFFI_FFIDEF_FOREIGN_FUTURE_DROPPED_CALLBACK +typedef void (*UniffiForeignFutureDroppedCallback)(uint64_t ); #endif @@ -62,309 +62,301 @@ typedef void (*UniffiCallbackInterfaceFree)(uint64_t ); #endif -#ifndef UNIFFI_FFIDEF_FOREIGN_FUTURE -#define UNIFFI_FFIDEF_FOREIGN_FUTURE -typedef struct UniffiForeignFuture { +#ifndef UNIFFI_FFIDEF_CALLBACK_INTERFACE_CLONE +#define UNIFFI_FFIDEF_CALLBACK_INTERFACE_CLONE +typedef uint64_t (*UniffiCallbackInterfaceClone)(uint64_t + ); + +#endif +#ifndef UNIFFI_FFIDEF_FOREIGN_FUTURE_DROPPED_CALLBACK_STRUCT +#define UNIFFI_FFIDEF_FOREIGN_FUTURE_DROPPED_CALLBACK_STRUCT +typedef struct UniffiForeignFutureDroppedCallbackStruct { uint64_t handle; - UniffiForeignFutureFree _Nonnull free; -} UniffiForeignFuture; + UniffiForeignFutureDroppedCallback _Nonnull free; +} UniffiForeignFutureDroppedCallbackStruct; #endif -#ifndef UNIFFI_FFIDEF_FOREIGN_FUTURE_STRUCT_U8 -#define UNIFFI_FFIDEF_FOREIGN_FUTURE_STRUCT_U8 -typedef struct UniffiForeignFutureStructU8 { +#ifndef UNIFFI_FFIDEF_FOREIGN_FUTURE_RESULT_U8 +#define UNIFFI_FFIDEF_FOREIGN_FUTURE_RESULT_U8 +typedef struct UniffiForeignFutureResultU8 { uint8_t returnValue; RustCallStatus callStatus; -} UniffiForeignFutureStructU8; +} UniffiForeignFutureResultU8; #endif #ifndef UNIFFI_FFIDEF_FOREIGN_FUTURE_COMPLETE_U8 #define UNIFFI_FFIDEF_FOREIGN_FUTURE_COMPLETE_U8 -typedef void (*UniffiForeignFutureCompleteU8)(uint64_t, UniffiForeignFutureStructU8 +typedef void (*UniffiForeignFutureCompleteU8)(uint64_t, UniffiForeignFutureResultU8 ); #endif -#ifndef UNIFFI_FFIDEF_FOREIGN_FUTURE_STRUCT_I8 -#define UNIFFI_FFIDEF_FOREIGN_FUTURE_STRUCT_I8 -typedef struct UniffiForeignFutureStructI8 { +#ifndef UNIFFI_FFIDEF_FOREIGN_FUTURE_RESULT_I8 +#define UNIFFI_FFIDEF_FOREIGN_FUTURE_RESULT_I8 +typedef struct UniffiForeignFutureResultI8 { int8_t returnValue; RustCallStatus callStatus; -} UniffiForeignFutureStructI8; +} UniffiForeignFutureResultI8; #endif #ifndef UNIFFI_FFIDEF_FOREIGN_FUTURE_COMPLETE_I8 #define UNIFFI_FFIDEF_FOREIGN_FUTURE_COMPLETE_I8 -typedef void (*UniffiForeignFutureCompleteI8)(uint64_t, UniffiForeignFutureStructI8 +typedef void (*UniffiForeignFutureCompleteI8)(uint64_t, UniffiForeignFutureResultI8 ); #endif -#ifndef UNIFFI_FFIDEF_FOREIGN_FUTURE_STRUCT_U16 -#define UNIFFI_FFIDEF_FOREIGN_FUTURE_STRUCT_U16 -typedef struct UniffiForeignFutureStructU16 { +#ifndef UNIFFI_FFIDEF_FOREIGN_FUTURE_RESULT_U16 +#define UNIFFI_FFIDEF_FOREIGN_FUTURE_RESULT_U16 +typedef struct UniffiForeignFutureResultU16 { uint16_t returnValue; RustCallStatus callStatus; -} UniffiForeignFutureStructU16; +} UniffiForeignFutureResultU16; #endif #ifndef UNIFFI_FFIDEF_FOREIGN_FUTURE_COMPLETE_U16 #define UNIFFI_FFIDEF_FOREIGN_FUTURE_COMPLETE_U16 -typedef void (*UniffiForeignFutureCompleteU16)(uint64_t, UniffiForeignFutureStructU16 +typedef void (*UniffiForeignFutureCompleteU16)(uint64_t, UniffiForeignFutureResultU16 ); #endif -#ifndef UNIFFI_FFIDEF_FOREIGN_FUTURE_STRUCT_I16 -#define UNIFFI_FFIDEF_FOREIGN_FUTURE_STRUCT_I16 -typedef struct UniffiForeignFutureStructI16 { +#ifndef UNIFFI_FFIDEF_FOREIGN_FUTURE_RESULT_I16 +#define UNIFFI_FFIDEF_FOREIGN_FUTURE_RESULT_I16 +typedef struct UniffiForeignFutureResultI16 { int16_t returnValue; RustCallStatus callStatus; -} UniffiForeignFutureStructI16; +} UniffiForeignFutureResultI16; #endif #ifndef UNIFFI_FFIDEF_FOREIGN_FUTURE_COMPLETE_I16 #define UNIFFI_FFIDEF_FOREIGN_FUTURE_COMPLETE_I16 -typedef void (*UniffiForeignFutureCompleteI16)(uint64_t, UniffiForeignFutureStructI16 +typedef void (*UniffiForeignFutureCompleteI16)(uint64_t, UniffiForeignFutureResultI16 ); #endif -#ifndef UNIFFI_FFIDEF_FOREIGN_FUTURE_STRUCT_U32 -#define UNIFFI_FFIDEF_FOREIGN_FUTURE_STRUCT_U32 -typedef struct UniffiForeignFutureStructU32 { +#ifndef UNIFFI_FFIDEF_FOREIGN_FUTURE_RESULT_U32 +#define UNIFFI_FFIDEF_FOREIGN_FUTURE_RESULT_U32 +typedef struct UniffiForeignFutureResultU32 { uint32_t returnValue; RustCallStatus callStatus; -} UniffiForeignFutureStructU32; +} UniffiForeignFutureResultU32; #endif #ifndef UNIFFI_FFIDEF_FOREIGN_FUTURE_COMPLETE_U32 #define UNIFFI_FFIDEF_FOREIGN_FUTURE_COMPLETE_U32 -typedef void (*UniffiForeignFutureCompleteU32)(uint64_t, UniffiForeignFutureStructU32 +typedef void (*UniffiForeignFutureCompleteU32)(uint64_t, UniffiForeignFutureResultU32 ); #endif -#ifndef UNIFFI_FFIDEF_FOREIGN_FUTURE_STRUCT_I32 -#define UNIFFI_FFIDEF_FOREIGN_FUTURE_STRUCT_I32 -typedef struct UniffiForeignFutureStructI32 { +#ifndef UNIFFI_FFIDEF_FOREIGN_FUTURE_RESULT_I32 +#define UNIFFI_FFIDEF_FOREIGN_FUTURE_RESULT_I32 +typedef struct UniffiForeignFutureResultI32 { int32_t returnValue; RustCallStatus callStatus; -} UniffiForeignFutureStructI32; +} UniffiForeignFutureResultI32; #endif #ifndef UNIFFI_FFIDEF_FOREIGN_FUTURE_COMPLETE_I32 #define UNIFFI_FFIDEF_FOREIGN_FUTURE_COMPLETE_I32 -typedef void (*UniffiForeignFutureCompleteI32)(uint64_t, UniffiForeignFutureStructI32 +typedef void (*UniffiForeignFutureCompleteI32)(uint64_t, UniffiForeignFutureResultI32 ); #endif -#ifndef UNIFFI_FFIDEF_FOREIGN_FUTURE_STRUCT_U64 -#define UNIFFI_FFIDEF_FOREIGN_FUTURE_STRUCT_U64 -typedef struct UniffiForeignFutureStructU64 { +#ifndef UNIFFI_FFIDEF_FOREIGN_FUTURE_RESULT_U64 +#define UNIFFI_FFIDEF_FOREIGN_FUTURE_RESULT_U64 +typedef struct UniffiForeignFutureResultU64 { uint64_t returnValue; RustCallStatus callStatus; -} UniffiForeignFutureStructU64; +} UniffiForeignFutureResultU64; #endif #ifndef UNIFFI_FFIDEF_FOREIGN_FUTURE_COMPLETE_U64 #define UNIFFI_FFIDEF_FOREIGN_FUTURE_COMPLETE_U64 -typedef void (*UniffiForeignFutureCompleteU64)(uint64_t, UniffiForeignFutureStructU64 +typedef void (*UniffiForeignFutureCompleteU64)(uint64_t, UniffiForeignFutureResultU64 ); #endif -#ifndef UNIFFI_FFIDEF_FOREIGN_FUTURE_STRUCT_I64 -#define UNIFFI_FFIDEF_FOREIGN_FUTURE_STRUCT_I64 -typedef struct UniffiForeignFutureStructI64 { +#ifndef UNIFFI_FFIDEF_FOREIGN_FUTURE_RESULT_I64 +#define UNIFFI_FFIDEF_FOREIGN_FUTURE_RESULT_I64 +typedef struct UniffiForeignFutureResultI64 { int64_t returnValue; RustCallStatus callStatus; -} UniffiForeignFutureStructI64; +} UniffiForeignFutureResultI64; #endif #ifndef UNIFFI_FFIDEF_FOREIGN_FUTURE_COMPLETE_I64 #define UNIFFI_FFIDEF_FOREIGN_FUTURE_COMPLETE_I64 -typedef void (*UniffiForeignFutureCompleteI64)(uint64_t, UniffiForeignFutureStructI64 +typedef void (*UniffiForeignFutureCompleteI64)(uint64_t, UniffiForeignFutureResultI64 ); #endif -#ifndef UNIFFI_FFIDEF_FOREIGN_FUTURE_STRUCT_F32 -#define UNIFFI_FFIDEF_FOREIGN_FUTURE_STRUCT_F32 -typedef struct UniffiForeignFutureStructF32 { +#ifndef UNIFFI_FFIDEF_FOREIGN_FUTURE_RESULT_F32 +#define UNIFFI_FFIDEF_FOREIGN_FUTURE_RESULT_F32 +typedef struct UniffiForeignFutureResultF32 { float returnValue; RustCallStatus callStatus; -} UniffiForeignFutureStructF32; +} UniffiForeignFutureResultF32; #endif #ifndef UNIFFI_FFIDEF_FOREIGN_FUTURE_COMPLETE_F32 #define UNIFFI_FFIDEF_FOREIGN_FUTURE_COMPLETE_F32 -typedef void (*UniffiForeignFutureCompleteF32)(uint64_t, UniffiForeignFutureStructF32 +typedef void (*UniffiForeignFutureCompleteF32)(uint64_t, UniffiForeignFutureResultF32 ); #endif -#ifndef UNIFFI_FFIDEF_FOREIGN_FUTURE_STRUCT_F64 -#define UNIFFI_FFIDEF_FOREIGN_FUTURE_STRUCT_F64 -typedef struct UniffiForeignFutureStructF64 { +#ifndef UNIFFI_FFIDEF_FOREIGN_FUTURE_RESULT_F64 +#define UNIFFI_FFIDEF_FOREIGN_FUTURE_RESULT_F64 +typedef struct UniffiForeignFutureResultF64 { double returnValue; RustCallStatus callStatus; -} UniffiForeignFutureStructF64; +} UniffiForeignFutureResultF64; #endif #ifndef UNIFFI_FFIDEF_FOREIGN_FUTURE_COMPLETE_F64 #define UNIFFI_FFIDEF_FOREIGN_FUTURE_COMPLETE_F64 -typedef void (*UniffiForeignFutureCompleteF64)(uint64_t, UniffiForeignFutureStructF64 - ); - -#endif -#ifndef UNIFFI_FFIDEF_FOREIGN_FUTURE_STRUCT_POINTER -#define UNIFFI_FFIDEF_FOREIGN_FUTURE_STRUCT_POINTER -typedef struct UniffiForeignFutureStructPointer { - void*_Nonnull returnValue; - RustCallStatus callStatus; -} UniffiForeignFutureStructPointer; - -#endif -#ifndef UNIFFI_FFIDEF_FOREIGN_FUTURE_COMPLETE_POINTER -#define UNIFFI_FFIDEF_FOREIGN_FUTURE_COMPLETE_POINTER -typedef void (*UniffiForeignFutureCompletePointer)(uint64_t, UniffiForeignFutureStructPointer +typedef void (*UniffiForeignFutureCompleteF64)(uint64_t, UniffiForeignFutureResultF64 ); #endif -#ifndef UNIFFI_FFIDEF_FOREIGN_FUTURE_STRUCT_RUST_BUFFER -#define UNIFFI_FFIDEF_FOREIGN_FUTURE_STRUCT_RUST_BUFFER -typedef struct UniffiForeignFutureStructRustBuffer { +#ifndef UNIFFI_FFIDEF_FOREIGN_FUTURE_RESULT_RUST_BUFFER +#define UNIFFI_FFIDEF_FOREIGN_FUTURE_RESULT_RUST_BUFFER +typedef struct UniffiForeignFutureResultRustBuffer { RustBuffer returnValue; RustCallStatus callStatus; -} UniffiForeignFutureStructRustBuffer; +} UniffiForeignFutureResultRustBuffer; #endif #ifndef UNIFFI_FFIDEF_FOREIGN_FUTURE_COMPLETE_RUST_BUFFER #define UNIFFI_FFIDEF_FOREIGN_FUTURE_COMPLETE_RUST_BUFFER -typedef void (*UniffiForeignFutureCompleteRustBuffer)(uint64_t, UniffiForeignFutureStructRustBuffer +typedef void (*UniffiForeignFutureCompleteRustBuffer)(uint64_t, UniffiForeignFutureResultRustBuffer ); #endif -#ifndef UNIFFI_FFIDEF_FOREIGN_FUTURE_STRUCT_VOID -#define UNIFFI_FFIDEF_FOREIGN_FUTURE_STRUCT_VOID -typedef struct UniffiForeignFutureStructVoid { +#ifndef UNIFFI_FFIDEF_FOREIGN_FUTURE_RESULT_VOID +#define UNIFFI_FFIDEF_FOREIGN_FUTURE_RESULT_VOID +typedef struct UniffiForeignFutureResultVoid { RustCallStatus callStatus; -} UniffiForeignFutureStructVoid; +} UniffiForeignFutureResultVoid; #endif #ifndef UNIFFI_FFIDEF_FOREIGN_FUTURE_COMPLETE_VOID #define UNIFFI_FFIDEF_FOREIGN_FUTURE_COMPLETE_VOID -typedef void (*UniffiForeignFutureCompleteVoid)(uint64_t, UniffiForeignFutureStructVoid +typedef void (*UniffiForeignFutureCompleteVoid)(uint64_t, UniffiForeignFutureResultVoid ); #endif #ifndef UNIFFI_FFIDEF_UNIFFI_DEVOLUTIONS_CRYPTO_UNIFFI_FN_CLONE_ARGON2PARAMETERS #define UNIFFI_FFIDEF_UNIFFI_DEVOLUTIONS_CRYPTO_UNIFFI_FN_CLONE_ARGON2PARAMETERS -void*_Nonnull uniffi_devolutions_crypto_uniffi_fn_clone_argon2parameters(void*_Nonnull ptr, RustCallStatus *_Nonnull out_status +uint64_t uniffi_devolutions_crypto_uniffi_fn_clone_argon2parameters(uint64_t handle, RustCallStatus *_Nonnull out_status ); #endif #ifndef UNIFFI_FFIDEF_UNIFFI_DEVOLUTIONS_CRYPTO_UNIFFI_FN_FREE_ARGON2PARAMETERS #define UNIFFI_FFIDEF_UNIFFI_DEVOLUTIONS_CRYPTO_UNIFFI_FN_FREE_ARGON2PARAMETERS -void uniffi_devolutions_crypto_uniffi_fn_free_argon2parameters(void*_Nonnull ptr, RustCallStatus *_Nonnull out_status +void uniffi_devolutions_crypto_uniffi_fn_free_argon2parameters(uint64_t handle, RustCallStatus *_Nonnull out_status ); #endif #ifndef UNIFFI_FFIDEF_UNIFFI_DEVOLUTIONS_CRYPTO_UNIFFI_FN_CONSTRUCTOR_ARGON2PARAMETERS_NEW_FROM_BYTES #define UNIFFI_FFIDEF_UNIFFI_DEVOLUTIONS_CRYPTO_UNIFFI_FN_CONSTRUCTOR_ARGON2PARAMETERS_NEW_FROM_BYTES -void*_Nonnull uniffi_devolutions_crypto_uniffi_fn_constructor_argon2parameters_new_from_bytes(RustBuffer data, RustCallStatus *_Nonnull out_status +uint64_t uniffi_devolutions_crypto_uniffi_fn_constructor_argon2parameters_new_from_bytes(RustBuffer data, RustCallStatus *_Nonnull out_status ); #endif #ifndef UNIFFI_FFIDEF_UNIFFI_DEVOLUTIONS_CRYPTO_UNIFFI_FN_METHOD_ARGON2PARAMETERS_GET_BYTES #define UNIFFI_FFIDEF_UNIFFI_DEVOLUTIONS_CRYPTO_UNIFFI_FN_METHOD_ARGON2PARAMETERS_GET_BYTES -RustBuffer uniffi_devolutions_crypto_uniffi_fn_method_argon2parameters_get_bytes(void*_Nonnull ptr, RustCallStatus *_Nonnull out_status +RustBuffer uniffi_devolutions_crypto_uniffi_fn_method_argon2parameters_get_bytes(uint64_t ptr, RustCallStatus *_Nonnull out_status ); #endif #ifndef UNIFFI_FFIDEF_UNIFFI_DEVOLUTIONS_CRYPTO_UNIFFI_FN_CLONE_ARGON2PARAMETERSBUILDER #define UNIFFI_FFIDEF_UNIFFI_DEVOLUTIONS_CRYPTO_UNIFFI_FN_CLONE_ARGON2PARAMETERSBUILDER -void*_Nonnull uniffi_devolutions_crypto_uniffi_fn_clone_argon2parametersbuilder(void*_Nonnull ptr, RustCallStatus *_Nonnull out_status +uint64_t uniffi_devolutions_crypto_uniffi_fn_clone_argon2parametersbuilder(uint64_t handle, RustCallStatus *_Nonnull out_status ); #endif #ifndef UNIFFI_FFIDEF_UNIFFI_DEVOLUTIONS_CRYPTO_UNIFFI_FN_FREE_ARGON2PARAMETERSBUILDER #define UNIFFI_FFIDEF_UNIFFI_DEVOLUTIONS_CRYPTO_UNIFFI_FN_FREE_ARGON2PARAMETERSBUILDER -void uniffi_devolutions_crypto_uniffi_fn_free_argon2parametersbuilder(void*_Nonnull ptr, RustCallStatus *_Nonnull out_status +void uniffi_devolutions_crypto_uniffi_fn_free_argon2parametersbuilder(uint64_t handle, RustCallStatus *_Nonnull out_status ); #endif #ifndef UNIFFI_FFIDEF_UNIFFI_DEVOLUTIONS_CRYPTO_UNIFFI_FN_CONSTRUCTOR_ARGON2PARAMETERSBUILDER_NEW #define UNIFFI_FFIDEF_UNIFFI_DEVOLUTIONS_CRYPTO_UNIFFI_FN_CONSTRUCTOR_ARGON2PARAMETERSBUILDER_NEW -void*_Nonnull uniffi_devolutions_crypto_uniffi_fn_constructor_argon2parametersbuilder_new(RustCallStatus *_Nonnull out_status +uint64_t uniffi_devolutions_crypto_uniffi_fn_constructor_argon2parametersbuilder_new(RustCallStatus *_Nonnull out_status ); #endif #ifndef UNIFFI_FFIDEF_UNIFFI_DEVOLUTIONS_CRYPTO_UNIFFI_FN_METHOD_ARGON2PARAMETERSBUILDER_ASSOCIATED_DATA #define UNIFFI_FFIDEF_UNIFFI_DEVOLUTIONS_CRYPTO_UNIFFI_FN_METHOD_ARGON2PARAMETERSBUILDER_ASSOCIATED_DATA -void*_Nonnull uniffi_devolutions_crypto_uniffi_fn_method_argon2parametersbuilder_associated_data(void*_Nonnull ptr, RustBuffer value, RustCallStatus *_Nonnull out_status +uint64_t uniffi_devolutions_crypto_uniffi_fn_method_argon2parametersbuilder_associated_data(uint64_t ptr, RustBuffer value, RustCallStatus *_Nonnull out_status ); #endif #ifndef UNIFFI_FFIDEF_UNIFFI_DEVOLUTIONS_CRYPTO_UNIFFI_FN_METHOD_ARGON2PARAMETERSBUILDER_BUILD #define UNIFFI_FFIDEF_UNIFFI_DEVOLUTIONS_CRYPTO_UNIFFI_FN_METHOD_ARGON2PARAMETERSBUILDER_BUILD -void*_Nonnull uniffi_devolutions_crypto_uniffi_fn_method_argon2parametersbuilder_build(void*_Nonnull ptr, RustCallStatus *_Nonnull out_status +uint64_t uniffi_devolutions_crypto_uniffi_fn_method_argon2parametersbuilder_build(uint64_t ptr, RustCallStatus *_Nonnull out_status ); #endif #ifndef UNIFFI_FFIDEF_UNIFFI_DEVOLUTIONS_CRYPTO_UNIFFI_FN_METHOD_ARGON2PARAMETERSBUILDER_DC_VERSION #define UNIFFI_FFIDEF_UNIFFI_DEVOLUTIONS_CRYPTO_UNIFFI_FN_METHOD_ARGON2PARAMETERSBUILDER_DC_VERSION -void*_Nonnull uniffi_devolutions_crypto_uniffi_fn_method_argon2parametersbuilder_dc_version(void*_Nonnull ptr, uint32_t value, RustCallStatus *_Nonnull out_status +uint64_t uniffi_devolutions_crypto_uniffi_fn_method_argon2parametersbuilder_dc_version(uint64_t ptr, uint32_t value, RustCallStatus *_Nonnull out_status ); #endif #ifndef UNIFFI_FFIDEF_UNIFFI_DEVOLUTIONS_CRYPTO_UNIFFI_FN_METHOD_ARGON2PARAMETERSBUILDER_ITERATIONS #define UNIFFI_FFIDEF_UNIFFI_DEVOLUTIONS_CRYPTO_UNIFFI_FN_METHOD_ARGON2PARAMETERSBUILDER_ITERATIONS -void*_Nonnull uniffi_devolutions_crypto_uniffi_fn_method_argon2parametersbuilder_iterations(void*_Nonnull ptr, uint32_t value, RustCallStatus *_Nonnull out_status +uint64_t uniffi_devolutions_crypto_uniffi_fn_method_argon2parametersbuilder_iterations(uint64_t ptr, uint32_t value, RustCallStatus *_Nonnull out_status ); #endif #ifndef UNIFFI_FFIDEF_UNIFFI_DEVOLUTIONS_CRYPTO_UNIFFI_FN_METHOD_ARGON2PARAMETERSBUILDER_LANES #define UNIFFI_FFIDEF_UNIFFI_DEVOLUTIONS_CRYPTO_UNIFFI_FN_METHOD_ARGON2PARAMETERSBUILDER_LANES -void*_Nonnull uniffi_devolutions_crypto_uniffi_fn_method_argon2parametersbuilder_lanes(void*_Nonnull ptr, uint32_t value, RustCallStatus *_Nonnull out_status +uint64_t uniffi_devolutions_crypto_uniffi_fn_method_argon2parametersbuilder_lanes(uint64_t ptr, uint32_t value, RustCallStatus *_Nonnull out_status ); #endif #ifndef UNIFFI_FFIDEF_UNIFFI_DEVOLUTIONS_CRYPTO_UNIFFI_FN_METHOD_ARGON2PARAMETERSBUILDER_LENGTH #define UNIFFI_FFIDEF_UNIFFI_DEVOLUTIONS_CRYPTO_UNIFFI_FN_METHOD_ARGON2PARAMETERSBUILDER_LENGTH -void*_Nonnull uniffi_devolutions_crypto_uniffi_fn_method_argon2parametersbuilder_length(void*_Nonnull ptr, uint32_t value, RustCallStatus *_Nonnull out_status +uint64_t uniffi_devolutions_crypto_uniffi_fn_method_argon2parametersbuilder_length(uint64_t ptr, uint32_t value, RustCallStatus *_Nonnull out_status ); #endif #ifndef UNIFFI_FFIDEF_UNIFFI_DEVOLUTIONS_CRYPTO_UNIFFI_FN_METHOD_ARGON2PARAMETERSBUILDER_MEMORY #define UNIFFI_FFIDEF_UNIFFI_DEVOLUTIONS_CRYPTO_UNIFFI_FN_METHOD_ARGON2PARAMETERSBUILDER_MEMORY -void*_Nonnull uniffi_devolutions_crypto_uniffi_fn_method_argon2parametersbuilder_memory(void*_Nonnull ptr, uint32_t value, RustCallStatus *_Nonnull out_status +uint64_t uniffi_devolutions_crypto_uniffi_fn_method_argon2parametersbuilder_memory(uint64_t ptr, uint32_t value, RustCallStatus *_Nonnull out_status ); #endif #ifndef UNIFFI_FFIDEF_UNIFFI_DEVOLUTIONS_CRYPTO_UNIFFI_FN_METHOD_ARGON2PARAMETERSBUILDER_SALT #define UNIFFI_FFIDEF_UNIFFI_DEVOLUTIONS_CRYPTO_UNIFFI_FN_METHOD_ARGON2PARAMETERSBUILDER_SALT -void*_Nonnull uniffi_devolutions_crypto_uniffi_fn_method_argon2parametersbuilder_salt(void*_Nonnull ptr, RustBuffer value, RustCallStatus *_Nonnull out_status +uint64_t uniffi_devolutions_crypto_uniffi_fn_method_argon2parametersbuilder_salt(uint64_t ptr, RustBuffer value, RustCallStatus *_Nonnull out_status ); #endif #ifndef UNIFFI_FFIDEF_UNIFFI_DEVOLUTIONS_CRYPTO_UNIFFI_FN_METHOD_ARGON2PARAMETERSBUILDER_SECRET_KEY #define UNIFFI_FFIDEF_UNIFFI_DEVOLUTIONS_CRYPTO_UNIFFI_FN_METHOD_ARGON2PARAMETERSBUILDER_SECRET_KEY -void*_Nonnull uniffi_devolutions_crypto_uniffi_fn_method_argon2parametersbuilder_secret_key(void*_Nonnull ptr, RustBuffer value, RustCallStatus *_Nonnull out_status +uint64_t uniffi_devolutions_crypto_uniffi_fn_method_argon2parametersbuilder_secret_key(uint64_t ptr, RustBuffer value, RustCallStatus *_Nonnull out_status ); #endif #ifndef UNIFFI_FFIDEF_UNIFFI_DEVOLUTIONS_CRYPTO_UNIFFI_FN_METHOD_ARGON2PARAMETERSBUILDER_VARIANT #define UNIFFI_FFIDEF_UNIFFI_DEVOLUTIONS_CRYPTO_UNIFFI_FN_METHOD_ARGON2PARAMETERSBUILDER_VARIANT -void*_Nonnull uniffi_devolutions_crypto_uniffi_fn_method_argon2parametersbuilder_variant(void*_Nonnull ptr, RustBuffer value, RustCallStatus *_Nonnull out_status +uint64_t uniffi_devolutions_crypto_uniffi_fn_method_argon2parametersbuilder_variant(uint64_t ptr, RustBuffer value, RustCallStatus *_Nonnull out_status ); #endif #ifndef UNIFFI_FFIDEF_UNIFFI_DEVOLUTIONS_CRYPTO_UNIFFI_FN_METHOD_ARGON2PARAMETERSBUILDER_VERSION #define UNIFFI_FFIDEF_UNIFFI_DEVOLUTIONS_CRYPTO_UNIFFI_FN_METHOD_ARGON2PARAMETERSBUILDER_VERSION -void*_Nonnull uniffi_devolutions_crypto_uniffi_fn_method_argon2parametersbuilder_version(void*_Nonnull ptr, RustBuffer value, RustCallStatus *_Nonnull out_status +uint64_t uniffi_devolutions_crypto_uniffi_fn_method_argon2parametersbuilder_version(uint64_t ptr, RustBuffer value, RustCallStatus *_Nonnull out_status ); #endif #ifndef UNIFFI_FFIDEF_UNIFFI_DEVOLUTIONS_CRYPTO_UNIFFI_FN_CLONE_SIGNINGKEYPAIR #define UNIFFI_FFIDEF_UNIFFI_DEVOLUTIONS_CRYPTO_UNIFFI_FN_CLONE_SIGNINGKEYPAIR -void*_Nonnull uniffi_devolutions_crypto_uniffi_fn_clone_signingkeypair(void*_Nonnull ptr, RustCallStatus *_Nonnull out_status +uint64_t uniffi_devolutions_crypto_uniffi_fn_clone_signingkeypair(uint64_t handle, RustCallStatus *_Nonnull out_status ); #endif #ifndef UNIFFI_FFIDEF_UNIFFI_DEVOLUTIONS_CRYPTO_UNIFFI_FN_FREE_SIGNINGKEYPAIR #define UNIFFI_FFIDEF_UNIFFI_DEVOLUTIONS_CRYPTO_UNIFFI_FN_FREE_SIGNINGKEYPAIR -void uniffi_devolutions_crypto_uniffi_fn_free_signingkeypair(void*_Nonnull ptr, RustCallStatus *_Nonnull out_status +void uniffi_devolutions_crypto_uniffi_fn_free_signingkeypair(uint64_t handle, RustCallStatus *_Nonnull out_status ); #endif #ifndef UNIFFI_FFIDEF_UNIFFI_DEVOLUTIONS_CRYPTO_UNIFFI_FN_CONSTRUCTOR_SIGNINGKEYPAIR_NEW_FROM_BYTES #define UNIFFI_FFIDEF_UNIFFI_DEVOLUTIONS_CRYPTO_UNIFFI_FN_CONSTRUCTOR_SIGNINGKEYPAIR_NEW_FROM_BYTES -void*_Nonnull uniffi_devolutions_crypto_uniffi_fn_constructor_signingkeypair_new_from_bytes(RustBuffer data, RustCallStatus *_Nonnull out_status +uint64_t uniffi_devolutions_crypto_uniffi_fn_constructor_signingkeypair_new_from_bytes(RustBuffer data, RustCallStatus *_Nonnull out_status ); #endif #ifndef UNIFFI_FFIDEF_UNIFFI_DEVOLUTIONS_CRYPTO_UNIFFI_FN_METHOD_SIGNINGKEYPAIR_GET_PRIVATE_KEY #define UNIFFI_FFIDEF_UNIFFI_DEVOLUTIONS_CRYPTO_UNIFFI_FN_METHOD_SIGNINGKEYPAIR_GET_PRIVATE_KEY -RustBuffer uniffi_devolutions_crypto_uniffi_fn_method_signingkeypair_get_private_key(void*_Nonnull ptr, RustCallStatus *_Nonnull out_status +RustBuffer uniffi_devolutions_crypto_uniffi_fn_method_signingkeypair_get_private_key(uint64_t ptr, RustCallStatus *_Nonnull out_status ); #endif #ifndef UNIFFI_FFIDEF_UNIFFI_DEVOLUTIONS_CRYPTO_UNIFFI_FN_METHOD_SIGNINGKEYPAIR_GET_PUBLIC_KEY #define UNIFFI_FFIDEF_UNIFFI_DEVOLUTIONS_CRYPTO_UNIFFI_FN_METHOD_SIGNINGKEYPAIR_GET_PUBLIC_KEY -RustBuffer uniffi_devolutions_crypto_uniffi_fn_method_signingkeypair_get_public_key(void*_Nonnull ptr, RustCallStatus *_Nonnull out_status +RustBuffer uniffi_devolutions_crypto_uniffi_fn_method_signingkeypair_get_public_key(uint64_t ptr, RustCallStatus *_Nonnull out_status ); #endif #ifndef UNIFFI_FFIDEF_UNIFFI_DEVOLUTIONS_CRYPTO_UNIFFI_FN_FUNC_BASE64_DECODE @@ -409,7 +401,7 @@ RustBuffer uniffi_devolutions_crypto_uniffi_fn_func_decrypt_with_aad(RustBuffer #endif #ifndef UNIFFI_FFIDEF_UNIFFI_DEVOLUTIONS_CRYPTO_UNIFFI_FN_FUNC_DERIVE_KEY_ARGON2 #define UNIFFI_FFIDEF_UNIFFI_DEVOLUTIONS_CRYPTO_UNIFFI_FN_FUNC_DERIVE_KEY_ARGON2 -RustBuffer uniffi_devolutions_crypto_uniffi_fn_func_derive_key_argon2(RustBuffer key, void*_Nonnull parameters, RustCallStatus *_Nonnull out_status +RustBuffer uniffi_devolutions_crypto_uniffi_fn_func_derive_key_argon2(RustBuffer key, uint64_t parameters, RustCallStatus *_Nonnull out_status ); #endif #ifndef UNIFFI_FFIDEF_UNIFFI_DEVOLUTIONS_CRYPTO_UNIFFI_FN_FUNC_DERIVE_KEY_PBKDF2 @@ -454,7 +446,7 @@ RustBuffer uniffi_devolutions_crypto_uniffi_fn_func_generate_shared_key(uint8_t #endif #ifndef UNIFFI_FFIDEF_UNIFFI_DEVOLUTIONS_CRYPTO_UNIFFI_FN_FUNC_GENERATE_SIGNING_KEYPAIR #define UNIFFI_FFIDEF_UNIFFI_DEVOLUTIONS_CRYPTO_UNIFFI_FN_FUNC_GENERATE_SIGNING_KEYPAIR -void*_Nonnull uniffi_devolutions_crypto_uniffi_fn_func_generate_signing_keypair(RustBuffer version, RustCallStatus *_Nonnull out_status +uint64_t uniffi_devolutions_crypto_uniffi_fn_func_generate_signing_keypair(RustBuffer version, RustCallStatus *_Nonnull out_status ); #endif #ifndef UNIFFI_FFIDEF_UNIFFI_DEVOLUTIONS_CRYPTO_UNIFFI_FN_FUNC_HASH_PASSWORD @@ -712,26 +704,6 @@ void ffi_devolutions_crypto_uniffi_rust_future_free_f64(uint64_t handle double ffi_devolutions_crypto_uniffi_rust_future_complete_f64(uint64_t handle, RustCallStatus *_Nonnull out_status ); #endif -#ifndef UNIFFI_FFIDEF_FFI_DEVOLUTIONS_CRYPTO_UNIFFI_RUST_FUTURE_POLL_POINTER -#define UNIFFI_FFIDEF_FFI_DEVOLUTIONS_CRYPTO_UNIFFI_RUST_FUTURE_POLL_POINTER -void ffi_devolutions_crypto_uniffi_rust_future_poll_pointer(uint64_t handle, UniffiRustFutureContinuationCallback _Nonnull callback, uint64_t callback_data -); -#endif -#ifndef UNIFFI_FFIDEF_FFI_DEVOLUTIONS_CRYPTO_UNIFFI_RUST_FUTURE_CANCEL_POINTER -#define UNIFFI_FFIDEF_FFI_DEVOLUTIONS_CRYPTO_UNIFFI_RUST_FUTURE_CANCEL_POINTER -void ffi_devolutions_crypto_uniffi_rust_future_cancel_pointer(uint64_t handle -); -#endif -#ifndef UNIFFI_FFIDEF_FFI_DEVOLUTIONS_CRYPTO_UNIFFI_RUST_FUTURE_FREE_POINTER -#define UNIFFI_FFIDEF_FFI_DEVOLUTIONS_CRYPTO_UNIFFI_RUST_FUTURE_FREE_POINTER -void ffi_devolutions_crypto_uniffi_rust_future_free_pointer(uint64_t handle -); -#endif -#ifndef UNIFFI_FFIDEF_FFI_DEVOLUTIONS_CRYPTO_UNIFFI_RUST_FUTURE_COMPLETE_POINTER -#define UNIFFI_FFIDEF_FFI_DEVOLUTIONS_CRYPTO_UNIFFI_RUST_FUTURE_COMPLETE_POINTER -void*_Nonnull ffi_devolutions_crypto_uniffi_rust_future_complete_pointer(uint64_t handle, RustCallStatus *_Nonnull out_status -); -#endif #ifndef UNIFFI_FFIDEF_FFI_DEVOLUTIONS_CRYPTO_UNIFFI_RUST_FUTURE_POLL_RUST_BUFFER #define UNIFFI_FFIDEF_FFI_DEVOLUTIONS_CRYPTO_UNIFFI_RUST_FUTURE_POLL_RUST_BUFFER void ffi_devolutions_crypto_uniffi_rust_future_poll_rust_buffer(uint64_t handle, UniffiRustFutureContinuationCallback _Nonnull callback, uint64_t callback_data From 98423f9d6565f93f6ee9ed2fbe3c2bddb68c2d67 Mon Sep 17 00:00:00 2001 From: Mathieu Morrissette Date: Thu, 8 Jan 2026 14:42:14 -0500 Subject: [PATCH 2/2] clippy --- .../src/argon2parameters.rs | 35 ++++++++++++------- .../src/ciphertext.rs | 6 +++- 2 files changed, 28 insertions(+), 13 deletions(-) diff --git a/uniffi/devolutions-crypto-uniffi/src/argon2parameters.rs b/uniffi/devolutions-crypto-uniffi/src/argon2parameters.rs index 04060d860..805e2bab2 100644 --- a/uniffi/devolutions-crypto-uniffi/src/argon2parameters.rs +++ b/uniffi/devolutions-crypto-uniffi/src/argon2parameters.rs @@ -97,18 +97,29 @@ impl Argon2ParametersBuilder { let salt = self.salt.lock().unwrap().clone(); // Build by chaining all fields together (typed-builder requires all fields to be set) - let inner = devolutions_crypto::Argon2Parameters::builder() - .length(length.unwrap_or(32)) - .lanes(lanes.unwrap_or(1)) - .memory(memory.unwrap_or(4096)) - .iterations(iterations.unwrap_or(3)) - .variant(variant.map(|v| v.into()).unwrap_or(argon2::Variant::Argon2id)) - .version(version.map(|v| v.into()).unwrap_or(argon2::Version::Version13)) - .dc_version(dc_version.unwrap_or(1)) - .associated_data(associated_data.unwrap_or_default()) - .secret_key(secret_key.unwrap_or_default()) - .salt(salt.unwrap_or_else(|| devolutions_crypto::argon2parameters_defaults::salt().unwrap())) - .build(); + let inner = + devolutions_crypto::Argon2Parameters::builder() + .length(length.unwrap_or(32)) + .lanes(lanes.unwrap_or(1)) + .memory(memory.unwrap_or(4096)) + .iterations(iterations.unwrap_or(3)) + .variant( + variant + .map(|v| v.into()) + .unwrap_or(argon2::Variant::Argon2id), + ) + .version( + version + .map(|v| v.into()) + .unwrap_or(argon2::Version::Version13), + ) + .dc_version(dc_version.unwrap_or(1)) + .associated_data(associated_data.unwrap_or_default()) + .secret_key(secret_key.unwrap_or_default()) + .salt(salt.unwrap_or_else(|| { + devolutions_crypto::argon2parameters_defaults::salt().unwrap() + })) + .build(); Arc::new(Argon2Parameters { inner }) } diff --git a/uniffi/devolutions-crypto-uniffi/src/ciphertext.rs b/uniffi/devolutions-crypto-uniffi/src/ciphertext.rs index 741ac304c..eb96487ff 100644 --- a/uniffi/devolutions-crypto-uniffi/src/ciphertext.rs +++ b/uniffi/devolutions-crypto-uniffi/src/ciphertext.rs @@ -31,7 +31,11 @@ fn decrypt_with_aad(data: &[u8], key: &[u8], aad: &[u8]) -> Result> { } #[uniffi::export(default(version = None))] -pub fn encrypt_asymmetric(data: &[u8], key: &[u8], version: Option) -> Result> { +pub fn encrypt_asymmetric( + data: &[u8], + key: &[u8], + version: Option, +) -> Result> { let version = version.unwrap_or(CiphertextVersion::Latest); let key = key.try_into()?; Ok(devolutions_crypto::ciphertext::encrypt_asymmetric(data, &key, version)?.into())