From 6a813e0ea9dcac69c99682a45f3db2c431505915 Mon Sep 17 00:00:00 2001 From: Mathieu Morrissette Date: Thu, 8 Jan 2026 13:59:28 -0500 Subject: [PATCH 01/11] 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 71da5935d..fbf8655d3 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]] @@ -1144,6 +1153,7 @@ dependencies = [ "base64 0.22.1", "blake2b_simd", "constant_time_eq 0.4.2", + "crossbeam-utils", ] [[package]] @@ -1299,6 +1309,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" @@ -1458,11 +1477,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]] @@ -1495,6 +1520,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" @@ -1529,16 +1560,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", @@ -1561,9 +1591,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", @@ -1585,22 +1615,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", @@ -1610,9 +1629,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", @@ -1623,9 +1642,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", @@ -1640,9 +1659,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", @@ -1652,9 +1671,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", @@ -1665,9 +1684,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 b383807ea..24ba62bed 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -242,3 +242,6 @@ pub const DEFAULT_PBKDF2_ITERATIONS: u32 = 600000; #[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 020fcf849..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 = 600000, 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 bedb00722..53fa32219 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 d89d439f0a3b6d531dba8fb0a84c2d296b168158 Mon Sep 17 00:00:00 2001 From: Mathieu Morrissette Date: Thu, 8 Jan 2026 14:42:14 -0500 Subject: [PATCH 02/11] clippy --- .../src/argon2parameters.rs | 35 +- .../src/ciphertext.rs | 6 +- .../DevolutionsCryptoSwift.swift | 1758 ----------------- .../devolutions_cryptoFFI.h | 1005 ---------- 4 files changed, 28 insertions(+), 2776 deletions(-) delete mode 100644 wrappers/swift/DevolutionsCryptoSwift/Sources/DevolutionsCryptoSwift/DevolutionsCryptoSwift.swift delete mode 100644 wrappers/swift/DevolutionsCryptoSwift/Sources/devolutions_cryptoFFI/devolutions_cryptoFFI.h 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()) diff --git a/wrappers/swift/DevolutionsCryptoSwift/Sources/DevolutionsCryptoSwift/DevolutionsCryptoSwift.swift b/wrappers/swift/DevolutionsCryptoSwift/Sources/DevolutionsCryptoSwift/DevolutionsCryptoSwift.swift deleted file mode 100644 index 0a94570d5..000000000 --- a/wrappers/swift/DevolutionsCryptoSwift/Sources/DevolutionsCryptoSwift/DevolutionsCryptoSwift.swift +++ /dev/null @@ -1,1758 +0,0 @@ -// This file was autogenerated by some hot garbage in the `uniffi` crate. -// Trust me, you don't want to mess with it! - -// swiftlint:disable all -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_crypto_uniffiFFI) -import devolutions_crypto_uniffiFFI -#endif - -fileprivate extension RustBuffer { - // Allocate a new buffer, copying the contents of a `UInt8` array. - init(bytes: [UInt8]) { - let rbuf = bytes.withUnsafeBufferPointer { ptr in - RustBuffer.from(ptr) - } - self.init(capacity: rbuf.capacity, len: rbuf.len, data: rbuf.data) - } - - static func empty() -> RustBuffer { - RustBuffer(capacity: 0, len:0, data: nil) - } - - static func from(_ ptr: UnsafeBufferPointer) -> RustBuffer { - try! rustCall { ffi_devolutions_crypto_uniffi_rustbuffer_from_bytes(ForeignBytes(bufferPointer: ptr), $0) } - } - - // Frees the buffer in place. - // The buffer must not be used after this is called. - func deallocate() { - try! rustCall { ffi_devolutions_crypto_uniffi_rustbuffer_free(self, $0) } - } -} - -fileprivate extension ForeignBytes { - init(bufferPointer: UnsafeBufferPointer) { - self.init(len: Int32(bufferPointer.count), data: bufferPointer.baseAddress) - } -} - -// For every type used in the interface, we provide helper methods for conveniently -// lifting and lowering that type from C-compatible data, and for reading and writing -// values of that type in a buffer. - -// Helper classes/extensions that don't change. -// Someday, this will be in a library of its own. - -fileprivate extension Data { - init(rustBuffer: RustBuffer) { - self.init( - bytesNoCopy: rustBuffer.data!, - count: Int(rustBuffer.len), - deallocator: .none - ) - } -} - -// Define reader functionality. Normally this would be defined in a class or -// struct, but we use standalone functions instead in order to make external -// types work. -// -// With external types, one swift source file needs to be able to call the read -// method on another source file's FfiConverter, but then what visibility -// should Reader have? -// - If Reader is fileprivate, then this means the read() must also -// be fileprivate, which doesn't work with external types. -// - If Reader is internal/public, we'll get compile errors since both source -// files will try define the same type. -// -// Instead, the read() method and these helper functions input a tuple of data - -fileprivate func createReader(data: Data) -> (data: Data, offset: Data.Index) { - (data: data, offset: 0) -} - -// Reads an integer at the current offset, in big-endian order, and advances -// the offset on success. Throws if reading the integer would move the -// offset past the end of the buffer. -fileprivate func readInt(_ reader: inout (data: Data, offset: Data.Index)) throws -> T { - let range = reader.offset...size - guard reader.data.count >= range.upperBound else { - throw UniffiInternalError.bufferOverflow - } - if T.self == UInt8.self { - let value = reader.data[reader.offset] - reader.offset += 1 - return value as! T - } - var value: T = 0 - let _ = withUnsafeMutableBytes(of: &value, { reader.data.copyBytes(to: $0, from: range)}) - reader.offset = range.upperBound - return value.bigEndian -} - -// Reads an arbitrary number of bytes, to be used to read -// raw bytes, this is useful when lifting strings -fileprivate func readBytes(_ reader: inout (data: Data, offset: Data.Index), count: Int) throws -> Array { - let range = reader.offset..<(reader.offset+count) - guard reader.data.count >= range.upperBound else { - throw UniffiInternalError.bufferOverflow - } - var value = [UInt8](repeating: 0, count: count) - value.withUnsafeMutableBufferPointer({ buffer in - reader.data.copyBytes(to: buffer, from: range) - }) - reader.offset = range.upperBound - return value -} - -// Reads a float at the current offset. -fileprivate func readFloat(_ reader: inout (data: Data, offset: Data.Index)) throws -> Float { - return Float(bitPattern: try readInt(&reader)) -} - -// Reads a float at the current offset. -fileprivate func readDouble(_ reader: inout (data: Data, offset: Data.Index)) throws -> Double { - return Double(bitPattern: try readInt(&reader)) -} - -// Indicates if the offset has reached the end of the buffer. -fileprivate func hasRemaining(_ reader: (data: Data, offset: Data.Index)) -> Bool { - return reader.offset < reader.data.count -} - -// Define writer functionality. Normally this would be defined in a class or -// struct, but we use standalone functions instead in order to make external -// types work. See the above discussion on Readers for details. - -fileprivate func createWriter() -> [UInt8] { - return [] -} - -fileprivate func writeBytes(_ writer: inout [UInt8], _ byteArr: S) where S: Sequence, S.Element == UInt8 { - writer.append(contentsOf: byteArr) -} - -// Writes an integer in big-endian order. -// -// Warning: make sure what you are trying to write -// is in the correct type! -fileprivate func writeInt(_ writer: inout [UInt8], _ value: T) { - var value = value.bigEndian - withUnsafeBytes(of: &value) { writer.append(contentsOf: $0) } -} - -fileprivate func writeFloat(_ writer: inout [UInt8], _ value: Float) { - writeInt(&writer, value.bitPattern) -} - -fileprivate func writeDouble(_ writer: inout [UInt8], _ value: Double) { - writeInt(&writer, value.bitPattern) -} - -// Protocol for types that transfer other types across the FFI. This is -// analogous to the Rust trait of the same name. -fileprivate protocol FfiConverter { - associatedtype FfiType - associatedtype SwiftType - - static func lift(_ value: FfiType) throws -> SwiftType - static func lower(_ value: SwiftType) -> FfiType - static func read(from buf: inout (data: Data, offset: Data.Index)) throws -> SwiftType - static func write(_ value: SwiftType, into buf: inout [UInt8]) -} - -// Types conforming to `Primitive` pass themselves directly over the FFI. -fileprivate protocol FfiConverterPrimitive: FfiConverter where FfiType == SwiftType { } - -extension FfiConverterPrimitive { -#if swift(>=5.8) - @_documentation(visibility: private) -#endif - public static func lift(_ value: FfiType) throws -> SwiftType { - return value - } - -#if swift(>=5.8) - @_documentation(visibility: private) -#endif - public static func lower(_ value: SwiftType) -> FfiType { - return value - } -} - -// Types conforming to `FfiConverterRustBuffer` lift and lower into a `RustBuffer`. -// Used for complex types where it's hard to write a custom lift/lower. -fileprivate protocol FfiConverterRustBuffer: FfiConverter where FfiType == RustBuffer {} - -extension FfiConverterRustBuffer { -#if swift(>=5.8) - @_documentation(visibility: private) -#endif - public static func lift(_ buf: RustBuffer) throws -> SwiftType { - var reader = createReader(data: Data(rustBuffer: buf)) - let value = try read(from: &reader) - if hasRemaining(reader) { - throw UniffiInternalError.incompleteData - } - buf.deallocate() - return value - } - -#if swift(>=5.8) - @_documentation(visibility: private) -#endif - public static func lower(_ value: SwiftType) -> RustBuffer { - var writer = createWriter() - write(value, into: &writer) - return RustBuffer(bytes: writer) - } -} -// An error type for FFI errors. These errors occur at the UniFFI level, not -// the library level. -fileprivate enum UniffiInternalError: LocalizedError { - case bufferOverflow - case incompleteData - case unexpectedOptionalTag - case unexpectedEnumCase - case unexpectedNullPointer - case unexpectedRustCallStatusCode - case unexpectedRustCallError - case unexpectedStaleHandle - case rustPanic(_ message: String) - - public var errorDescription: String? { - switch self { - case .bufferOverflow: return "Reading the requested value would read past the end of the buffer" - case .incompleteData: return "The buffer still has data after lifting its containing value" - case .unexpectedOptionalTag: return "Unexpected optional tag; should be 0 or 1" - case .unexpectedEnumCase: return "Raw enum value doesn't match any cases" - case .unexpectedNullPointer: return "Raw pointer value was null" - case .unexpectedRustCallStatusCode: return "Unexpected RustCallStatus code" - case .unexpectedRustCallError: return "CALL_ERROR but no errorClass specified" - case .unexpectedStaleHandle: return "The object in the handle map has been dropped already" - case let .rustPanic(message): return message - } - } -} - -fileprivate extension NSLock { - func withLock(f: () throws -> T) rethrows -> T { - self.lock() - defer { self.unlock() } - return try f() - } -} - -fileprivate let CALL_SUCCESS: Int8 = 0 -fileprivate let CALL_ERROR: Int8 = 1 -fileprivate let CALL_UNEXPECTED_ERROR: Int8 = 2 -fileprivate let CALL_CANCELLED: Int8 = 3 - -fileprivate extension RustCallStatus { - init() { - self.init( - code: CALL_SUCCESS, - errorBuf: RustBuffer.init( - capacity: 0, - len: 0, - data: nil - ) - ) - } -} - -private func rustCall(_ callback: (UnsafeMutablePointer) -> T) throws -> T { - let neverThrow: ((RustBuffer) throws -> Never)? = nil - return try makeRustCall(callback, errorHandler: neverThrow) -} - -private func rustCallWithError( - _ errorHandler: @escaping (RustBuffer) throws -> E, - _ callback: (UnsafeMutablePointer) -> T) throws -> T { - try makeRustCall(callback, errorHandler: errorHandler) -} - -private func makeRustCall( - _ callback: (UnsafeMutablePointer) -> T, - errorHandler: ((RustBuffer) throws -> E)? -) throws -> T { - uniffiEnsureDevolutionsCryptoUniffiInitialized() - var callStatus = RustCallStatus.init() - let returnedVal = callback(&callStatus) - try uniffiCheckCallStatus(callStatus: callStatus, errorHandler: errorHandler) - return returnedVal -} - -private func uniffiCheckCallStatus( - callStatus: RustCallStatus, - errorHandler: ((RustBuffer) throws -> E)? -) throws { - switch callStatus.code { - case CALL_SUCCESS: - return - - case CALL_ERROR: - if let errorHandler = errorHandler { - throw try errorHandler(callStatus.errorBuf) - } else { - callStatus.errorBuf.deallocate() - throw UniffiInternalError.unexpectedRustCallError - } - - case CALL_UNEXPECTED_ERROR: - // 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 callStatus.errorBuf.len > 0 { - throw UniffiInternalError.rustPanic(try FfiConverterString.lift(callStatus.errorBuf)) - } else { - callStatus.errorBuf.deallocate() - throw UniffiInternalError.rustPanic("Rust panic") - } - - case CALL_CANCELLED: - fatalError("Cancellation not supported yet") - - default: - throw UniffiInternalError.unexpectedRustCallStatusCode - } -} - -private func uniffiTraitInterfaceCall( - callStatus: UnsafeMutablePointer, - makeCall: () throws -> T, - writeReturn: (T) -> () -) { - do { - try writeReturn(makeCall()) - } catch let error { - callStatus.pointee.code = CALL_UNEXPECTED_ERROR - callStatus.pointee.errorBuf = FfiConverterString.lower(String(describing: error)) - } -} - -private func uniffiTraitInterfaceCallWithError( - callStatus: UnsafeMutablePointer, - makeCall: () throws -> T, - writeReturn: (T) -> (), - lowerError: (E) -> RustBuffer -) { - do { - try writeReturn(makeCall()) - } catch let error as E { - callStatus.pointee.code = CALL_ERROR - callStatus.pointee.errorBuf = lowerError(error) - } catch { - callStatus.pointee.code = CALL_UNEXPECTED_ERROR - 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 = UNIFFI_HANDLEMAP_INITIAL - - func insert(obj: T) -> UInt64 { - lock.withLock { - 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 { - throw UniffiInternalError.unexpectedStaleHandle - } - return obj - } - } - - 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 { - guard let obj = map.removeValue(forKey: handle) else { - throw UniffiInternalError.unexpectedStaleHandle - } - return obj - } - } - - var count: Int { - get { - map.count - } - } -} - - -// Public interface members begin here. - - -#if swift(>=5.8) -@_documentation(visibility: private) -#endif -fileprivate struct FfiConverterUInt8: FfiConverterPrimitive { - typealias FfiType = UInt8 - typealias SwiftType = UInt8 - - public static func read(from buf: inout (data: Data, offset: Data.Index)) throws -> UInt8 { - return try lift(readInt(&buf)) - } - - public static func write(_ value: UInt8, into buf: inout [UInt8]) { - writeInt(&buf, lower(value)) - } -} - -#if swift(>=5.8) -@_documentation(visibility: private) -#endif -fileprivate struct FfiConverterUInt32: FfiConverterPrimitive { - typealias FfiType = UInt32 - typealias SwiftType = UInt32 - - public static func read(from buf: inout (data: Data, offset: Data.Index)) throws -> UInt32 { - return try lift(readInt(&buf)) - } - - public static func write(_ value: SwiftType, into buf: inout [UInt8]) { - writeInt(&buf, lower(value)) - } -} - -#if swift(>=5.8) -@_documentation(visibility: private) -#endif -fileprivate struct FfiConverterBool : FfiConverter { - typealias FfiType = Int8 - typealias SwiftType = Bool - - public static func lift(_ value: Int8) throws -> Bool { - return value != 0 - } - - public static func lower(_ value: Bool) -> Int8 { - return value ? 1 : 0 - } - - public static func read(from buf: inout (data: Data, offset: Data.Index)) throws -> Bool { - return try lift(readInt(&buf)) - } - - public static func write(_ value: Bool, into buf: inout [UInt8]) { - writeInt(&buf, lower(value)) - } -} - -#if swift(>=5.8) -@_documentation(visibility: private) -#endif -fileprivate struct FfiConverterString: FfiConverter { - typealias SwiftType = String - typealias FfiType = RustBuffer - - public static func lift(_ value: RustBuffer) throws -> String { - defer { - value.deallocate() - } - if value.data == nil { - return String() - } - let bytes = UnsafeBufferPointer(start: value.data!, count: Int(value.len)) - return String(bytes: bytes, encoding: String.Encoding.utf8)! - } - - public static func lower(_ value: String) -> RustBuffer { - return value.utf8CString.withUnsafeBufferPointer { ptr in - // The swift string gives us int8_t, we want uint8_t. - ptr.withMemoryRebound(to: UInt8.self) { ptr in - // The swift string gives us a trailing null byte, we don't want it. - let buf = UnsafeBufferPointer(rebasing: ptr.prefix(upTo: ptr.count - 1)) - return RustBuffer.from(buf) - } - } - } - - public static func read(from buf: inout (data: Data, offset: Data.Index)) throws -> String { - let len: Int32 = try readInt(&buf) - return String(bytes: try readBytes(&buf, count: Int(len)), encoding: String.Encoding.utf8)! - } - - public static func write(_ value: String, into buf: inout [UInt8]) { - let len = Int32(value.utf8.count) - writeInt(&buf, len) - writeBytes(&buf, value.utf8) - } -} - -#if swift(>=5.8) -@_documentation(visibility: private) -#endif -fileprivate struct FfiConverterData: FfiConverterRustBuffer { - typealias SwiftType = Data - - public static func read(from buf: inout (data: Data, offset: Data.Index)) throws -> Data { - let len: Int32 = try readInt(&buf) - return Data(try readBytes(&buf, count: Int(len))) - } - - public static func write(_ value: Data, into buf: inout [UInt8]) { - let len = Int32(value.count) - writeInt(&buf, len) - writeBytes(&buf, value) - } -} - - - - -public protocol Argon2ParametersProtocol: AnyObject, Sendable { - - func getBytes() -> Data - -} -open class Argon2Parameters: Argon2ParametersProtocol, @unchecked Sendable { - fileprivate let handle: UInt64 - - /// Used to instantiate a [FFIObject] without an actual handle, for fakes in tests, mostly. -#if swift(>=5.8) - @_documentation(visibility: private) -#endif - public struct NoHandle { - public init() {} - } - - // TODO: We'd like this to be `private` but for Swifty reasons, - // we can't implement `FfiConverter` without making this `required` and we can't - // make it `required` without making it `public`. -#if swift(>=5.8) - @_documentation(visibility: private) -#endif - required public init(unsafeFromHandle handle: UInt64) { - self.handle = handle - } - - // This constructor can be used to instantiate a fake object. - // - 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 handle the FFI lower functions will crash. -#if swift(>=5.8) - @_documentation(visibility: private) -#endif - public init(noHandle: NoHandle) { - self.handle = 0 - } - -#if swift(>=5.8) - @_documentation(visibility: private) -#endif - 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 { - 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(FfiConverterTypeError_lift) { - uniffi_devolutions_crypto_uniffi_fn_constructor_argon2parameters_new_from_bytes( - FfiConverterData.lower(data),$0 - ) -}) -} - - - -open func getBytes() -> Data { - return try! FfiConverterData.lift(try! rustCall() { - uniffi_devolutions_crypto_uniffi_fn_method_argon2parameters_get_bytes( - self.uniffiCloneHandle(),$0 - ) -}) -} - - - -} - - -#if swift(>=5.8) -@_documentation(visibility: private) -#endif -public struct FfiConverterTypeArgon2Parameters: FfiConverter { - typealias FfiType = UInt64 - typealias SwiftType = Argon2Parameters - - public static func lift(_ handle: UInt64) throws -> Argon2Parameters { - return Argon2Parameters(unsafeFromHandle: handle) - } - - 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 handle: UInt64 = try readInt(&buf) - return try lift(handle) - } - - public static func write(_ value: Argon2Parameters, into buf: inout [UInt8]) { - writeInt(&buf, lower(value)) - } -} - - -#if swift(>=5.8) -@_documentation(visibility: private) -#endif -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) -> UInt64 { - return FfiConverterTypeArgon2Parameters.lower(value) -} - - - - - - -public protocol Argon2ParametersBuilderProtocol: AnyObject, Sendable { - - func associatedData(value: Data) -> Argon2ParametersBuilder - - func build() -> Argon2Parameters - - func dcVersion(value: UInt32) -> Argon2ParametersBuilder - - func iterations(value: UInt32) -> Argon2ParametersBuilder - - func lanes(value: UInt32) -> Argon2ParametersBuilder - - func length(value: UInt32) -> Argon2ParametersBuilder - - func memory(value: UInt32) -> Argon2ParametersBuilder - - func salt(value: Data) -> Argon2ParametersBuilder - - func secretKey(value: Data) -> Argon2ParametersBuilder - - func variant(value: Argon2Variant) -> Argon2ParametersBuilder - - func version(value: Argon2Version) -> Argon2ParametersBuilder - -} -open class Argon2ParametersBuilder: Argon2ParametersBuilderProtocol, @unchecked Sendable { - fileprivate let handle: UInt64 - - /// Used to instantiate a [FFIObject] without an actual handle, for fakes in tests, mostly. -#if swift(>=5.8) - @_documentation(visibility: private) -#endif - public struct NoHandle { - public init() {} - } - - // TODO: We'd like this to be `private` but for Swifty reasons, - // we can't implement `FfiConverter` without making this `required` and we can't - // make it `required` without making it `public`. -#if swift(>=5.8) - @_documentation(visibility: private) -#endif - required public init(unsafeFromHandle handle: UInt64) { - self.handle = handle - } - - // This constructor can be used to instantiate a fake object. - // - 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 handle the FFI lower functions will crash. -#if swift(>=5.8) - @_documentation(visibility: private) -#endif - public init(noHandle: NoHandle) { - self.handle = 0 - } - -#if swift(>=5.8) - @_documentation(visibility: private) -#endif - public func uniffiCloneHandle() -> UInt64 { - return try! rustCall { uniffi_devolutions_crypto_uniffi_fn_clone_argon2parametersbuilder(self.handle, $0) } - } -public convenience init() { - let handle = - try! rustCall() { - uniffi_devolutions_crypto_uniffi_fn_constructor_argon2parametersbuilder_new($0 - ) -} - self.init(unsafeFromHandle: handle) -} - - deinit { - try! rustCall { uniffi_devolutions_crypto_uniffi_fn_free_argon2parametersbuilder(handle, $0) } - } - - - - -open func associatedData(value: Data) -> Argon2ParametersBuilder { - return try! FfiConverterTypeArgon2ParametersBuilder_lift(try! rustCall() { - uniffi_devolutions_crypto_uniffi_fn_method_argon2parametersbuilder_associated_data( - self.uniffiCloneHandle(), - FfiConverterData.lower(value),$0 - ) -}) -} - -open func build() -> Argon2Parameters { - return try! FfiConverterTypeArgon2Parameters_lift(try! rustCall() { - 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.uniffiCloneHandle(), - FfiConverterUInt32.lower(value),$0 - ) -}) -} - -open func iterations(value: UInt32) -> Argon2ParametersBuilder { - return try! FfiConverterTypeArgon2ParametersBuilder_lift(try! rustCall() { - uniffi_devolutions_crypto_uniffi_fn_method_argon2parametersbuilder_iterations( - self.uniffiCloneHandle(), - FfiConverterUInt32.lower(value),$0 - ) -}) -} - -open func lanes(value: UInt32) -> Argon2ParametersBuilder { - return try! FfiConverterTypeArgon2ParametersBuilder_lift(try! rustCall() { - uniffi_devolutions_crypto_uniffi_fn_method_argon2parametersbuilder_lanes( - self.uniffiCloneHandle(), - FfiConverterUInt32.lower(value),$0 - ) -}) -} - -open func length(value: UInt32) -> Argon2ParametersBuilder { - return try! FfiConverterTypeArgon2ParametersBuilder_lift(try! rustCall() { - uniffi_devolutions_crypto_uniffi_fn_method_argon2parametersbuilder_length( - self.uniffiCloneHandle(), - FfiConverterUInt32.lower(value),$0 - ) -}) -} - -open func memory(value: UInt32) -> Argon2ParametersBuilder { - return try! FfiConverterTypeArgon2ParametersBuilder_lift(try! rustCall() { - uniffi_devolutions_crypto_uniffi_fn_method_argon2parametersbuilder_memory( - self.uniffiCloneHandle(), - FfiConverterUInt32.lower(value),$0 - ) -}) -} - -open func salt(value: Data) -> Argon2ParametersBuilder { - return try! FfiConverterTypeArgon2ParametersBuilder_lift(try! rustCall() { - uniffi_devolutions_crypto_uniffi_fn_method_argon2parametersbuilder_salt( - self.uniffiCloneHandle(), - FfiConverterData.lower(value),$0 - ) -}) -} - -open func secretKey(value: Data) -> Argon2ParametersBuilder { - return try! FfiConverterTypeArgon2ParametersBuilder_lift(try! rustCall() { - uniffi_devolutions_crypto_uniffi_fn_method_argon2parametersbuilder_secret_key( - self.uniffiCloneHandle(), - FfiConverterData.lower(value),$0 - ) -}) -} - -open func variant(value: Argon2Variant) -> Argon2ParametersBuilder { - return try! FfiConverterTypeArgon2ParametersBuilder_lift(try! rustCall() { - uniffi_devolutions_crypto_uniffi_fn_method_argon2parametersbuilder_variant( - self.uniffiCloneHandle(), - FfiConverterTypeArgon2Variant_lower(value),$0 - ) -}) -} - -open func version(value: Argon2Version) -> Argon2ParametersBuilder { - return try! FfiConverterTypeArgon2ParametersBuilder_lift(try! rustCall() { - uniffi_devolutions_crypto_uniffi_fn_method_argon2parametersbuilder_version( - self.uniffiCloneHandle(), - FfiConverterTypeArgon2Version_lower(value),$0 - ) -}) -} - - - -} - - -#if swift(>=5.8) -@_documentation(visibility: private) -#endif -public struct FfiConverterTypeArgon2ParametersBuilder: FfiConverter { - typealias FfiType = UInt64 - typealias SwiftType = Argon2ParametersBuilder - - public static func lift(_ handle: UInt64) throws -> Argon2ParametersBuilder { - return Argon2ParametersBuilder(unsafeFromHandle: handle) - } - - 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 handle: UInt64 = try readInt(&buf) - return try lift(handle) - } - - public static func write(_ value: Argon2ParametersBuilder, into buf: inout [UInt8]) { - writeInt(&buf, lower(value)) - } -} - - -#if swift(>=5.8) -@_documentation(visibility: private) -#endif -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) -> UInt64 { - return FfiConverterTypeArgon2ParametersBuilder.lower(value) -} - - - - - - -public protocol SigningKeyPairProtocol: AnyObject, Sendable { - - func getPrivateKey() -> Data - - func getPublicKey() -> Data - -} -open class SigningKeyPair: SigningKeyPairProtocol, @unchecked Sendable { - fileprivate let handle: UInt64 - - /// Used to instantiate a [FFIObject] without an actual handle, for fakes in tests, mostly. -#if swift(>=5.8) - @_documentation(visibility: private) -#endif - public struct NoHandle { - public init() {} - } - - // TODO: We'd like this to be `private` but for Swifty reasons, - // we can't implement `FfiConverter` without making this `required` and we can't - // make it `required` without making it `public`. -#if swift(>=5.8) - @_documentation(visibility: private) -#endif - required public init(unsafeFromHandle handle: UInt64) { - self.handle = handle - } - - // This constructor can be used to instantiate a fake object. - // - 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 handle the FFI lower functions will crash. -#if swift(>=5.8) - @_documentation(visibility: private) -#endif - public init(noHandle: NoHandle) { - self.handle = 0 - } - -#if swift(>=5.8) - @_documentation(visibility: private) -#endif - 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 { - 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(FfiConverterTypeError_lift) { - uniffi_devolutions_crypto_uniffi_fn_constructor_signingkeypair_new_from_bytes( - FfiConverterData.lower(data),$0 - ) -}) -} - - - -open func getPrivateKey() -> Data { - return try! FfiConverterData.lift(try! rustCall() { - 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.uniffiCloneHandle(),$0 - ) -}) -} - - - -} - - -#if swift(>=5.8) -@_documentation(visibility: private) -#endif -public struct FfiConverterTypeSigningKeyPair: FfiConverter { - typealias FfiType = UInt64 - typealias SwiftType = SigningKeyPair - - public static func lift(_ handle: UInt64) throws -> SigningKeyPair { - return SigningKeyPair(unsafeFromHandle: handle) - } - - 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 handle: UInt64 = try readInt(&buf) - return try lift(handle) - } - - public static func write(_ value: SigningKeyPair, into buf: inout [UInt8]) { - writeInt(&buf, lower(value)) - } -} - - -#if swift(>=5.8) -@_documentation(visibility: private) -#endif -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) -> UInt64 { - return FfiConverterTypeSigningKeyPair.lower(value) -} - - - - -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(privateKey: Data, publicKey: Data) { - self.privateKey = privateKey - self.publicKey = publicKey - } - - -} - -#if compiler(>=6) -extension KeyPair: Sendable {} -#endif - -#if swift(>=5.8) -@_documentation(visibility: private) -#endif -public struct FfiConverterTypeKeyPair: FfiConverterRustBuffer { - public static func read(from buf: inout (data: Data, offset: Data.Index)) throws -> KeyPair { - return - try KeyPair( - privateKey: FfiConverterData.read(from: &buf), - publicKey: FfiConverterData.read(from: &buf) - ) - } - - public static func write(_ value: KeyPair, into buf: inout [UInt8]) { - FfiConverterData.write(value.privateKey, into: &buf) - FfiConverterData.write(value.publicKey, into: &buf) - } -} - - -#if swift(>=5.8) -@_documentation(visibility: private) -#endif -public func FfiConverterTypeKeyPair_lift(_ buf: RustBuffer) throws -> KeyPair { - return try FfiConverterTypeKeyPair.lift(buf) -} - -#if swift(>=5.8) -@_documentation(visibility: private) -#endif -public func FfiConverterTypeKeyPair_lower(_ value: KeyPair) -> RustBuffer { - return FfiConverterTypeKeyPair.lower(value) -} - -// 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: Equatable, Hashable { - - case argon2d - case argon2i - case argon2id - - - -} - -#if compiler(>=6) -extension Argon2Variant: Sendable {} -#endif - -#if swift(>=5.8) -@_documentation(visibility: private) -#endif -public struct FfiConverterTypeArgon2Variant: FfiConverterRustBuffer { - typealias SwiftType = Argon2Variant - - public static func read(from buf: inout (data: Data, offset: Data.Index)) throws -> Argon2Variant { - let variant: Int32 = try readInt(&buf) - switch variant { - - case 1: return .argon2d - - case 2: return .argon2i - - case 3: return .argon2id - - default: throw UniffiInternalError.unexpectedEnumCase - } - } - - public static func write(_ value: Argon2Variant, into buf: inout [UInt8]) { - switch value { - - - case .argon2d: - writeInt(&buf, Int32(1)) - - - case .argon2i: - writeInt(&buf, Int32(2)) - - - case .argon2id: - writeInt(&buf, Int32(3)) - - } - } -} - - -#if swift(>=5.8) -@_documentation(visibility: private) -#endif -public func FfiConverterTypeArgon2Variant_lift(_ buf: RustBuffer) throws -> Argon2Variant { - return try FfiConverterTypeArgon2Variant.lift(buf) -} - -#if swift(>=5.8) -@_documentation(visibility: private) -#endif -public func FfiConverterTypeArgon2Variant_lower(_ value: Argon2Variant) -> RustBuffer { - return FfiConverterTypeArgon2Variant.lower(value) -} - - -// 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: Equatable, Hashable { - - case version10 - case version13 - - - -} - -#if compiler(>=6) -extension Argon2Version: Sendable {} -#endif - -#if swift(>=5.8) -@_documentation(visibility: private) -#endif -public struct FfiConverterTypeArgon2Version: FfiConverterRustBuffer { - typealias SwiftType = Argon2Version - - public static func read(from buf: inout (data: Data, offset: Data.Index)) throws -> Argon2Version { - let variant: Int32 = try readInt(&buf) - switch variant { - - case 1: return .version10 - - case 2: return .version13 - - default: throw UniffiInternalError.unexpectedEnumCase - } - } - - public static func write(_ value: Argon2Version, into buf: inout [UInt8]) { - switch value { - - - case .version10: - writeInt(&buf, Int32(1)) - - - case .version13: - writeInt(&buf, Int32(2)) - - } - } -} - - -#if swift(>=5.8) -@_documentation(visibility: private) -#endif -public func FfiConverterTypeArgon2Version_lift(_ buf: RustBuffer) throws -> Argon2Version { - return try FfiConverterTypeArgon2Version.lift(buf) -} - -#if swift(>=5.8) -@_documentation(visibility: private) -#endif -public func FfiConverterTypeArgon2Version_lower(_ value: Argon2Version) -> RustBuffer { - return FfiConverterTypeArgon2Version.lower(value) -} - - -#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 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 -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 -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) - } - - 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 swift(>=5.8) -@_documentation(visibility: private) -#endif -fileprivate struct FfiConverterOptionTypePasswordHashVersion: FfiConverterRustBuffer { - typealias SwiftType = PasswordHashVersion? - - 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 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 -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 -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 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 -fileprivate struct FfiConverterOptionTypeSigningKeyVersion: FfiConverterRustBuffer { - typealias SwiftType = SigningKeyVersion? - - 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 FfiConverterTypeSigningKeyVersion.read(from: &buf) - default: throw UniffiInternalError.unexpectedOptionalTag - } - } -} - -#if swift(>=5.8) -@_documentation(visibility: private) -#endif -fileprivate struct FfiConverterSequenceData: FfiConverterRustBuffer { - typealias SwiftType = [Data] - - public static func write(_ value: [Data], into buf: inout [UInt8]) { - let len = Int32(value.count) - writeInt(&buf, len) - for item in value { - FfiConverterData.write(item, into: &buf) - } - } - - public static func read(from buf: inout (data: Data, offset: Data.Index)) throws -> [Data] { - let len: Int32 = try readInt(&buf) - var seq = [Data]() - seq.reserveCapacity(Int(len)) - for _ in 0 ..< len { - seq.append(try FfiConverterData.read(from: &buf)) - } - return seq - } -} -public func base64Decode(data: String)throws -> Data { - 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(FfiConverterTypeError_lift) { - uniffi_devolutions_crypto_uniffi_fn_func_base64_decode_url( - FfiConverterString.lower(data),$0 - ) -}) -} -public func base64Encode(data: Data) -> String { - return try! FfiConverterString.lift(try! rustCall() { - uniffi_devolutions_crypto_uniffi_fn_func_base64_encode( - FfiConverterData.lower(data),$0 - ) -}) -} -public func base64EncodeUrl(data: Data) -> String { - return try! FfiConverterString.lift(try! rustCall() { - uniffi_devolutions_crypto_uniffi_fn_func_base64_encode_url( - FfiConverterData.lower(data),$0 - ) -}) -} -public func decrypt(data: Data, key: Data)throws -> Data { - return try FfiConverterData.lift(try rustCallWithError(FfiConverterTypeError_lift) { - uniffi_devolutions_crypto_uniffi_fn_func_decrypt( - FfiConverterData.lower(data), - FfiConverterData.lower(key),$0 - ) -}) -} -public func decryptAsymmetric(data: Data, key: Data)throws -> Data { - return try FfiConverterData.lift(try rustCallWithError(FfiConverterTypeError_lift) { - uniffi_devolutions_crypto_uniffi_fn_func_decrypt_asymmetric( - FfiConverterData.lower(data), - FfiConverterData.lower(key),$0 - ) -}) -} -public func decryptAsymmetricWithAad(data: Data, key: Data, aad: Data)throws -> Data { - return try FfiConverterData.lift(try rustCallWithError(FfiConverterTypeError_lift) { - uniffi_devolutions_crypto_uniffi_fn_func_decrypt_asymmetric_with_aad( - FfiConverterData.lower(data), - FfiConverterData.lower(key), - FfiConverterData.lower(aad),$0 - ) -}) -} -public func decryptWithAad(data: Data, key: Data, aad: Data)throws -> Data { - return try FfiConverterData.lift(try rustCallWithError(FfiConverterTypeError_lift) { - uniffi_devolutions_crypto_uniffi_fn_func_decrypt_with_aad( - FfiConverterData.lower(data), - FfiConverterData.lower(key), - FfiConverterData.lower(aad),$0 - ) -}) -} -public func deriveKeyArgon2(key: Data, parameters: Argon2Parameters)throws -> Data { - return try FfiConverterData.lift(try rustCallWithError(FfiConverterTypeError_lift) { - uniffi_devolutions_crypto_uniffi_fn_func_derive_key_argon2( - FfiConverterData.lower(key), - FfiConverterTypeArgon2Parameters_lower(parameters),$0 - ) -}) -} -public func deriveKeyPbkdf2(key: Data, salt: Data?, iterations: UInt32 = UInt32(10000), length: UInt32 = UInt32(32)) -> Data { - return try! FfiConverterData.lift(try! rustCall() { - uniffi_devolutions_crypto_uniffi_fn_func_derive_key_pbkdf2( - FfiConverterData.lower(key), - FfiConverterOptionData.lower(salt), - FfiConverterUInt32.lower(iterations), - FfiConverterUInt32.lower(length),$0 - ) -}) -} -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), - FfiConverterOptionTypeCiphertextVersion.lower(version),$0 - ) -}) -} -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), - FfiConverterOptionTypeCiphertextVersion.lower(version),$0 - ) -}) -} -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), - FfiConverterOptionTypeCiphertextVersion.lower(version),$0 - ) -}) -} -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), - FfiConverterOptionTypeCiphertextVersion.lower(version),$0 - ) -}) -} -public func generateKey(length: UInt32 = UInt32(32))throws -> Data { - 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? = nil) -> KeyPair { - return try! FfiConverterTypeKeyPair_lift(try! rustCall() { - uniffi_devolutions_crypto_uniffi_fn_func_generate_keypair( - FfiConverterOptionTypeKeyVersion.lower(version),$0 - ) -}) -} -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), - FfiConverterOptionTypeSecretSharingVersion.lower(version),$0 - ) -}) -} -public func generateSigningKeypair(version: SigningKeyVersion? = nil) -> SigningKeyPair { - return try! FfiConverterTypeSigningKeyPair_lift(try! rustCall() { - uniffi_devolutions_crypto_uniffi_fn_func_generate_signing_keypair( - FfiConverterOptionTypeSigningKeyVersion.lower(version),$0 - ) -}) -} -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), - FfiConverterOptionTypePasswordHashVersion.lower(version),$0 - ) -}) -} -public func joinShares(shares: [Data])throws -> Data { - 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(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? = nil)throws -> Data { - return try FfiConverterData.lift(try rustCallWithError(FfiConverterTypeError_lift) { - uniffi_devolutions_crypto_uniffi_fn_func_sign( - FfiConverterData.lower(data), - FfiConverterData.lower(keypair), - FfiConverterOptionTypeSignatureVersion.lower(version),$0 - ) -}) -} -public func validateHeader(data: Data, dataType: DataType) -> Bool { - return try! FfiConverterBool.lift(try! rustCall() { - uniffi_devolutions_crypto_uniffi_fn_func_validate_header( - FfiConverterData.lower(data), - FfiConverterTypeDataType_lower(dataType),$0 - ) -}) -} -public func verifyPassword(password: Data, hash: Data)throws -> Bool { - return try FfiConverterBool.lift(try rustCallWithError(FfiConverterTypeError_lift) { - uniffi_devolutions_crypto_uniffi_fn_func_verify_password( - FfiConverterData.lower(password), - FfiConverterData.lower(hash),$0 - ) -}) -} -public func verifySignature(data: Data, publicKey: Data, signature: Data)throws -> Bool { - return try FfiConverterBool.lift(try rustCallWithError(FfiConverterTypeError_lift) { - uniffi_devolutions_crypto_uniffi_fn_func_verify_signature( - FfiConverterData.lower(data), - FfiConverterData.lower(publicKey), - FfiConverterData.lower(signature),$0 - ) -}) -} - -private enum InitializationResult { - case ok - case contractVersionMismatch - case apiChecksumMismatch -} -// Use a global variable to perform the versioning checks. Swift ensures that -// the code inside is only computed once. -private let initializationResult: InitializationResult = { - // Get the bindings contract version from our ComponentInterface - 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() != 15059) { - return InitializationResult.apiChecksumMismatch - } - if (uniffi_devolutions_crypto_uniffi_checksum_func_base64_decode_url() != 15429) { - return InitializationResult.apiChecksumMismatch - } - if (uniffi_devolutions_crypto_uniffi_checksum_func_base64_encode() != 61134) { - return InitializationResult.apiChecksumMismatch - } - if (uniffi_devolutions_crypto_uniffi_checksum_func_base64_encode_url() != 31513) { - return InitializationResult.apiChecksumMismatch - } - if (uniffi_devolutions_crypto_uniffi_checksum_func_decrypt() != 39921) { - return InitializationResult.apiChecksumMismatch - } - if (uniffi_devolutions_crypto_uniffi_checksum_func_decrypt_asymmetric() != 6283) { - return InitializationResult.apiChecksumMismatch - } - 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() != 43775) { - return InitializationResult.apiChecksumMismatch - } - if (uniffi_devolutions_crypto_uniffi_checksum_func_derive_key_argon2() != 27403) { - return InitializationResult.apiChecksumMismatch - } - if (uniffi_devolutions_crypto_uniffi_checksum_func_derive_key_pbkdf2() != 32212) { - return InitializationResult.apiChecksumMismatch - } - if (uniffi_devolutions_crypto_uniffi_checksum_func_encrypt() != 28651) { - return InitializationResult.apiChecksumMismatch - } - if (uniffi_devolutions_crypto_uniffi_checksum_func_encrypt_asymmetric() != 17008) { - return InitializationResult.apiChecksumMismatch - } - 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() != 29699) { - return InitializationResult.apiChecksumMismatch - } - if (uniffi_devolutions_crypto_uniffi_checksum_func_generate_key() != 29427) { - return InitializationResult.apiChecksumMismatch - } - if (uniffi_devolutions_crypto_uniffi_checksum_func_generate_keypair() != 38891) { - return InitializationResult.apiChecksumMismatch - } - if (uniffi_devolutions_crypto_uniffi_checksum_func_generate_shared_key() != 57051) { - return InitializationResult.apiChecksumMismatch - } - if (uniffi_devolutions_crypto_uniffi_checksum_func_generate_signing_keypair() != 51146) { - return InitializationResult.apiChecksumMismatch - } - if (uniffi_devolutions_crypto_uniffi_checksum_func_hash_password() != 12769) { - return InitializationResult.apiChecksumMismatch - } - if (uniffi_devolutions_crypto_uniffi_checksum_func_join_shares() != 65529) { - return InitializationResult.apiChecksumMismatch - } - if (uniffi_devolutions_crypto_uniffi_checksum_func_mix_key_exchange() != 21197) { - return InitializationResult.apiChecksumMismatch - } - if (uniffi_devolutions_crypto_uniffi_checksum_func_sign() != 42756) { - return InitializationResult.apiChecksumMismatch - } - if (uniffi_devolutions_crypto_uniffi_checksum_func_validate_header() != 53669) { - return InitializationResult.apiChecksumMismatch - } - if (uniffi_devolutions_crypto_uniffi_checksum_func_verify_password() != 7704) { - return InitializationResult.apiChecksumMismatch - } - if (uniffi_devolutions_crypto_uniffi_checksum_func_verify_signature() != 51084) { - return InitializationResult.apiChecksumMismatch - } - if (uniffi_devolutions_crypto_uniffi_checksum_method_argon2parameters_get_bytes() != 26758) { - return InitializationResult.apiChecksumMismatch - } - if (uniffi_devolutions_crypto_uniffi_checksum_method_argon2parametersbuilder_associated_data() != 27028) { - return InitializationResult.apiChecksumMismatch - } - if (uniffi_devolutions_crypto_uniffi_checksum_method_argon2parametersbuilder_build() != 8751) { - return InitializationResult.apiChecksumMismatch - } - if (uniffi_devolutions_crypto_uniffi_checksum_method_argon2parametersbuilder_dc_version() != 35235) { - return InitializationResult.apiChecksumMismatch - } - if (uniffi_devolutions_crypto_uniffi_checksum_method_argon2parametersbuilder_iterations() != 15990) { - return InitializationResult.apiChecksumMismatch - } - if (uniffi_devolutions_crypto_uniffi_checksum_method_argon2parametersbuilder_lanes() != 57040) { - return InitializationResult.apiChecksumMismatch - } - if (uniffi_devolutions_crypto_uniffi_checksum_method_argon2parametersbuilder_length() != 65258) { - return InitializationResult.apiChecksumMismatch - } - if (uniffi_devolutions_crypto_uniffi_checksum_method_argon2parametersbuilder_memory() != 41617) { - return InitializationResult.apiChecksumMismatch - } - if (uniffi_devolutions_crypto_uniffi_checksum_method_argon2parametersbuilder_salt() != 5080) { - return InitializationResult.apiChecksumMismatch - } - if (uniffi_devolutions_crypto_uniffi_checksum_method_argon2parametersbuilder_secret_key() != 14932) { - return InitializationResult.apiChecksumMismatch - } - if (uniffi_devolutions_crypto_uniffi_checksum_method_argon2parametersbuilder_variant() != 48907) { - return InitializationResult.apiChecksumMismatch - } - if (uniffi_devolutions_crypto_uniffi_checksum_method_argon2parametersbuilder_version() != 31568) { - return InitializationResult.apiChecksumMismatch - } - 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() != 50462) { - return InitializationResult.apiChecksumMismatch - } - if (uniffi_devolutions_crypto_uniffi_checksum_constructor_argon2parameters_new_from_bytes() != 58986) { - return InitializationResult.apiChecksumMismatch - } - if (uniffi_devolutions_crypto_uniffi_checksum_constructor_argon2parametersbuilder_new() != 40769) { - return InitializationResult.apiChecksumMismatch - } - if (uniffi_devolutions_crypto_uniffi_checksum_constructor_signingkeypair_new_from_bytes() != 59560) { - return InitializationResult.apiChecksumMismatch - } - - uniffiEnsureDevolutionsCryptoInitialized() - return InitializationResult.ok -}() - -// Make the ensure init function public so that other modules which have external type references to -// our types can call it. -public func uniffiEnsureDevolutionsCryptoUniffiInitialized() { - switch initializationResult { - case .ok: - break - case .contractVersionMismatch: - fatalError("UniFFI contract version mismatch: try cleaning and rebuilding your project") - case .apiChecksumMismatch: - fatalError("UniFFI API checksum mismatch: try cleaning and rebuilding your project") - } -} - -// swiftlint:enable all \ No newline at end of file diff --git a/wrappers/swift/DevolutionsCryptoSwift/Sources/devolutions_cryptoFFI/devolutions_cryptoFFI.h b/wrappers/swift/DevolutionsCryptoSwift/Sources/devolutions_cryptoFFI/devolutions_cryptoFFI.h deleted file mode 100644 index fb08a2ef3..000000000 --- a/wrappers/swift/DevolutionsCryptoSwift/Sources/devolutions_cryptoFFI/devolutions_cryptoFFI.h +++ /dev/null @@ -1,1005 +0,0 @@ -// This file was autogenerated by some hot garbage in the `uniffi` crate. -// Trust me, you don't want to mess with it! - -#pragma once - -#include -#include -#include - -// The following structs are used to implement the lowest level -// of the FFI, and thus useful to multiple uniffied crates. -// We ensure they are declared exactly once, with a header guard, UNIFFI_SHARED_H. -#ifdef UNIFFI_SHARED_H - // We also try to prevent mixing versions of shared uniffi header structs. - // If you add anything to the #else block, you must increment the version suffix in UNIFFI_SHARED_HEADER_V4 - #ifndef UNIFFI_SHARED_HEADER_V4 - #error Combining helper code from multiple versions of uniffi is not supported - #endif // ndef UNIFFI_SHARED_HEADER_V4 -#else -#define UNIFFI_SHARED_H -#define UNIFFI_SHARED_HEADER_V4 -// ⚠️ Attention: If you change this #else block (ending in `#endif // def UNIFFI_SHARED_H`) you *must* ⚠️ -// ⚠️ increment the version suffix in all instances of UNIFFI_SHARED_HEADER_V4 in this file. ⚠️ - -typedef struct RustBuffer -{ - uint64_t capacity; - uint64_t len; - uint8_t *_Nullable data; -} RustBuffer; - -typedef struct ForeignBytes -{ - int32_t len; - const uint8_t *_Nullable data; -} ForeignBytes; - -// Error definitions -typedef struct RustCallStatus { - int8_t code; - RustBuffer errorBuf; -} RustCallStatus; - -// ⚠️ Attention: If you change this #else block (ending in `#endif // def UNIFFI_SHARED_H`) you *must* ⚠️ -// ⚠️ increment the version suffix in all instances of UNIFFI_SHARED_HEADER_V4 in this file. ⚠️ -#endif // def UNIFFI_SHARED_H -#ifndef UNIFFI_FFIDEF_RUST_FUTURE_CONTINUATION_CALLBACK -#define UNIFFI_FFIDEF_RUST_FUTURE_CONTINUATION_CALLBACK -typedef void (*UniffiRustFutureContinuationCallback)(uint64_t, int8_t - ); - -#endif -#ifndef UNIFFI_FFIDEF_FOREIGN_FUTURE_DROPPED_CALLBACK -#define UNIFFI_FFIDEF_FOREIGN_FUTURE_DROPPED_CALLBACK -typedef void (*UniffiForeignFutureDroppedCallback)(uint64_t - ); - -#endif -#ifndef UNIFFI_FFIDEF_CALLBACK_INTERFACE_FREE -#define UNIFFI_FFIDEF_CALLBACK_INTERFACE_FREE -typedef void (*UniffiCallbackInterfaceFree)(uint64_t - ); - -#endif -#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; - UniffiForeignFutureDroppedCallback _Nonnull free; -} UniffiForeignFutureDroppedCallbackStruct; - -#endif -#ifndef UNIFFI_FFIDEF_FOREIGN_FUTURE_RESULT_U8 -#define UNIFFI_FFIDEF_FOREIGN_FUTURE_RESULT_U8 -typedef struct UniffiForeignFutureResultU8 { - uint8_t returnValue; - RustCallStatus callStatus; -} UniffiForeignFutureResultU8; - -#endif -#ifndef UNIFFI_FFIDEF_FOREIGN_FUTURE_COMPLETE_U8 -#define UNIFFI_FFIDEF_FOREIGN_FUTURE_COMPLETE_U8 -typedef void (*UniffiForeignFutureCompleteU8)(uint64_t, UniffiForeignFutureResultU8 - ); - -#endif -#ifndef UNIFFI_FFIDEF_FOREIGN_FUTURE_RESULT_I8 -#define UNIFFI_FFIDEF_FOREIGN_FUTURE_RESULT_I8 -typedef struct UniffiForeignFutureResultI8 { - int8_t returnValue; - RustCallStatus callStatus; -} UniffiForeignFutureResultI8; - -#endif -#ifndef UNIFFI_FFIDEF_FOREIGN_FUTURE_COMPLETE_I8 -#define UNIFFI_FFIDEF_FOREIGN_FUTURE_COMPLETE_I8 -typedef void (*UniffiForeignFutureCompleteI8)(uint64_t, UniffiForeignFutureResultI8 - ); - -#endif -#ifndef UNIFFI_FFIDEF_FOREIGN_FUTURE_RESULT_U16 -#define UNIFFI_FFIDEF_FOREIGN_FUTURE_RESULT_U16 -typedef struct UniffiForeignFutureResultU16 { - uint16_t returnValue; - RustCallStatus callStatus; -} UniffiForeignFutureResultU16; - -#endif -#ifndef UNIFFI_FFIDEF_FOREIGN_FUTURE_COMPLETE_U16 -#define UNIFFI_FFIDEF_FOREIGN_FUTURE_COMPLETE_U16 -typedef void (*UniffiForeignFutureCompleteU16)(uint64_t, UniffiForeignFutureResultU16 - ); - -#endif -#ifndef UNIFFI_FFIDEF_FOREIGN_FUTURE_RESULT_I16 -#define UNIFFI_FFIDEF_FOREIGN_FUTURE_RESULT_I16 -typedef struct UniffiForeignFutureResultI16 { - int16_t returnValue; - RustCallStatus callStatus; -} UniffiForeignFutureResultI16; - -#endif -#ifndef UNIFFI_FFIDEF_FOREIGN_FUTURE_COMPLETE_I16 -#define UNIFFI_FFIDEF_FOREIGN_FUTURE_COMPLETE_I16 -typedef void (*UniffiForeignFutureCompleteI16)(uint64_t, UniffiForeignFutureResultI16 - ); - -#endif -#ifndef UNIFFI_FFIDEF_FOREIGN_FUTURE_RESULT_U32 -#define UNIFFI_FFIDEF_FOREIGN_FUTURE_RESULT_U32 -typedef struct UniffiForeignFutureResultU32 { - uint32_t returnValue; - RustCallStatus callStatus; -} UniffiForeignFutureResultU32; - -#endif -#ifndef UNIFFI_FFIDEF_FOREIGN_FUTURE_COMPLETE_U32 -#define UNIFFI_FFIDEF_FOREIGN_FUTURE_COMPLETE_U32 -typedef void (*UniffiForeignFutureCompleteU32)(uint64_t, UniffiForeignFutureResultU32 - ); - -#endif -#ifndef UNIFFI_FFIDEF_FOREIGN_FUTURE_RESULT_I32 -#define UNIFFI_FFIDEF_FOREIGN_FUTURE_RESULT_I32 -typedef struct UniffiForeignFutureResultI32 { - int32_t returnValue; - RustCallStatus callStatus; -} UniffiForeignFutureResultI32; - -#endif -#ifndef UNIFFI_FFIDEF_FOREIGN_FUTURE_COMPLETE_I32 -#define UNIFFI_FFIDEF_FOREIGN_FUTURE_COMPLETE_I32 -typedef void (*UniffiForeignFutureCompleteI32)(uint64_t, UniffiForeignFutureResultI32 - ); - -#endif -#ifndef UNIFFI_FFIDEF_FOREIGN_FUTURE_RESULT_U64 -#define UNIFFI_FFIDEF_FOREIGN_FUTURE_RESULT_U64 -typedef struct UniffiForeignFutureResultU64 { - uint64_t returnValue; - RustCallStatus callStatus; -} UniffiForeignFutureResultU64; - -#endif -#ifndef UNIFFI_FFIDEF_FOREIGN_FUTURE_COMPLETE_U64 -#define UNIFFI_FFIDEF_FOREIGN_FUTURE_COMPLETE_U64 -typedef void (*UniffiForeignFutureCompleteU64)(uint64_t, UniffiForeignFutureResultU64 - ); - -#endif -#ifndef UNIFFI_FFIDEF_FOREIGN_FUTURE_RESULT_I64 -#define UNIFFI_FFIDEF_FOREIGN_FUTURE_RESULT_I64 -typedef struct UniffiForeignFutureResultI64 { - int64_t returnValue; - RustCallStatus callStatus; -} UniffiForeignFutureResultI64; - -#endif -#ifndef UNIFFI_FFIDEF_FOREIGN_FUTURE_COMPLETE_I64 -#define UNIFFI_FFIDEF_FOREIGN_FUTURE_COMPLETE_I64 -typedef void (*UniffiForeignFutureCompleteI64)(uint64_t, UniffiForeignFutureResultI64 - ); - -#endif -#ifndef UNIFFI_FFIDEF_FOREIGN_FUTURE_RESULT_F32 -#define UNIFFI_FFIDEF_FOREIGN_FUTURE_RESULT_F32 -typedef struct UniffiForeignFutureResultF32 { - float returnValue; - RustCallStatus callStatus; -} UniffiForeignFutureResultF32; - -#endif -#ifndef UNIFFI_FFIDEF_FOREIGN_FUTURE_COMPLETE_F32 -#define UNIFFI_FFIDEF_FOREIGN_FUTURE_COMPLETE_F32 -typedef void (*UniffiForeignFutureCompleteF32)(uint64_t, UniffiForeignFutureResultF32 - ); - -#endif -#ifndef UNIFFI_FFIDEF_FOREIGN_FUTURE_RESULT_F64 -#define UNIFFI_FFIDEF_FOREIGN_FUTURE_RESULT_F64 -typedef struct UniffiForeignFutureResultF64 { - double returnValue; - RustCallStatus callStatus; -} UniffiForeignFutureResultF64; - -#endif -#ifndef UNIFFI_FFIDEF_FOREIGN_FUTURE_COMPLETE_F64 -#define UNIFFI_FFIDEF_FOREIGN_FUTURE_COMPLETE_F64 -typedef void (*UniffiForeignFutureCompleteF64)(uint64_t, UniffiForeignFutureResultF64 - ); - -#endif -#ifndef UNIFFI_FFIDEF_FOREIGN_FUTURE_RESULT_RUST_BUFFER -#define UNIFFI_FFIDEF_FOREIGN_FUTURE_RESULT_RUST_BUFFER -typedef struct UniffiForeignFutureResultRustBuffer { - RustBuffer returnValue; - RustCallStatus callStatus; -} UniffiForeignFutureResultRustBuffer; - -#endif -#ifndef UNIFFI_FFIDEF_FOREIGN_FUTURE_COMPLETE_RUST_BUFFER -#define UNIFFI_FFIDEF_FOREIGN_FUTURE_COMPLETE_RUST_BUFFER -typedef void (*UniffiForeignFutureCompleteRustBuffer)(uint64_t, UniffiForeignFutureResultRustBuffer - ); - -#endif -#ifndef UNIFFI_FFIDEF_FOREIGN_FUTURE_RESULT_VOID -#define UNIFFI_FFIDEF_FOREIGN_FUTURE_RESULT_VOID -typedef struct UniffiForeignFutureResultVoid { - RustCallStatus callStatus; -} UniffiForeignFutureResultVoid; - -#endif -#ifndef UNIFFI_FFIDEF_FOREIGN_FUTURE_COMPLETE_VOID -#define UNIFFI_FFIDEF_FOREIGN_FUTURE_COMPLETE_VOID -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 -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(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 -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(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 -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(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 -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 -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 -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 -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 -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 -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 -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 -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 -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 -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 -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 -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 -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(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 -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(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(uint64_t ptr, RustCallStatus *_Nonnull out_status -); -#endif -#ifndef UNIFFI_FFIDEF_UNIFFI_DEVOLUTIONS_CRYPTO_UNIFFI_FN_FUNC_BASE64_DECODE -#define UNIFFI_FFIDEF_UNIFFI_DEVOLUTIONS_CRYPTO_UNIFFI_FN_FUNC_BASE64_DECODE -RustBuffer uniffi_devolutions_crypto_uniffi_fn_func_base64_decode(RustBuffer data, RustCallStatus *_Nonnull out_status -); -#endif -#ifndef UNIFFI_FFIDEF_UNIFFI_DEVOLUTIONS_CRYPTO_UNIFFI_FN_FUNC_BASE64_DECODE_URL -#define UNIFFI_FFIDEF_UNIFFI_DEVOLUTIONS_CRYPTO_UNIFFI_FN_FUNC_BASE64_DECODE_URL -RustBuffer uniffi_devolutions_crypto_uniffi_fn_func_base64_decode_url(RustBuffer data, RustCallStatus *_Nonnull out_status -); -#endif -#ifndef UNIFFI_FFIDEF_UNIFFI_DEVOLUTIONS_CRYPTO_UNIFFI_FN_FUNC_BASE64_ENCODE -#define UNIFFI_FFIDEF_UNIFFI_DEVOLUTIONS_CRYPTO_UNIFFI_FN_FUNC_BASE64_ENCODE -RustBuffer uniffi_devolutions_crypto_uniffi_fn_func_base64_encode(RustBuffer data, RustCallStatus *_Nonnull out_status -); -#endif -#ifndef UNIFFI_FFIDEF_UNIFFI_DEVOLUTIONS_CRYPTO_UNIFFI_FN_FUNC_BASE64_ENCODE_URL -#define UNIFFI_FFIDEF_UNIFFI_DEVOLUTIONS_CRYPTO_UNIFFI_FN_FUNC_BASE64_ENCODE_URL -RustBuffer uniffi_devolutions_crypto_uniffi_fn_func_base64_encode_url(RustBuffer data, RustCallStatus *_Nonnull out_status -); -#endif -#ifndef UNIFFI_FFIDEF_UNIFFI_DEVOLUTIONS_CRYPTO_UNIFFI_FN_FUNC_DECRYPT -#define UNIFFI_FFIDEF_UNIFFI_DEVOLUTIONS_CRYPTO_UNIFFI_FN_FUNC_DECRYPT -RustBuffer uniffi_devolutions_crypto_uniffi_fn_func_decrypt(RustBuffer data, RustBuffer key, RustCallStatus *_Nonnull out_status -); -#endif -#ifndef UNIFFI_FFIDEF_UNIFFI_DEVOLUTIONS_CRYPTO_UNIFFI_FN_FUNC_DECRYPT_ASYMMETRIC -#define UNIFFI_FFIDEF_UNIFFI_DEVOLUTIONS_CRYPTO_UNIFFI_FN_FUNC_DECRYPT_ASYMMETRIC -RustBuffer uniffi_devolutions_crypto_uniffi_fn_func_decrypt_asymmetric(RustBuffer data, RustBuffer key, RustCallStatus *_Nonnull out_status -); -#endif -#ifndef UNIFFI_FFIDEF_UNIFFI_DEVOLUTIONS_CRYPTO_UNIFFI_FN_FUNC_DECRYPT_ASYMMETRIC_WITH_AAD -#define UNIFFI_FFIDEF_UNIFFI_DEVOLUTIONS_CRYPTO_UNIFFI_FN_FUNC_DECRYPT_ASYMMETRIC_WITH_AAD -RustBuffer uniffi_devolutions_crypto_uniffi_fn_func_decrypt_asymmetric_with_aad(RustBuffer data, RustBuffer key, RustBuffer aad, RustCallStatus *_Nonnull out_status -); -#endif -#ifndef UNIFFI_FFIDEF_UNIFFI_DEVOLUTIONS_CRYPTO_UNIFFI_FN_FUNC_DECRYPT_WITH_AAD -#define UNIFFI_FFIDEF_UNIFFI_DEVOLUTIONS_CRYPTO_UNIFFI_FN_FUNC_DECRYPT_WITH_AAD -RustBuffer uniffi_devolutions_crypto_uniffi_fn_func_decrypt_with_aad(RustBuffer data, RustBuffer key, RustBuffer aad, RustCallStatus *_Nonnull out_status -); -#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, uint64_t parameters, RustCallStatus *_Nonnull out_status -); -#endif -#ifndef UNIFFI_FFIDEF_UNIFFI_DEVOLUTIONS_CRYPTO_UNIFFI_FN_FUNC_DERIVE_KEY_PBKDF2 -#define UNIFFI_FFIDEF_UNIFFI_DEVOLUTIONS_CRYPTO_UNIFFI_FN_FUNC_DERIVE_KEY_PBKDF2 -RustBuffer uniffi_devolutions_crypto_uniffi_fn_func_derive_key_pbkdf2(RustBuffer key, RustBuffer salt, uint32_t iterations, uint32_t length, RustCallStatus *_Nonnull out_status -); -#endif -#ifndef UNIFFI_FFIDEF_UNIFFI_DEVOLUTIONS_CRYPTO_UNIFFI_FN_FUNC_ENCRYPT -#define UNIFFI_FFIDEF_UNIFFI_DEVOLUTIONS_CRYPTO_UNIFFI_FN_FUNC_ENCRYPT -RustBuffer uniffi_devolutions_crypto_uniffi_fn_func_encrypt(RustBuffer data, RustBuffer key, RustBuffer version, RustCallStatus *_Nonnull out_status -); -#endif -#ifndef UNIFFI_FFIDEF_UNIFFI_DEVOLUTIONS_CRYPTO_UNIFFI_FN_FUNC_ENCRYPT_ASYMMETRIC -#define UNIFFI_FFIDEF_UNIFFI_DEVOLUTIONS_CRYPTO_UNIFFI_FN_FUNC_ENCRYPT_ASYMMETRIC -RustBuffer uniffi_devolutions_crypto_uniffi_fn_func_encrypt_asymmetric(RustBuffer data, RustBuffer key, RustBuffer version, RustCallStatus *_Nonnull out_status -); -#endif -#ifndef UNIFFI_FFIDEF_UNIFFI_DEVOLUTIONS_CRYPTO_UNIFFI_FN_FUNC_ENCRYPT_ASYMMETRIC_WITH_AAD -#define UNIFFI_FFIDEF_UNIFFI_DEVOLUTIONS_CRYPTO_UNIFFI_FN_FUNC_ENCRYPT_ASYMMETRIC_WITH_AAD -RustBuffer uniffi_devolutions_crypto_uniffi_fn_func_encrypt_asymmetric_with_aad(RustBuffer data, RustBuffer key, RustBuffer aad, RustBuffer version, RustCallStatus *_Nonnull out_status -); -#endif -#ifndef UNIFFI_FFIDEF_UNIFFI_DEVOLUTIONS_CRYPTO_UNIFFI_FN_FUNC_ENCRYPT_WITH_AAD -#define UNIFFI_FFIDEF_UNIFFI_DEVOLUTIONS_CRYPTO_UNIFFI_FN_FUNC_ENCRYPT_WITH_AAD -RustBuffer uniffi_devolutions_crypto_uniffi_fn_func_encrypt_with_aad(RustBuffer data, RustBuffer key, RustBuffer aad, RustBuffer version, RustCallStatus *_Nonnull out_status -); -#endif -#ifndef UNIFFI_FFIDEF_UNIFFI_DEVOLUTIONS_CRYPTO_UNIFFI_FN_FUNC_GENERATE_KEY -#define UNIFFI_FFIDEF_UNIFFI_DEVOLUTIONS_CRYPTO_UNIFFI_FN_FUNC_GENERATE_KEY -RustBuffer uniffi_devolutions_crypto_uniffi_fn_func_generate_key(uint32_t length, RustCallStatus *_Nonnull out_status -); -#endif -#ifndef UNIFFI_FFIDEF_UNIFFI_DEVOLUTIONS_CRYPTO_UNIFFI_FN_FUNC_GENERATE_KEYPAIR -#define UNIFFI_FFIDEF_UNIFFI_DEVOLUTIONS_CRYPTO_UNIFFI_FN_FUNC_GENERATE_KEYPAIR -RustBuffer uniffi_devolutions_crypto_uniffi_fn_func_generate_keypair(RustBuffer version, RustCallStatus *_Nonnull out_status -); -#endif -#ifndef UNIFFI_FFIDEF_UNIFFI_DEVOLUTIONS_CRYPTO_UNIFFI_FN_FUNC_GENERATE_SHARED_KEY -#define UNIFFI_FFIDEF_UNIFFI_DEVOLUTIONS_CRYPTO_UNIFFI_FN_FUNC_GENERATE_SHARED_KEY -RustBuffer uniffi_devolutions_crypto_uniffi_fn_func_generate_shared_key(uint8_t n_shares, uint8_t threshold, uint32_t length, RustBuffer version, RustCallStatus *_Nonnull out_status -); -#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 -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 -#define UNIFFI_FFIDEF_UNIFFI_DEVOLUTIONS_CRYPTO_UNIFFI_FN_FUNC_HASH_PASSWORD -RustBuffer uniffi_devolutions_crypto_uniffi_fn_func_hash_password(RustBuffer password, uint32_t iterations, RustBuffer version, RustCallStatus *_Nonnull out_status -); -#endif -#ifndef UNIFFI_FFIDEF_UNIFFI_DEVOLUTIONS_CRYPTO_UNIFFI_FN_FUNC_JOIN_SHARES -#define UNIFFI_FFIDEF_UNIFFI_DEVOLUTIONS_CRYPTO_UNIFFI_FN_FUNC_JOIN_SHARES -RustBuffer uniffi_devolutions_crypto_uniffi_fn_func_join_shares(RustBuffer shares, RustCallStatus *_Nonnull out_status -); -#endif -#ifndef UNIFFI_FFIDEF_UNIFFI_DEVOLUTIONS_CRYPTO_UNIFFI_FN_FUNC_MIX_KEY_EXCHANGE -#define UNIFFI_FFIDEF_UNIFFI_DEVOLUTIONS_CRYPTO_UNIFFI_FN_FUNC_MIX_KEY_EXCHANGE -RustBuffer uniffi_devolutions_crypto_uniffi_fn_func_mix_key_exchange(RustBuffer private_key, RustBuffer public_key, RustCallStatus *_Nonnull out_status -); -#endif -#ifndef UNIFFI_FFIDEF_UNIFFI_DEVOLUTIONS_CRYPTO_UNIFFI_FN_FUNC_SIGN -#define UNIFFI_FFIDEF_UNIFFI_DEVOLUTIONS_CRYPTO_UNIFFI_FN_FUNC_SIGN -RustBuffer uniffi_devolutions_crypto_uniffi_fn_func_sign(RustBuffer data, RustBuffer keypair, RustBuffer version, RustCallStatus *_Nonnull out_status -); -#endif -#ifndef UNIFFI_FFIDEF_UNIFFI_DEVOLUTIONS_CRYPTO_UNIFFI_FN_FUNC_VALIDATE_HEADER -#define UNIFFI_FFIDEF_UNIFFI_DEVOLUTIONS_CRYPTO_UNIFFI_FN_FUNC_VALIDATE_HEADER -int8_t uniffi_devolutions_crypto_uniffi_fn_func_validate_header(RustBuffer data, RustBuffer data_type, RustCallStatus *_Nonnull out_status -); -#endif -#ifndef UNIFFI_FFIDEF_UNIFFI_DEVOLUTIONS_CRYPTO_UNIFFI_FN_FUNC_VERIFY_PASSWORD -#define UNIFFI_FFIDEF_UNIFFI_DEVOLUTIONS_CRYPTO_UNIFFI_FN_FUNC_VERIFY_PASSWORD -int8_t uniffi_devolutions_crypto_uniffi_fn_func_verify_password(RustBuffer password, RustBuffer hash, RustCallStatus *_Nonnull out_status -); -#endif -#ifndef UNIFFI_FFIDEF_UNIFFI_DEVOLUTIONS_CRYPTO_UNIFFI_FN_FUNC_VERIFY_SIGNATURE -#define UNIFFI_FFIDEF_UNIFFI_DEVOLUTIONS_CRYPTO_UNIFFI_FN_FUNC_VERIFY_SIGNATURE -int8_t uniffi_devolutions_crypto_uniffi_fn_func_verify_signature(RustBuffer data, RustBuffer public_key, RustBuffer signature, RustCallStatus *_Nonnull out_status -); -#endif -#ifndef UNIFFI_FFIDEF_FFI_DEVOLUTIONS_CRYPTO_UNIFFI_RUSTBUFFER_ALLOC -#define UNIFFI_FFIDEF_FFI_DEVOLUTIONS_CRYPTO_UNIFFI_RUSTBUFFER_ALLOC -RustBuffer ffi_devolutions_crypto_uniffi_rustbuffer_alloc(uint64_t size, RustCallStatus *_Nonnull out_status -); -#endif -#ifndef UNIFFI_FFIDEF_FFI_DEVOLUTIONS_CRYPTO_UNIFFI_RUSTBUFFER_FROM_BYTES -#define UNIFFI_FFIDEF_FFI_DEVOLUTIONS_CRYPTO_UNIFFI_RUSTBUFFER_FROM_BYTES -RustBuffer ffi_devolutions_crypto_uniffi_rustbuffer_from_bytes(ForeignBytes bytes, RustCallStatus *_Nonnull out_status -); -#endif -#ifndef UNIFFI_FFIDEF_FFI_DEVOLUTIONS_CRYPTO_UNIFFI_RUSTBUFFER_FREE -#define UNIFFI_FFIDEF_FFI_DEVOLUTIONS_CRYPTO_UNIFFI_RUSTBUFFER_FREE -void ffi_devolutions_crypto_uniffi_rustbuffer_free(RustBuffer buf, RustCallStatus *_Nonnull out_status -); -#endif -#ifndef UNIFFI_FFIDEF_FFI_DEVOLUTIONS_CRYPTO_UNIFFI_RUSTBUFFER_RESERVE -#define UNIFFI_FFIDEF_FFI_DEVOLUTIONS_CRYPTO_UNIFFI_RUSTBUFFER_RESERVE -RustBuffer ffi_devolutions_crypto_uniffi_rustbuffer_reserve(RustBuffer buf, uint64_t additional, RustCallStatus *_Nonnull out_status -); -#endif -#ifndef UNIFFI_FFIDEF_FFI_DEVOLUTIONS_CRYPTO_UNIFFI_RUST_FUTURE_POLL_U8 -#define UNIFFI_FFIDEF_FFI_DEVOLUTIONS_CRYPTO_UNIFFI_RUST_FUTURE_POLL_U8 -void ffi_devolutions_crypto_uniffi_rust_future_poll_u8(uint64_t handle, UniffiRustFutureContinuationCallback _Nonnull callback, uint64_t callback_data -); -#endif -#ifndef UNIFFI_FFIDEF_FFI_DEVOLUTIONS_CRYPTO_UNIFFI_RUST_FUTURE_CANCEL_U8 -#define UNIFFI_FFIDEF_FFI_DEVOLUTIONS_CRYPTO_UNIFFI_RUST_FUTURE_CANCEL_U8 -void ffi_devolutions_crypto_uniffi_rust_future_cancel_u8(uint64_t handle -); -#endif -#ifndef UNIFFI_FFIDEF_FFI_DEVOLUTIONS_CRYPTO_UNIFFI_RUST_FUTURE_FREE_U8 -#define UNIFFI_FFIDEF_FFI_DEVOLUTIONS_CRYPTO_UNIFFI_RUST_FUTURE_FREE_U8 -void ffi_devolutions_crypto_uniffi_rust_future_free_u8(uint64_t handle -); -#endif -#ifndef UNIFFI_FFIDEF_FFI_DEVOLUTIONS_CRYPTO_UNIFFI_RUST_FUTURE_COMPLETE_U8 -#define UNIFFI_FFIDEF_FFI_DEVOLUTIONS_CRYPTO_UNIFFI_RUST_FUTURE_COMPLETE_U8 -uint8_t ffi_devolutions_crypto_uniffi_rust_future_complete_u8(uint64_t handle, RustCallStatus *_Nonnull out_status -); -#endif -#ifndef UNIFFI_FFIDEF_FFI_DEVOLUTIONS_CRYPTO_UNIFFI_RUST_FUTURE_POLL_I8 -#define UNIFFI_FFIDEF_FFI_DEVOLUTIONS_CRYPTO_UNIFFI_RUST_FUTURE_POLL_I8 -void ffi_devolutions_crypto_uniffi_rust_future_poll_i8(uint64_t handle, UniffiRustFutureContinuationCallback _Nonnull callback, uint64_t callback_data -); -#endif -#ifndef UNIFFI_FFIDEF_FFI_DEVOLUTIONS_CRYPTO_UNIFFI_RUST_FUTURE_CANCEL_I8 -#define UNIFFI_FFIDEF_FFI_DEVOLUTIONS_CRYPTO_UNIFFI_RUST_FUTURE_CANCEL_I8 -void ffi_devolutions_crypto_uniffi_rust_future_cancel_i8(uint64_t handle -); -#endif -#ifndef UNIFFI_FFIDEF_FFI_DEVOLUTIONS_CRYPTO_UNIFFI_RUST_FUTURE_FREE_I8 -#define UNIFFI_FFIDEF_FFI_DEVOLUTIONS_CRYPTO_UNIFFI_RUST_FUTURE_FREE_I8 -void ffi_devolutions_crypto_uniffi_rust_future_free_i8(uint64_t handle -); -#endif -#ifndef UNIFFI_FFIDEF_FFI_DEVOLUTIONS_CRYPTO_UNIFFI_RUST_FUTURE_COMPLETE_I8 -#define UNIFFI_FFIDEF_FFI_DEVOLUTIONS_CRYPTO_UNIFFI_RUST_FUTURE_COMPLETE_I8 -int8_t ffi_devolutions_crypto_uniffi_rust_future_complete_i8(uint64_t handle, RustCallStatus *_Nonnull out_status -); -#endif -#ifndef UNIFFI_FFIDEF_FFI_DEVOLUTIONS_CRYPTO_UNIFFI_RUST_FUTURE_POLL_U16 -#define UNIFFI_FFIDEF_FFI_DEVOLUTIONS_CRYPTO_UNIFFI_RUST_FUTURE_POLL_U16 -void ffi_devolutions_crypto_uniffi_rust_future_poll_u16(uint64_t handle, UniffiRustFutureContinuationCallback _Nonnull callback, uint64_t callback_data -); -#endif -#ifndef UNIFFI_FFIDEF_FFI_DEVOLUTIONS_CRYPTO_UNIFFI_RUST_FUTURE_CANCEL_U16 -#define UNIFFI_FFIDEF_FFI_DEVOLUTIONS_CRYPTO_UNIFFI_RUST_FUTURE_CANCEL_U16 -void ffi_devolutions_crypto_uniffi_rust_future_cancel_u16(uint64_t handle -); -#endif -#ifndef UNIFFI_FFIDEF_FFI_DEVOLUTIONS_CRYPTO_UNIFFI_RUST_FUTURE_FREE_U16 -#define UNIFFI_FFIDEF_FFI_DEVOLUTIONS_CRYPTO_UNIFFI_RUST_FUTURE_FREE_U16 -void ffi_devolutions_crypto_uniffi_rust_future_free_u16(uint64_t handle -); -#endif -#ifndef UNIFFI_FFIDEF_FFI_DEVOLUTIONS_CRYPTO_UNIFFI_RUST_FUTURE_COMPLETE_U16 -#define UNIFFI_FFIDEF_FFI_DEVOLUTIONS_CRYPTO_UNIFFI_RUST_FUTURE_COMPLETE_U16 -uint16_t ffi_devolutions_crypto_uniffi_rust_future_complete_u16(uint64_t handle, RustCallStatus *_Nonnull out_status -); -#endif -#ifndef UNIFFI_FFIDEF_FFI_DEVOLUTIONS_CRYPTO_UNIFFI_RUST_FUTURE_POLL_I16 -#define UNIFFI_FFIDEF_FFI_DEVOLUTIONS_CRYPTO_UNIFFI_RUST_FUTURE_POLL_I16 -void ffi_devolutions_crypto_uniffi_rust_future_poll_i16(uint64_t handle, UniffiRustFutureContinuationCallback _Nonnull callback, uint64_t callback_data -); -#endif -#ifndef UNIFFI_FFIDEF_FFI_DEVOLUTIONS_CRYPTO_UNIFFI_RUST_FUTURE_CANCEL_I16 -#define UNIFFI_FFIDEF_FFI_DEVOLUTIONS_CRYPTO_UNIFFI_RUST_FUTURE_CANCEL_I16 -void ffi_devolutions_crypto_uniffi_rust_future_cancel_i16(uint64_t handle -); -#endif -#ifndef UNIFFI_FFIDEF_FFI_DEVOLUTIONS_CRYPTO_UNIFFI_RUST_FUTURE_FREE_I16 -#define UNIFFI_FFIDEF_FFI_DEVOLUTIONS_CRYPTO_UNIFFI_RUST_FUTURE_FREE_I16 -void ffi_devolutions_crypto_uniffi_rust_future_free_i16(uint64_t handle -); -#endif -#ifndef UNIFFI_FFIDEF_FFI_DEVOLUTIONS_CRYPTO_UNIFFI_RUST_FUTURE_COMPLETE_I16 -#define UNIFFI_FFIDEF_FFI_DEVOLUTIONS_CRYPTO_UNIFFI_RUST_FUTURE_COMPLETE_I16 -int16_t ffi_devolutions_crypto_uniffi_rust_future_complete_i16(uint64_t handle, RustCallStatus *_Nonnull out_status -); -#endif -#ifndef UNIFFI_FFIDEF_FFI_DEVOLUTIONS_CRYPTO_UNIFFI_RUST_FUTURE_POLL_U32 -#define UNIFFI_FFIDEF_FFI_DEVOLUTIONS_CRYPTO_UNIFFI_RUST_FUTURE_POLL_U32 -void ffi_devolutions_crypto_uniffi_rust_future_poll_u32(uint64_t handle, UniffiRustFutureContinuationCallback _Nonnull callback, uint64_t callback_data -); -#endif -#ifndef UNIFFI_FFIDEF_FFI_DEVOLUTIONS_CRYPTO_UNIFFI_RUST_FUTURE_CANCEL_U32 -#define UNIFFI_FFIDEF_FFI_DEVOLUTIONS_CRYPTO_UNIFFI_RUST_FUTURE_CANCEL_U32 -void ffi_devolutions_crypto_uniffi_rust_future_cancel_u32(uint64_t handle -); -#endif -#ifndef UNIFFI_FFIDEF_FFI_DEVOLUTIONS_CRYPTO_UNIFFI_RUST_FUTURE_FREE_U32 -#define UNIFFI_FFIDEF_FFI_DEVOLUTIONS_CRYPTO_UNIFFI_RUST_FUTURE_FREE_U32 -void ffi_devolutions_crypto_uniffi_rust_future_free_u32(uint64_t handle -); -#endif -#ifndef UNIFFI_FFIDEF_FFI_DEVOLUTIONS_CRYPTO_UNIFFI_RUST_FUTURE_COMPLETE_U32 -#define UNIFFI_FFIDEF_FFI_DEVOLUTIONS_CRYPTO_UNIFFI_RUST_FUTURE_COMPLETE_U32 -uint32_t ffi_devolutions_crypto_uniffi_rust_future_complete_u32(uint64_t handle, RustCallStatus *_Nonnull out_status -); -#endif -#ifndef UNIFFI_FFIDEF_FFI_DEVOLUTIONS_CRYPTO_UNIFFI_RUST_FUTURE_POLL_I32 -#define UNIFFI_FFIDEF_FFI_DEVOLUTIONS_CRYPTO_UNIFFI_RUST_FUTURE_POLL_I32 -void ffi_devolutions_crypto_uniffi_rust_future_poll_i32(uint64_t handle, UniffiRustFutureContinuationCallback _Nonnull callback, uint64_t callback_data -); -#endif -#ifndef UNIFFI_FFIDEF_FFI_DEVOLUTIONS_CRYPTO_UNIFFI_RUST_FUTURE_CANCEL_I32 -#define UNIFFI_FFIDEF_FFI_DEVOLUTIONS_CRYPTO_UNIFFI_RUST_FUTURE_CANCEL_I32 -void ffi_devolutions_crypto_uniffi_rust_future_cancel_i32(uint64_t handle -); -#endif -#ifndef UNIFFI_FFIDEF_FFI_DEVOLUTIONS_CRYPTO_UNIFFI_RUST_FUTURE_FREE_I32 -#define UNIFFI_FFIDEF_FFI_DEVOLUTIONS_CRYPTO_UNIFFI_RUST_FUTURE_FREE_I32 -void ffi_devolutions_crypto_uniffi_rust_future_free_i32(uint64_t handle -); -#endif -#ifndef UNIFFI_FFIDEF_FFI_DEVOLUTIONS_CRYPTO_UNIFFI_RUST_FUTURE_COMPLETE_I32 -#define UNIFFI_FFIDEF_FFI_DEVOLUTIONS_CRYPTO_UNIFFI_RUST_FUTURE_COMPLETE_I32 -int32_t ffi_devolutions_crypto_uniffi_rust_future_complete_i32(uint64_t handle, RustCallStatus *_Nonnull out_status -); -#endif -#ifndef UNIFFI_FFIDEF_FFI_DEVOLUTIONS_CRYPTO_UNIFFI_RUST_FUTURE_POLL_U64 -#define UNIFFI_FFIDEF_FFI_DEVOLUTIONS_CRYPTO_UNIFFI_RUST_FUTURE_POLL_U64 -void ffi_devolutions_crypto_uniffi_rust_future_poll_u64(uint64_t handle, UniffiRustFutureContinuationCallback _Nonnull callback, uint64_t callback_data -); -#endif -#ifndef UNIFFI_FFIDEF_FFI_DEVOLUTIONS_CRYPTO_UNIFFI_RUST_FUTURE_CANCEL_U64 -#define UNIFFI_FFIDEF_FFI_DEVOLUTIONS_CRYPTO_UNIFFI_RUST_FUTURE_CANCEL_U64 -void ffi_devolutions_crypto_uniffi_rust_future_cancel_u64(uint64_t handle -); -#endif -#ifndef UNIFFI_FFIDEF_FFI_DEVOLUTIONS_CRYPTO_UNIFFI_RUST_FUTURE_FREE_U64 -#define UNIFFI_FFIDEF_FFI_DEVOLUTIONS_CRYPTO_UNIFFI_RUST_FUTURE_FREE_U64 -void ffi_devolutions_crypto_uniffi_rust_future_free_u64(uint64_t handle -); -#endif -#ifndef UNIFFI_FFIDEF_FFI_DEVOLUTIONS_CRYPTO_UNIFFI_RUST_FUTURE_COMPLETE_U64 -#define UNIFFI_FFIDEF_FFI_DEVOLUTIONS_CRYPTO_UNIFFI_RUST_FUTURE_COMPLETE_U64 -uint64_t ffi_devolutions_crypto_uniffi_rust_future_complete_u64(uint64_t handle, RustCallStatus *_Nonnull out_status -); -#endif -#ifndef UNIFFI_FFIDEF_FFI_DEVOLUTIONS_CRYPTO_UNIFFI_RUST_FUTURE_POLL_I64 -#define UNIFFI_FFIDEF_FFI_DEVOLUTIONS_CRYPTO_UNIFFI_RUST_FUTURE_POLL_I64 -void ffi_devolutions_crypto_uniffi_rust_future_poll_i64(uint64_t handle, UniffiRustFutureContinuationCallback _Nonnull callback, uint64_t callback_data -); -#endif -#ifndef UNIFFI_FFIDEF_FFI_DEVOLUTIONS_CRYPTO_UNIFFI_RUST_FUTURE_CANCEL_I64 -#define UNIFFI_FFIDEF_FFI_DEVOLUTIONS_CRYPTO_UNIFFI_RUST_FUTURE_CANCEL_I64 -void ffi_devolutions_crypto_uniffi_rust_future_cancel_i64(uint64_t handle -); -#endif -#ifndef UNIFFI_FFIDEF_FFI_DEVOLUTIONS_CRYPTO_UNIFFI_RUST_FUTURE_FREE_I64 -#define UNIFFI_FFIDEF_FFI_DEVOLUTIONS_CRYPTO_UNIFFI_RUST_FUTURE_FREE_I64 -void ffi_devolutions_crypto_uniffi_rust_future_free_i64(uint64_t handle -); -#endif -#ifndef UNIFFI_FFIDEF_FFI_DEVOLUTIONS_CRYPTO_UNIFFI_RUST_FUTURE_COMPLETE_I64 -#define UNIFFI_FFIDEF_FFI_DEVOLUTIONS_CRYPTO_UNIFFI_RUST_FUTURE_COMPLETE_I64 -int64_t ffi_devolutions_crypto_uniffi_rust_future_complete_i64(uint64_t handle, RustCallStatus *_Nonnull out_status -); -#endif -#ifndef UNIFFI_FFIDEF_FFI_DEVOLUTIONS_CRYPTO_UNIFFI_RUST_FUTURE_POLL_F32 -#define UNIFFI_FFIDEF_FFI_DEVOLUTIONS_CRYPTO_UNIFFI_RUST_FUTURE_POLL_F32 -void ffi_devolutions_crypto_uniffi_rust_future_poll_f32(uint64_t handle, UniffiRustFutureContinuationCallback _Nonnull callback, uint64_t callback_data -); -#endif -#ifndef UNIFFI_FFIDEF_FFI_DEVOLUTIONS_CRYPTO_UNIFFI_RUST_FUTURE_CANCEL_F32 -#define UNIFFI_FFIDEF_FFI_DEVOLUTIONS_CRYPTO_UNIFFI_RUST_FUTURE_CANCEL_F32 -void ffi_devolutions_crypto_uniffi_rust_future_cancel_f32(uint64_t handle -); -#endif -#ifndef UNIFFI_FFIDEF_FFI_DEVOLUTIONS_CRYPTO_UNIFFI_RUST_FUTURE_FREE_F32 -#define UNIFFI_FFIDEF_FFI_DEVOLUTIONS_CRYPTO_UNIFFI_RUST_FUTURE_FREE_F32 -void ffi_devolutions_crypto_uniffi_rust_future_free_f32(uint64_t handle -); -#endif -#ifndef UNIFFI_FFIDEF_FFI_DEVOLUTIONS_CRYPTO_UNIFFI_RUST_FUTURE_COMPLETE_F32 -#define UNIFFI_FFIDEF_FFI_DEVOLUTIONS_CRYPTO_UNIFFI_RUST_FUTURE_COMPLETE_F32 -float ffi_devolutions_crypto_uniffi_rust_future_complete_f32(uint64_t handle, RustCallStatus *_Nonnull out_status -); -#endif -#ifndef UNIFFI_FFIDEF_FFI_DEVOLUTIONS_CRYPTO_UNIFFI_RUST_FUTURE_POLL_F64 -#define UNIFFI_FFIDEF_FFI_DEVOLUTIONS_CRYPTO_UNIFFI_RUST_FUTURE_POLL_F64 -void ffi_devolutions_crypto_uniffi_rust_future_poll_f64(uint64_t handle, UniffiRustFutureContinuationCallback _Nonnull callback, uint64_t callback_data -); -#endif -#ifndef UNIFFI_FFIDEF_FFI_DEVOLUTIONS_CRYPTO_UNIFFI_RUST_FUTURE_CANCEL_F64 -#define UNIFFI_FFIDEF_FFI_DEVOLUTIONS_CRYPTO_UNIFFI_RUST_FUTURE_CANCEL_F64 -void ffi_devolutions_crypto_uniffi_rust_future_cancel_f64(uint64_t handle -); -#endif -#ifndef UNIFFI_FFIDEF_FFI_DEVOLUTIONS_CRYPTO_UNIFFI_RUST_FUTURE_FREE_F64 -#define UNIFFI_FFIDEF_FFI_DEVOLUTIONS_CRYPTO_UNIFFI_RUST_FUTURE_FREE_F64 -void ffi_devolutions_crypto_uniffi_rust_future_free_f64(uint64_t handle -); -#endif -#ifndef UNIFFI_FFIDEF_FFI_DEVOLUTIONS_CRYPTO_UNIFFI_RUST_FUTURE_COMPLETE_F64 -#define UNIFFI_FFIDEF_FFI_DEVOLUTIONS_CRYPTO_UNIFFI_RUST_FUTURE_COMPLETE_F64 -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_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 -); -#endif -#ifndef UNIFFI_FFIDEF_FFI_DEVOLUTIONS_CRYPTO_UNIFFI_RUST_FUTURE_CANCEL_RUST_BUFFER -#define UNIFFI_FFIDEF_FFI_DEVOLUTIONS_CRYPTO_UNIFFI_RUST_FUTURE_CANCEL_RUST_BUFFER -void ffi_devolutions_crypto_uniffi_rust_future_cancel_rust_buffer(uint64_t handle -); -#endif -#ifndef UNIFFI_FFIDEF_FFI_DEVOLUTIONS_CRYPTO_UNIFFI_RUST_FUTURE_FREE_RUST_BUFFER -#define UNIFFI_FFIDEF_FFI_DEVOLUTIONS_CRYPTO_UNIFFI_RUST_FUTURE_FREE_RUST_BUFFER -void ffi_devolutions_crypto_uniffi_rust_future_free_rust_buffer(uint64_t handle -); -#endif -#ifndef UNIFFI_FFIDEF_FFI_DEVOLUTIONS_CRYPTO_UNIFFI_RUST_FUTURE_COMPLETE_RUST_BUFFER -#define UNIFFI_FFIDEF_FFI_DEVOLUTIONS_CRYPTO_UNIFFI_RUST_FUTURE_COMPLETE_RUST_BUFFER -RustBuffer ffi_devolutions_crypto_uniffi_rust_future_complete_rust_buffer(uint64_t handle, RustCallStatus *_Nonnull out_status -); -#endif -#ifndef UNIFFI_FFIDEF_FFI_DEVOLUTIONS_CRYPTO_UNIFFI_RUST_FUTURE_POLL_VOID -#define UNIFFI_FFIDEF_FFI_DEVOLUTIONS_CRYPTO_UNIFFI_RUST_FUTURE_POLL_VOID -void ffi_devolutions_crypto_uniffi_rust_future_poll_void(uint64_t handle, UniffiRustFutureContinuationCallback _Nonnull callback, uint64_t callback_data -); -#endif -#ifndef UNIFFI_FFIDEF_FFI_DEVOLUTIONS_CRYPTO_UNIFFI_RUST_FUTURE_CANCEL_VOID -#define UNIFFI_FFIDEF_FFI_DEVOLUTIONS_CRYPTO_UNIFFI_RUST_FUTURE_CANCEL_VOID -void ffi_devolutions_crypto_uniffi_rust_future_cancel_void(uint64_t handle -); -#endif -#ifndef UNIFFI_FFIDEF_FFI_DEVOLUTIONS_CRYPTO_UNIFFI_RUST_FUTURE_FREE_VOID -#define UNIFFI_FFIDEF_FFI_DEVOLUTIONS_CRYPTO_UNIFFI_RUST_FUTURE_FREE_VOID -void ffi_devolutions_crypto_uniffi_rust_future_free_void(uint64_t handle -); -#endif -#ifndef UNIFFI_FFIDEF_FFI_DEVOLUTIONS_CRYPTO_UNIFFI_RUST_FUTURE_COMPLETE_VOID -#define UNIFFI_FFIDEF_FFI_DEVOLUTIONS_CRYPTO_UNIFFI_RUST_FUTURE_COMPLETE_VOID -void ffi_devolutions_crypto_uniffi_rust_future_complete_void(uint64_t handle, RustCallStatus *_Nonnull out_status -); -#endif -#ifndef UNIFFI_FFIDEF_UNIFFI_DEVOLUTIONS_CRYPTO_UNIFFI_CHECKSUM_FUNC_BASE64_DECODE -#define UNIFFI_FFIDEF_UNIFFI_DEVOLUTIONS_CRYPTO_UNIFFI_CHECKSUM_FUNC_BASE64_DECODE -uint16_t uniffi_devolutions_crypto_uniffi_checksum_func_base64_decode(void - -); -#endif -#ifndef UNIFFI_FFIDEF_UNIFFI_DEVOLUTIONS_CRYPTO_UNIFFI_CHECKSUM_FUNC_BASE64_DECODE_URL -#define UNIFFI_FFIDEF_UNIFFI_DEVOLUTIONS_CRYPTO_UNIFFI_CHECKSUM_FUNC_BASE64_DECODE_URL -uint16_t uniffi_devolutions_crypto_uniffi_checksum_func_base64_decode_url(void - -); -#endif -#ifndef UNIFFI_FFIDEF_UNIFFI_DEVOLUTIONS_CRYPTO_UNIFFI_CHECKSUM_FUNC_BASE64_ENCODE -#define UNIFFI_FFIDEF_UNIFFI_DEVOLUTIONS_CRYPTO_UNIFFI_CHECKSUM_FUNC_BASE64_ENCODE -uint16_t uniffi_devolutions_crypto_uniffi_checksum_func_base64_encode(void - -); -#endif -#ifndef UNIFFI_FFIDEF_UNIFFI_DEVOLUTIONS_CRYPTO_UNIFFI_CHECKSUM_FUNC_BASE64_ENCODE_URL -#define UNIFFI_FFIDEF_UNIFFI_DEVOLUTIONS_CRYPTO_UNIFFI_CHECKSUM_FUNC_BASE64_ENCODE_URL -uint16_t uniffi_devolutions_crypto_uniffi_checksum_func_base64_encode_url(void - -); -#endif -#ifndef UNIFFI_FFIDEF_UNIFFI_DEVOLUTIONS_CRYPTO_UNIFFI_CHECKSUM_FUNC_DECRYPT -#define UNIFFI_FFIDEF_UNIFFI_DEVOLUTIONS_CRYPTO_UNIFFI_CHECKSUM_FUNC_DECRYPT -uint16_t uniffi_devolutions_crypto_uniffi_checksum_func_decrypt(void - -); -#endif -#ifndef UNIFFI_FFIDEF_UNIFFI_DEVOLUTIONS_CRYPTO_UNIFFI_CHECKSUM_FUNC_DECRYPT_ASYMMETRIC -#define UNIFFI_FFIDEF_UNIFFI_DEVOLUTIONS_CRYPTO_UNIFFI_CHECKSUM_FUNC_DECRYPT_ASYMMETRIC -uint16_t uniffi_devolutions_crypto_uniffi_checksum_func_decrypt_asymmetric(void - -); -#endif -#ifndef UNIFFI_FFIDEF_UNIFFI_DEVOLUTIONS_CRYPTO_UNIFFI_CHECKSUM_FUNC_DECRYPT_ASYMMETRIC_WITH_AAD -#define UNIFFI_FFIDEF_UNIFFI_DEVOLUTIONS_CRYPTO_UNIFFI_CHECKSUM_FUNC_DECRYPT_ASYMMETRIC_WITH_AAD -uint16_t uniffi_devolutions_crypto_uniffi_checksum_func_decrypt_asymmetric_with_aad(void - -); -#endif -#ifndef UNIFFI_FFIDEF_UNIFFI_DEVOLUTIONS_CRYPTO_UNIFFI_CHECKSUM_FUNC_DECRYPT_WITH_AAD -#define UNIFFI_FFIDEF_UNIFFI_DEVOLUTIONS_CRYPTO_UNIFFI_CHECKSUM_FUNC_DECRYPT_WITH_AAD -uint16_t uniffi_devolutions_crypto_uniffi_checksum_func_decrypt_with_aad(void - -); -#endif -#ifndef UNIFFI_FFIDEF_UNIFFI_DEVOLUTIONS_CRYPTO_UNIFFI_CHECKSUM_FUNC_DERIVE_KEY_ARGON2 -#define UNIFFI_FFIDEF_UNIFFI_DEVOLUTIONS_CRYPTO_UNIFFI_CHECKSUM_FUNC_DERIVE_KEY_ARGON2 -uint16_t uniffi_devolutions_crypto_uniffi_checksum_func_derive_key_argon2(void - -); -#endif -#ifndef UNIFFI_FFIDEF_UNIFFI_DEVOLUTIONS_CRYPTO_UNIFFI_CHECKSUM_FUNC_DERIVE_KEY_PBKDF2 -#define UNIFFI_FFIDEF_UNIFFI_DEVOLUTIONS_CRYPTO_UNIFFI_CHECKSUM_FUNC_DERIVE_KEY_PBKDF2 -uint16_t uniffi_devolutions_crypto_uniffi_checksum_func_derive_key_pbkdf2(void - -); -#endif -#ifndef UNIFFI_FFIDEF_UNIFFI_DEVOLUTIONS_CRYPTO_UNIFFI_CHECKSUM_FUNC_ENCRYPT -#define UNIFFI_FFIDEF_UNIFFI_DEVOLUTIONS_CRYPTO_UNIFFI_CHECKSUM_FUNC_ENCRYPT -uint16_t uniffi_devolutions_crypto_uniffi_checksum_func_encrypt(void - -); -#endif -#ifndef UNIFFI_FFIDEF_UNIFFI_DEVOLUTIONS_CRYPTO_UNIFFI_CHECKSUM_FUNC_ENCRYPT_ASYMMETRIC -#define UNIFFI_FFIDEF_UNIFFI_DEVOLUTIONS_CRYPTO_UNIFFI_CHECKSUM_FUNC_ENCRYPT_ASYMMETRIC -uint16_t uniffi_devolutions_crypto_uniffi_checksum_func_encrypt_asymmetric(void - -); -#endif -#ifndef UNIFFI_FFIDEF_UNIFFI_DEVOLUTIONS_CRYPTO_UNIFFI_CHECKSUM_FUNC_ENCRYPT_ASYMMETRIC_WITH_AAD -#define UNIFFI_FFIDEF_UNIFFI_DEVOLUTIONS_CRYPTO_UNIFFI_CHECKSUM_FUNC_ENCRYPT_ASYMMETRIC_WITH_AAD -uint16_t uniffi_devolutions_crypto_uniffi_checksum_func_encrypt_asymmetric_with_aad(void - -); -#endif -#ifndef UNIFFI_FFIDEF_UNIFFI_DEVOLUTIONS_CRYPTO_UNIFFI_CHECKSUM_FUNC_ENCRYPT_WITH_AAD -#define UNIFFI_FFIDEF_UNIFFI_DEVOLUTIONS_CRYPTO_UNIFFI_CHECKSUM_FUNC_ENCRYPT_WITH_AAD -uint16_t uniffi_devolutions_crypto_uniffi_checksum_func_encrypt_with_aad(void - -); -#endif -#ifndef UNIFFI_FFIDEF_UNIFFI_DEVOLUTIONS_CRYPTO_UNIFFI_CHECKSUM_FUNC_GENERATE_KEY -#define UNIFFI_FFIDEF_UNIFFI_DEVOLUTIONS_CRYPTO_UNIFFI_CHECKSUM_FUNC_GENERATE_KEY -uint16_t uniffi_devolutions_crypto_uniffi_checksum_func_generate_key(void - -); -#endif -#ifndef UNIFFI_FFIDEF_UNIFFI_DEVOLUTIONS_CRYPTO_UNIFFI_CHECKSUM_FUNC_GENERATE_KEYPAIR -#define UNIFFI_FFIDEF_UNIFFI_DEVOLUTIONS_CRYPTO_UNIFFI_CHECKSUM_FUNC_GENERATE_KEYPAIR -uint16_t uniffi_devolutions_crypto_uniffi_checksum_func_generate_keypair(void - -); -#endif -#ifndef UNIFFI_FFIDEF_UNIFFI_DEVOLUTIONS_CRYPTO_UNIFFI_CHECKSUM_FUNC_GENERATE_SHARED_KEY -#define UNIFFI_FFIDEF_UNIFFI_DEVOLUTIONS_CRYPTO_UNIFFI_CHECKSUM_FUNC_GENERATE_SHARED_KEY -uint16_t uniffi_devolutions_crypto_uniffi_checksum_func_generate_shared_key(void - -); -#endif -#ifndef UNIFFI_FFIDEF_UNIFFI_DEVOLUTIONS_CRYPTO_UNIFFI_CHECKSUM_FUNC_GENERATE_SIGNING_KEYPAIR -#define UNIFFI_FFIDEF_UNIFFI_DEVOLUTIONS_CRYPTO_UNIFFI_CHECKSUM_FUNC_GENERATE_SIGNING_KEYPAIR -uint16_t uniffi_devolutions_crypto_uniffi_checksum_func_generate_signing_keypair(void - -); -#endif -#ifndef UNIFFI_FFIDEF_UNIFFI_DEVOLUTIONS_CRYPTO_UNIFFI_CHECKSUM_FUNC_HASH_PASSWORD -#define UNIFFI_FFIDEF_UNIFFI_DEVOLUTIONS_CRYPTO_UNIFFI_CHECKSUM_FUNC_HASH_PASSWORD -uint16_t uniffi_devolutions_crypto_uniffi_checksum_func_hash_password(void - -); -#endif -#ifndef UNIFFI_FFIDEF_UNIFFI_DEVOLUTIONS_CRYPTO_UNIFFI_CHECKSUM_FUNC_JOIN_SHARES -#define UNIFFI_FFIDEF_UNIFFI_DEVOLUTIONS_CRYPTO_UNIFFI_CHECKSUM_FUNC_JOIN_SHARES -uint16_t uniffi_devolutions_crypto_uniffi_checksum_func_join_shares(void - -); -#endif -#ifndef UNIFFI_FFIDEF_UNIFFI_DEVOLUTIONS_CRYPTO_UNIFFI_CHECKSUM_FUNC_MIX_KEY_EXCHANGE -#define UNIFFI_FFIDEF_UNIFFI_DEVOLUTIONS_CRYPTO_UNIFFI_CHECKSUM_FUNC_MIX_KEY_EXCHANGE -uint16_t uniffi_devolutions_crypto_uniffi_checksum_func_mix_key_exchange(void - -); -#endif -#ifndef UNIFFI_FFIDEF_UNIFFI_DEVOLUTIONS_CRYPTO_UNIFFI_CHECKSUM_FUNC_SIGN -#define UNIFFI_FFIDEF_UNIFFI_DEVOLUTIONS_CRYPTO_UNIFFI_CHECKSUM_FUNC_SIGN -uint16_t uniffi_devolutions_crypto_uniffi_checksum_func_sign(void - -); -#endif -#ifndef UNIFFI_FFIDEF_UNIFFI_DEVOLUTIONS_CRYPTO_UNIFFI_CHECKSUM_FUNC_VALIDATE_HEADER -#define UNIFFI_FFIDEF_UNIFFI_DEVOLUTIONS_CRYPTO_UNIFFI_CHECKSUM_FUNC_VALIDATE_HEADER -uint16_t uniffi_devolutions_crypto_uniffi_checksum_func_validate_header(void - -); -#endif -#ifndef UNIFFI_FFIDEF_UNIFFI_DEVOLUTIONS_CRYPTO_UNIFFI_CHECKSUM_FUNC_VERIFY_PASSWORD -#define UNIFFI_FFIDEF_UNIFFI_DEVOLUTIONS_CRYPTO_UNIFFI_CHECKSUM_FUNC_VERIFY_PASSWORD -uint16_t uniffi_devolutions_crypto_uniffi_checksum_func_verify_password(void - -); -#endif -#ifndef UNIFFI_FFIDEF_UNIFFI_DEVOLUTIONS_CRYPTO_UNIFFI_CHECKSUM_FUNC_VERIFY_SIGNATURE -#define UNIFFI_FFIDEF_UNIFFI_DEVOLUTIONS_CRYPTO_UNIFFI_CHECKSUM_FUNC_VERIFY_SIGNATURE -uint16_t uniffi_devolutions_crypto_uniffi_checksum_func_verify_signature(void - -); -#endif -#ifndef UNIFFI_FFIDEF_UNIFFI_DEVOLUTIONS_CRYPTO_UNIFFI_CHECKSUM_METHOD_ARGON2PARAMETERS_GET_BYTES -#define UNIFFI_FFIDEF_UNIFFI_DEVOLUTIONS_CRYPTO_UNIFFI_CHECKSUM_METHOD_ARGON2PARAMETERS_GET_BYTES -uint16_t uniffi_devolutions_crypto_uniffi_checksum_method_argon2parameters_get_bytes(void - -); -#endif -#ifndef UNIFFI_FFIDEF_UNIFFI_DEVOLUTIONS_CRYPTO_UNIFFI_CHECKSUM_METHOD_ARGON2PARAMETERSBUILDER_ASSOCIATED_DATA -#define UNIFFI_FFIDEF_UNIFFI_DEVOLUTIONS_CRYPTO_UNIFFI_CHECKSUM_METHOD_ARGON2PARAMETERSBUILDER_ASSOCIATED_DATA -uint16_t uniffi_devolutions_crypto_uniffi_checksum_method_argon2parametersbuilder_associated_data(void - -); -#endif -#ifndef UNIFFI_FFIDEF_UNIFFI_DEVOLUTIONS_CRYPTO_UNIFFI_CHECKSUM_METHOD_ARGON2PARAMETERSBUILDER_BUILD -#define UNIFFI_FFIDEF_UNIFFI_DEVOLUTIONS_CRYPTO_UNIFFI_CHECKSUM_METHOD_ARGON2PARAMETERSBUILDER_BUILD -uint16_t uniffi_devolutions_crypto_uniffi_checksum_method_argon2parametersbuilder_build(void - -); -#endif -#ifndef UNIFFI_FFIDEF_UNIFFI_DEVOLUTIONS_CRYPTO_UNIFFI_CHECKSUM_METHOD_ARGON2PARAMETERSBUILDER_DC_VERSION -#define UNIFFI_FFIDEF_UNIFFI_DEVOLUTIONS_CRYPTO_UNIFFI_CHECKSUM_METHOD_ARGON2PARAMETERSBUILDER_DC_VERSION -uint16_t uniffi_devolutions_crypto_uniffi_checksum_method_argon2parametersbuilder_dc_version(void - -); -#endif -#ifndef UNIFFI_FFIDEF_UNIFFI_DEVOLUTIONS_CRYPTO_UNIFFI_CHECKSUM_METHOD_ARGON2PARAMETERSBUILDER_ITERATIONS -#define UNIFFI_FFIDEF_UNIFFI_DEVOLUTIONS_CRYPTO_UNIFFI_CHECKSUM_METHOD_ARGON2PARAMETERSBUILDER_ITERATIONS -uint16_t uniffi_devolutions_crypto_uniffi_checksum_method_argon2parametersbuilder_iterations(void - -); -#endif -#ifndef UNIFFI_FFIDEF_UNIFFI_DEVOLUTIONS_CRYPTO_UNIFFI_CHECKSUM_METHOD_ARGON2PARAMETERSBUILDER_LANES -#define UNIFFI_FFIDEF_UNIFFI_DEVOLUTIONS_CRYPTO_UNIFFI_CHECKSUM_METHOD_ARGON2PARAMETERSBUILDER_LANES -uint16_t uniffi_devolutions_crypto_uniffi_checksum_method_argon2parametersbuilder_lanes(void - -); -#endif -#ifndef UNIFFI_FFIDEF_UNIFFI_DEVOLUTIONS_CRYPTO_UNIFFI_CHECKSUM_METHOD_ARGON2PARAMETERSBUILDER_LENGTH -#define UNIFFI_FFIDEF_UNIFFI_DEVOLUTIONS_CRYPTO_UNIFFI_CHECKSUM_METHOD_ARGON2PARAMETERSBUILDER_LENGTH -uint16_t uniffi_devolutions_crypto_uniffi_checksum_method_argon2parametersbuilder_length(void - -); -#endif -#ifndef UNIFFI_FFIDEF_UNIFFI_DEVOLUTIONS_CRYPTO_UNIFFI_CHECKSUM_METHOD_ARGON2PARAMETERSBUILDER_MEMORY -#define UNIFFI_FFIDEF_UNIFFI_DEVOLUTIONS_CRYPTO_UNIFFI_CHECKSUM_METHOD_ARGON2PARAMETERSBUILDER_MEMORY -uint16_t uniffi_devolutions_crypto_uniffi_checksum_method_argon2parametersbuilder_memory(void - -); -#endif -#ifndef UNIFFI_FFIDEF_UNIFFI_DEVOLUTIONS_CRYPTO_UNIFFI_CHECKSUM_METHOD_ARGON2PARAMETERSBUILDER_SALT -#define UNIFFI_FFIDEF_UNIFFI_DEVOLUTIONS_CRYPTO_UNIFFI_CHECKSUM_METHOD_ARGON2PARAMETERSBUILDER_SALT -uint16_t uniffi_devolutions_crypto_uniffi_checksum_method_argon2parametersbuilder_salt(void - -); -#endif -#ifndef UNIFFI_FFIDEF_UNIFFI_DEVOLUTIONS_CRYPTO_UNIFFI_CHECKSUM_METHOD_ARGON2PARAMETERSBUILDER_SECRET_KEY -#define UNIFFI_FFIDEF_UNIFFI_DEVOLUTIONS_CRYPTO_UNIFFI_CHECKSUM_METHOD_ARGON2PARAMETERSBUILDER_SECRET_KEY -uint16_t uniffi_devolutions_crypto_uniffi_checksum_method_argon2parametersbuilder_secret_key(void - -); -#endif -#ifndef UNIFFI_FFIDEF_UNIFFI_DEVOLUTIONS_CRYPTO_UNIFFI_CHECKSUM_METHOD_ARGON2PARAMETERSBUILDER_VARIANT -#define UNIFFI_FFIDEF_UNIFFI_DEVOLUTIONS_CRYPTO_UNIFFI_CHECKSUM_METHOD_ARGON2PARAMETERSBUILDER_VARIANT -uint16_t uniffi_devolutions_crypto_uniffi_checksum_method_argon2parametersbuilder_variant(void - -); -#endif -#ifndef UNIFFI_FFIDEF_UNIFFI_DEVOLUTIONS_CRYPTO_UNIFFI_CHECKSUM_METHOD_ARGON2PARAMETERSBUILDER_VERSION -#define UNIFFI_FFIDEF_UNIFFI_DEVOLUTIONS_CRYPTO_UNIFFI_CHECKSUM_METHOD_ARGON2PARAMETERSBUILDER_VERSION -uint16_t uniffi_devolutions_crypto_uniffi_checksum_method_argon2parametersbuilder_version(void - -); -#endif -#ifndef UNIFFI_FFIDEF_UNIFFI_DEVOLUTIONS_CRYPTO_UNIFFI_CHECKSUM_METHOD_SIGNINGKEYPAIR_GET_PRIVATE_KEY -#define UNIFFI_FFIDEF_UNIFFI_DEVOLUTIONS_CRYPTO_UNIFFI_CHECKSUM_METHOD_SIGNINGKEYPAIR_GET_PRIVATE_KEY -uint16_t uniffi_devolutions_crypto_uniffi_checksum_method_signingkeypair_get_private_key(void - -); -#endif -#ifndef UNIFFI_FFIDEF_UNIFFI_DEVOLUTIONS_CRYPTO_UNIFFI_CHECKSUM_METHOD_SIGNINGKEYPAIR_GET_PUBLIC_KEY -#define UNIFFI_FFIDEF_UNIFFI_DEVOLUTIONS_CRYPTO_UNIFFI_CHECKSUM_METHOD_SIGNINGKEYPAIR_GET_PUBLIC_KEY -uint16_t uniffi_devolutions_crypto_uniffi_checksum_method_signingkeypair_get_public_key(void - -); -#endif -#ifndef UNIFFI_FFIDEF_UNIFFI_DEVOLUTIONS_CRYPTO_UNIFFI_CHECKSUM_CONSTRUCTOR_ARGON2PARAMETERS_NEW_FROM_BYTES -#define UNIFFI_FFIDEF_UNIFFI_DEVOLUTIONS_CRYPTO_UNIFFI_CHECKSUM_CONSTRUCTOR_ARGON2PARAMETERS_NEW_FROM_BYTES -uint16_t uniffi_devolutions_crypto_uniffi_checksum_constructor_argon2parameters_new_from_bytes(void - -); -#endif -#ifndef UNIFFI_FFIDEF_UNIFFI_DEVOLUTIONS_CRYPTO_UNIFFI_CHECKSUM_CONSTRUCTOR_ARGON2PARAMETERSBUILDER_NEW -#define UNIFFI_FFIDEF_UNIFFI_DEVOLUTIONS_CRYPTO_UNIFFI_CHECKSUM_CONSTRUCTOR_ARGON2PARAMETERSBUILDER_NEW -uint16_t uniffi_devolutions_crypto_uniffi_checksum_constructor_argon2parametersbuilder_new(void - -); -#endif -#ifndef UNIFFI_FFIDEF_UNIFFI_DEVOLUTIONS_CRYPTO_UNIFFI_CHECKSUM_CONSTRUCTOR_SIGNINGKEYPAIR_NEW_FROM_BYTES -#define UNIFFI_FFIDEF_UNIFFI_DEVOLUTIONS_CRYPTO_UNIFFI_CHECKSUM_CONSTRUCTOR_SIGNINGKEYPAIR_NEW_FROM_BYTES -uint16_t uniffi_devolutions_crypto_uniffi_checksum_constructor_signingkeypair_new_from_bytes(void - -); -#endif -#ifndef UNIFFI_FFIDEF_FFI_DEVOLUTIONS_CRYPTO_UNIFFI_UNIFFI_CONTRACT_VERSION -#define UNIFFI_FFIDEF_FFI_DEVOLUTIONS_CRYPTO_UNIFFI_UNIFFI_CONTRACT_VERSION -uint32_t ffi_devolutions_crypto_uniffi_uniffi_contract_version(void - -); -#endif - From 097bb16ed89c9cc06ff7d992b73daf59d2e7193f Mon Sep 17 00:00:00 2001 From: Mathieu Morrissette Date: Mon, 12 Jan 2026 10:11:07 -0500 Subject: [PATCH 03/11] improvements --- .../src/argon2parameters.rs | 2 - .../crypto/devolutions_crypto_uniffi.kt | 2997 ----------------- .../org/devolutions/crypto/AsymmetricTest.kt | 10 +- 3 files changed, 5 insertions(+), 3004 deletions(-) delete mode 100644 wrappers/kotlin/lib/src/main/kotlin/org/devolutions/crypto/devolutions_crypto_uniffi.kt diff --git a/uniffi/devolutions-crypto-uniffi/src/argon2parameters.rs b/uniffi/devolutions-crypto-uniffi/src/argon2parameters.rs index 805e2bab2..5b4c948df 100644 --- a/uniffi/devolutions-crypto-uniffi/src/argon2parameters.rs +++ b/uniffi/devolutions-crypto-uniffi/src/argon2parameters.rs @@ -84,7 +84,6 @@ impl Argon2ParametersBuilder { } 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(); @@ -96,7 +95,6 @@ impl Argon2ParametersBuilder { 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)) 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 deleted file mode 100644 index f47af17cb..000000000 --- a/wrappers/kotlin/lib/src/main/kotlin/org/devolutions/crypto/devolutions_crypto_uniffi.kt +++ /dev/null @@ -1,2997 +0,0 @@ -// 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 50b24a2ad..ba04522c0 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 @@ -63,8 +63,8 @@ class AsymmetricTest { @Test fun mixKeyExchangeTest() { - val bobKeypair = generateKeypair(null) - val aliceKeypair = generateKeypair(null) + val bobKeypair = generateKeypair() + val aliceKeypair = generateKeypair() val bobShared = mixKeyExchange(bobKeypair.privateKey, aliceKeypair.publicKey) val aliceShared = mixKeyExchange(aliceKeypair.privateKey, bobKeypair.publicKey) @@ -76,9 +76,9 @@ class AsymmetricTest { @Test fun mixKeyExchangeNotEqualsTest() { - val bobKeypair = generateKeypair(null) - val aliceKeypair = generateKeypair(null) - val eveKeypair = generateKeypair(null) + val bobKeypair = generateKeypair() + val aliceKeypair = generateKeypair() + val eveKeypair = generateKeypair() val bobAliceShared = mixKeyExchange(bobKeypair.privateKey, aliceKeypair.publicKey) val aliceBobShared = mixKeyExchange(aliceKeypair.privateKey, bobKeypair.publicKey) From 83a95f37bd578d513e313e648c77ab38c975d1e6 Mon Sep 17 00:00:00 2001 From: Mathieu Morrissette Date: Mon, 12 Jan 2026 11:19:13 -0500 Subject: [PATCH 04/11] improvements --- Cargo.lock | 7 ------- Cargo.toml | 3 ++- uniffi/devolutions-crypto-uniffi/Cargo.toml | 2 +- 3 files changed, 3 insertions(+), 9 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index fbf8655d3..f23850974 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -427,12 +427,6 @@ 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" @@ -1153,7 +1147,6 @@ dependencies = [ "base64 0.22.1", "blake2b_simd", "constant_time_eq 0.4.2", - "crossbeam-utils", ] [[package]] diff --git a/Cargo.toml b/Cargo.toml index ae9da019f..b7dfb8299 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -12,6 +12,7 @@ members = [ [workspace.dependencies] uniffi = "0.30.0" +rust-argon2 = { version = "3.0", default-features = false } [package] name = "devolutions-crypto" @@ -50,7 +51,7 @@ rand = "0.9" rand_08 = { package = "rand", version = "0.8" } thiserror = "2.0.12" typed-builder = "0.23.2" -rust-argon2 = { version = "3.0", default-features = false } +rust-argon2 = { workspace = true } uniffi = { workspace = true, optional = true } ed25519-dalek = { version = "2", features = [ "rand_core" ] } diff --git a/uniffi/devolutions-crypto-uniffi/Cargo.toml b/uniffi/devolutions-crypto-uniffi/Cargo.toml index d4dd844bb..265372395 100644 --- a/uniffi/devolutions-crypto-uniffi/Cargo.toml +++ b/uniffi/devolutions-crypto-uniffi/Cargo.toml @@ -9,4 +9,4 @@ crate-type = ["cdylib", "staticlib"] [dependencies] devolutions-crypto = { path = "../../", features = ["uniffi-support"] } uniffi = { workspace = true } -rust-argon2 = "3.0" +rust-argon2 = { workspace = true } From 97b17e891f66db702b275ebfb27d81bfe6b5d0f6 Mon Sep 17 00:00:00 2001 From: mmorrissette-devolutions Date: Thu, 23 Apr 2026 08:52:29 -0400 Subject: [PATCH 05/11] fix(uniffi): use canonical Argon2 defaults in builder Hardcoded fallbacks diverged from defaults::ITERATIONS=2 (was 3), which would silently change derived keys for callers relying on builder defaults. Route all fallbacks through argon2parameters_defaults so bindings stay in sync with the core crate. --- .../src/argon2parameters.rs | 37 +++++++------------ 1 file changed, 14 insertions(+), 23 deletions(-) diff --git a/uniffi/devolutions-crypto-uniffi/src/argon2parameters.rs b/uniffi/devolutions-crypto-uniffi/src/argon2parameters.rs index 5b4c948df..8e69df5ec 100644 --- a/uniffi/devolutions-crypto-uniffi/src/argon2parameters.rs +++ b/uniffi/devolutions-crypto-uniffi/src/argon2parameters.rs @@ -95,29 +95,20 @@ impl Argon2ParametersBuilder { let secret_key = self.secret_key.lock().unwrap().clone(); let salt = self.salt.lock().unwrap().clone(); - 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(); + use devolutions_crypto::argon2parameters_defaults as defaults; + + let inner = devolutions_crypto::Argon2Parameters::builder() + .length(length.unwrap_or(defaults::LENGTH)) + .lanes(lanes.unwrap_or(defaults::LANES)) + .memory(memory.unwrap_or(defaults::MEMORY)) + .iterations(iterations.unwrap_or(defaults::ITERATIONS)) + .variant(variant.map(|v| v.into()).unwrap_or(defaults::VARIANT)) + .version(version.map(|v| v.into()).unwrap_or(defaults::VERSION)) + .dc_version(dc_version.unwrap_or(defaults::DC_VERSION)) + .associated_data(associated_data.unwrap_or_default()) + .secret_key(secret_key.unwrap_or_default()) + .salt(salt.unwrap_or_else(|| defaults::salt().unwrap())) + .build(); Arc::new(Argon2Parameters { inner }) } From b7b6c8de964a9b2ca5b74d2e12e4885d499267f6 Mon Sep 17 00:00:00 2001 From: mmorrissette-devolutions Date: Thu, 23 Apr 2026 09:04:50 -0400 Subject: [PATCH 06/11] chore(swift): keep DevolutionsCryptoSwift sources dir with .gitkeep MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The autogenerated DevolutionsCryptoSwift.swift was removed, leaving the directory untracked. generate.sh copies the freshly generated bindings into Sources/DevolutionsCryptoSwift/ and Package.swift references that path as the target source — both break when the directory is absent after checkout. --- .../Sources/DevolutionsCryptoSwift/.gitkeep | 0 1 file changed, 0 insertions(+), 0 deletions(-) create mode 100644 wrappers/swift/DevolutionsCryptoSwift/Sources/DevolutionsCryptoSwift/.gitkeep diff --git a/wrappers/swift/DevolutionsCryptoSwift/Sources/DevolutionsCryptoSwift/.gitkeep b/wrappers/swift/DevolutionsCryptoSwift/Sources/DevolutionsCryptoSwift/.gitkeep new file mode 100644 index 000000000..e69de29bb From 7023aa99d94426af7b0602927a44141ef5a8ab00 Mon Sep 17 00:00:00 2001 From: mmorrissette-devolutions Date: Thu, 23 Apr 2026 09:07:58 -0400 Subject: [PATCH 07/11] chore(deps): bump uniffi to 0.31.1 --- Cargo.lock | 48 ++++++++++++++++++++++++------------------------ Cargo.toml | 2 +- 2 files changed, 25 insertions(+), 25 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index f23850974..0b2ecf0b7 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -111,9 +111,9 @@ dependencies = [ [[package]] name = "askama" -version = "0.13.1" +version = "0.14.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5d4744ed2eef2645831b441d8f5459689ade2ab27c854488fbab1fbe94fce1a7" +checksum = "f75363874b771be265f4ffe307ca705ef6f3baa19011c149da8674a87f1b75c4" dependencies = [ "askama_derive", "itoa", @@ -124,9 +124,9 @@ dependencies = [ [[package]] name = "askama_derive" -version = "0.13.1" +version = "0.14.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d661e0f57be36a5c14c48f78d09011e67e0cb618f269cca9f2fd8d15b68c46ac" +checksum = "129397200fe83088e8a68407a8e2b1f826cf0086b21ccdb866a722c8bcd3a94f" dependencies = [ "askama_parser", "basic-toml", @@ -141,9 +141,9 @@ dependencies = [ [[package]] name = "askama_parser" -version = "0.13.0" +version = "0.14.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cf315ce6524c857bb129ff794935cf6d42c82a6cff60526fe2a63593de4d0d4f" +checksum = "d6ab5630b3d5eaf232620167977f95eb51f3432fc76852328774afbd242d4358" dependencies = [ "memchr", "serde", @@ -1339,9 +1339,9 @@ dependencies = [ [[package]] name = "siphasher" -version = "0.3.11" +version = "1.0.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "38b58827f4464d87d377d175e90bf58eb00fd8716ff0a62f80356b5e61555d0d" +checksum = "b2aa850e253778c88a04c3d7323b043aeda9d3e30d5971937c1855769763678e" [[package]] name = "smawk" @@ -1553,9 +1553,9 @@ checksum = "9312f7c4f6ff9069b165498234ce8be658059c6728633667c526e27dc2cf1df5" [[package]] name = "uniffi" -version = "0.30.0" +version = "0.31.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c866f627c3f04c3df068b68bb2d725492caaa539dd313e2a9d26bb85b1a32f4e" +checksum = "dc5f2297ee5b893405bed1a6929faec4713a061df158ecf5198089f23910d470" dependencies = [ "anyhow", "camino", @@ -1584,9 +1584,9 @@ dependencies = [ [[package]] name = "uniffi_bindgen" -version = "0.30.0" +version = "0.31.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7c8ca600167641ebe7c8ba9254af40492dda3397c528cc3b2f511bd23e8541a5" +checksum = "8bc0c60a9607e7ab77a2ad47ec5530178015014839db25af7512447d2238016c" dependencies = [ "anyhow", "askama", @@ -1610,9 +1610,9 @@ dependencies = [ [[package]] name = "uniffi_core" -version = "0.30.0" +version = "0.31.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7e7a5a038ebffe8f4cf91416b154ef3c2468b18e828b7009e01b1b99938089f9" +checksum = "77baf5d539fe2e1ad6805e942dbc5dbdeb2b83eb5f2b3a6535d422ca4b02a12f" dependencies = [ "anyhow", "bytes", @@ -1622,9 +1622,9 @@ dependencies = [ [[package]] name = "uniffi_internal_macros" -version = "0.30.0" +version = "0.31.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e3c2a6f93e7b73726e2015696ece25ca0ac5a5f1cf8d6a7ab5214dd0a01d2edf" +checksum = "b4b42137524f4be6400fcaca9d02c1d4ecb6ad917e4013c0b93235526d8396e5" dependencies = [ "anyhow", "indexmap", @@ -1635,9 +1635,9 @@ dependencies = [ [[package]] name = "uniffi_macros" -version = "0.30.0" +version = "0.31.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "64c6309fc36c7992afc03bc0c5b059c656bccbef3f2a4bc362980017f8936141" +checksum = "d9273ec45330d8fe9a3701b7b983cea7a4e218503359831967cb95d26b873561" dependencies = [ "camino", "fs-err", @@ -1652,9 +1652,9 @@ dependencies = [ [[package]] name = "uniffi_meta" -version = "0.30.0" +version = "0.31.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0a138823392dba19b0aa494872689f97d0ee157de5852e2bec157ce6de9cdc22" +checksum = "431d2f443e7828a6c29d188de98b6771a6491ee98bba2d4372643bf93f988a18" dependencies = [ "anyhow", "siphasher", @@ -1664,9 +1664,9 @@ dependencies = [ [[package]] name = "uniffi_pipeline" -version = "0.30.0" +version = "0.31.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8c27c4b515d25f8e53cc918e238c39a79c3144a40eaf2e51c4a7958973422c29" +checksum = "761ef74f6175e15603d0424cc5f98854c5baccfe7bf4ccb08e5816f9ab8af689" dependencies = [ "anyhow", "heck", @@ -1677,9 +1677,9 @@ dependencies = [ [[package]] name = "uniffi_udl" -version = "0.30.0" +version = "0.31.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d0adacdd848aeed7af4f5af7d2f621d5e82531325d405e29463482becfdeafca" +checksum = "68773ec0e1c067b6505a73bbf6a5782f31a7f9209333a0df97b87565c46bf370" dependencies = [ "anyhow", "textwrap", diff --git a/Cargo.toml b/Cargo.toml index b7dfb8299..1f2097884 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -11,7 +11,7 @@ members = [ ] [workspace.dependencies] -uniffi = "0.30.0" +uniffi = "0.31.1" rust-argon2 = { version = "3.0", default-features = false } [package] From c0a03825055a9c4a1f31bbb492c4ee1d3befccda Mon Sep 17 00:00:00 2001 From: mmorrissette-devolutions Date: Thu, 23 Apr 2026 09:28:03 -0400 Subject: [PATCH 08/11] style: remove added comments in uniffi lib.rs --- uniffi/devolutions-crypto-uniffi/src/lib.rs | 2 -- 1 file changed, 2 deletions(-) diff --git a/uniffi/devolutions-crypto-uniffi/src/lib.rs b/uniffi/devolutions-crypto-uniffi/src/lib.rs index 5adbf04e2..344aa00c9 100644 --- a/uniffi/devolutions-crypto-uniffi/src/lib.rs +++ b/uniffi/devolutions-crypto-uniffi/src/lib.rs @@ -16,7 +16,6 @@ pub use signature::*; pub use signing_key::*; pub use utils::*; -// Re-export types from devolutions_crypto pub use devolutions_crypto::CiphertextVersion; pub use devolutions_crypto::DataType; pub use devolutions_crypto::Error as DevolutionsCryptoError; @@ -28,7 +27,6 @@ pub use devolutions_crypto::SigningKeyVersion; pub use devolutions_crypto::Result; -// Wrapper types for Argon2 enums from rust-argon2 crate #[derive(uniffi::Enum, Clone, Copy, Debug, PartialEq, Eq)] pub enum Argon2Version { Version10, From 9ca6af1b1442bba4e4db285b5409edea9eb8403f Mon Sep 17 00:00:00 2001 From: mmorrissette-devolutions Date: Thu, 23 Apr 2026 11:12:15 -0400 Subject: [PATCH 09/11] fix(uniffi): collapse to single namespace via remote types MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The previous setup had two scaffolding calls — one in the core crate (emitting devolutions_crypto.*) and one in the wrapper crate (emitting devolutions_crypto_uniffi.*). Swift generate.sh only copied the former, silently dropping all wrapper Object types (Argon2Parameters, Ciphertext, SigningKeyPair, ...) from the Swift package. Revert all uniffi derives and scaffolding from the core crate, then re-declare the shared enums and Error in the wrapper crate via #[uniffi::remote(...)]. Single scaffolding, single namespace (devolutions_crypto_uniffi), all types in one module. Rename the Swift systemLibrary target directory, modulemaps, and generate.sh filename references to match. --- Cargo.lock | 1 - Cargo.toml | 2 - src/enums.rs | 7 -- src/error.rs | 2 - src/lib.rs | 3 - uniffi/devolutions-crypto-uniffi/Cargo.toml | 2 +- uniffi/devolutions-crypto-uniffi/src/lib.rs | 86 ++++++++++++++++--- .../DevolutionsCryptoSwift/Package.swift | 6 +- .../devolutions_cryptoFFI/framework.modulemap | 6 -- .../devolutions_cryptoFFI/module.modulemap | 4 - .../framework.modulemap | 6 ++ .../module.modulemap | 4 + wrappers/swift/generate.sh | 24 +++--- 13 files changed, 102 insertions(+), 51 deletions(-) delete mode 100644 wrappers/swift/DevolutionsCryptoSwift/Sources/devolutions_cryptoFFI/framework.modulemap delete mode 100644 wrappers/swift/DevolutionsCryptoSwift/Sources/devolutions_cryptoFFI/module.modulemap create mode 100644 wrappers/swift/DevolutionsCryptoSwift/Sources/devolutions_crypto_uniffiFFI/framework.modulemap create mode 100644 wrappers/swift/DevolutionsCryptoSwift/Sources/devolutions_crypto_uniffiFFI/module.modulemap diff --git a/Cargo.lock b/Cargo.lock index 0b2ecf0b7..015b4dc39 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -519,7 +519,6 @@ dependencies = [ "subtle", "thiserror", "typed-builder", - "uniffi", "wasm-bindgen", "wasm-bindgen-test", "x25519-dalek", diff --git a/Cargo.toml b/Cargo.toml index 1f2097884..26de8e326 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -52,7 +52,6 @@ rand_08 = { package = "rand", version = "0.8" } thiserror = "2.0.12" typed-builder = "0.23.2" rust-argon2 = { workspace = true } -uniffi = { workspace = true, optional = true } ed25519-dalek = { version = "2", features = [ "rand_core" ] } x25519-dalek = { version = "2", features = [ "static_secrets" ] } @@ -78,7 +77,6 @@ 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 703dee101..fd4ceb08d 100644 --- a/src/enums.rs +++ b/src/enums.rs @@ -10,7 +10,6 @@ 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)] @@ -37,7 +36,6 @@ 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)] @@ -68,7 +66,6 @@ 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)] @@ -83,7 +80,6 @@ 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)] @@ -97,7 +93,6 @@ 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)] @@ -112,7 +107,6 @@ 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)] @@ -127,7 +121,6 @@ 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 cb919a1d1..99a8d5ee4 100644 --- a/src/error.rs +++ b/src/error.rs @@ -22,8 +22,6 @@ 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 24ba62bed..b383807ea 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -242,6 +242,3 @@ pub const DEFAULT_PBKDF2_ITERATIONS: u32 = 600000; #[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 265372395..0d1b3ea17 100644 --- a/uniffi/devolutions-crypto-uniffi/Cargo.toml +++ b/uniffi/devolutions-crypto-uniffi/Cargo.toml @@ -7,6 +7,6 @@ version.workspace = true crate-type = ["cdylib", "staticlib"] [dependencies] -devolutions-crypto = { path = "../../", features = ["uniffi-support"] } +devolutions-crypto = { path = "../../" } uniffi = { workspace = true } rust-argon2 = { workspace = true } diff --git a/uniffi/devolutions-crypto-uniffi/src/lib.rs b/uniffi/devolutions-crypto-uniffi/src/lib.rs index 344aa00c9..82d03d4ea 100644 --- a/uniffi/devolutions-crypto-uniffi/src/lib.rs +++ b/uniffi/devolutions-crypto-uniffi/src/lib.rs @@ -16,16 +16,82 @@ pub use signature::*; pub use signing_key::*; pub use utils::*; -pub use devolutions_crypto::CiphertextVersion; -pub use devolutions_crypto::DataType; -pub use devolutions_crypto::Error as DevolutionsCryptoError; -pub use devolutions_crypto::KeyVersion; -pub use devolutions_crypto::PasswordHashVersion; -pub use devolutions_crypto::SecretSharingVersion; -pub use devolutions_crypto::SignatureVersion; -pub use devolutions_crypto::SigningKeyVersion; - -pub use devolutions_crypto::Result; +pub use devolutions_crypto::{ + CiphertextVersion, DataType, Error as DevolutionsCryptoError, KeyVersion, PasswordHashVersion, + Result, SecretSharingVersion, SignatureVersion, SigningKeyVersion, +}; + +#[uniffi::remote(Enum)] +pub enum DataType { + None, + Key, + Ciphertext, + PasswordHash, + Share, + SigningKey, + Signature, + OnlineCiphertext, +} + +#[uniffi::remote(Enum)] +pub enum CiphertextVersion { + Latest, + V1, + V2, +} + +#[uniffi::remote(Enum)] +pub enum KeyVersion { + Latest, + V1, +} + +#[uniffi::remote(Enum)] +pub enum PasswordHashVersion { + Latest, + V1, +} + +#[uniffi::remote(Enum)] +pub enum SecretSharingVersion { + Latest, + V1, +} + +#[uniffi::remote(Enum)] +pub enum SignatureVersion { + Latest, + V1, +} + +#[uniffi::remote(Enum)] +pub enum SigningKeyVersion { + Latest, + V1, +} + +#[uniffi::remote(Error)] +#[uniffi(flat_error)] +pub enum DevolutionsCryptoError { + InvalidLength, + InvalidKeyLength, + InvalidOutputLength, + InvalidSignature, + InvalidMac, + InvalidDataType, + UnknownType, + UnknownSubtype, + UnknownVersion, + InvalidData, + NullPointer, + CryptoError, + RandomError, + IoError, + NotEnoughShares, + InconsistentVersion, + InvalidChunkLength, + PoisonedMutex, +} #[derive(uniffi::Enum, Clone, Copy, Debug, PartialEq, Eq)] pub enum Argon2Version { diff --git a/wrappers/swift/DevolutionsCryptoSwift/Package.swift b/wrappers/swift/DevolutionsCryptoSwift/Package.swift index c3aa2d3fd..f03c03906 100644 --- a/wrappers/swift/DevolutionsCryptoSwift/Package.swift +++ b/wrappers/swift/DevolutionsCryptoSwift/Package.swift @@ -17,8 +17,8 @@ let package = Package( ], targets: [ .systemLibrary( - name: "devolutions_cryptoFFI", - path: "Sources/devolutions_cryptoFFI" + name: "devolutions_crypto_uniffiFFI", + path: "Sources/devolutions_crypto_uniffiFFI" ), .binaryTarget( name: "libDevolutionsCrypto", @@ -27,7 +27,7 @@ let package = Package( .target( name: "DevolutionsCryptoSwift", dependencies: [ - "devolutions_cryptoFFI", + "devolutions_crypto_uniffiFFI", "libDevolutionsCrypto" ], path: "Sources/DevolutionsCryptoSwift" diff --git a/wrappers/swift/DevolutionsCryptoSwift/Sources/devolutions_cryptoFFI/framework.modulemap b/wrappers/swift/DevolutionsCryptoSwift/Sources/devolutions_cryptoFFI/framework.modulemap deleted file mode 100644 index 51a9c59bf..000000000 --- a/wrappers/swift/DevolutionsCryptoSwift/Sources/devolutions_cryptoFFI/framework.modulemap +++ /dev/null @@ -1,6 +0,0 @@ -framework module devolutions_cryptoFFI { - umbrella header "devolutions_cryptoFFI.h" - - export * - module * { export * } -} diff --git a/wrappers/swift/DevolutionsCryptoSwift/Sources/devolutions_cryptoFFI/module.modulemap b/wrappers/swift/DevolutionsCryptoSwift/Sources/devolutions_cryptoFFI/module.modulemap deleted file mode 100644 index bb0f390eb..000000000 --- a/wrappers/swift/DevolutionsCryptoSwift/Sources/devolutions_cryptoFFI/module.modulemap +++ /dev/null @@ -1,4 +0,0 @@ -module devolutions_cryptoFFI [system] { - header "devolutions_cryptoFFI.h" - export * -} diff --git a/wrappers/swift/DevolutionsCryptoSwift/Sources/devolutions_crypto_uniffiFFI/framework.modulemap b/wrappers/swift/DevolutionsCryptoSwift/Sources/devolutions_crypto_uniffiFFI/framework.modulemap new file mode 100644 index 000000000..2fb4d137c --- /dev/null +++ b/wrappers/swift/DevolutionsCryptoSwift/Sources/devolutions_crypto_uniffiFFI/framework.modulemap @@ -0,0 +1,6 @@ +framework module devolutions_crypto_uniffiFFI { + umbrella header "devolutions_crypto_uniffiFFI.h" + + export * + module * { export * } +} diff --git a/wrappers/swift/DevolutionsCryptoSwift/Sources/devolutions_crypto_uniffiFFI/module.modulemap b/wrappers/swift/DevolutionsCryptoSwift/Sources/devolutions_crypto_uniffiFFI/module.modulemap new file mode 100644 index 000000000..9d815698e --- /dev/null +++ b/wrappers/swift/DevolutionsCryptoSwift/Sources/devolutions_crypto_uniffiFFI/module.modulemap @@ -0,0 +1,4 @@ +module devolutions_crypto_uniffiFFI [system] { + header "devolutions_crypto_uniffiFFI.h" + export * +} diff --git a/wrappers/swift/generate.sh b/wrappers/swift/generate.sh index ab9bbf13b..73d5ef35e 100755 --- a/wrappers/swift/generate.sh +++ b/wrappers/swift/generate.sh @@ -53,26 +53,26 @@ mkdir ./framework-simulator/lib$LIBNAME.framework/Headers mkdir ./framework-ios/lib$LIBNAME.framework/Headers mkdir ./framework-macos/lib$LIBNAME.framework/Headers -cp ./bindings/devolutions_cryptoFFI.h ./framework-simulator/lib$LIBNAME.framework/Headers -cp ./bindings/devolutions_cryptoFFI.h ./framework-ios/lib$LIBNAME.framework/Headers -cp ./bindings/devolutions_cryptoFFI.h ./framework-macos/lib$LIBNAME.framework/Headers -cp ./bindings/devolutions_cryptoFFI.h ./DevolutionsCryptoSwift/Sources/devolutions_cryptoFFI/ +cp ./bindings/devolutions_crypto_uniffiFFI.h ./framework-simulator/lib$LIBNAME.framework/Headers +cp ./bindings/devolutions_crypto_uniffiFFI.h ./framework-ios/lib$LIBNAME.framework/Headers +cp ./bindings/devolutions_crypto_uniffiFFI.h ./framework-macos/lib$LIBNAME.framework/Headers +cp ./bindings/devolutions_crypto_uniffiFFI.h ./DevolutionsCryptoSwift/Sources/devolutions_crypto_uniffiFFI/ mkdir ./framework-simulator/lib$LIBNAME.framework/Modules mkdir ./framework-ios/lib$LIBNAME.framework/Modules mkdir ./framework-macos/lib$LIBNAME.framework/Modules -cp ./DevolutionsCryptoSwift/Sources/devolutions_cryptoFFI/framework.modulemap ./framework-simulator/lib$LIBNAME.framework/Modules/module.modulemap -cp ./DevolutionsCryptoSwift/Sources/devolutions_cryptoFFI/framework.modulemap ./framework-ios/lib$LIBNAME.framework/Modules/module.modulemap -cp ./DevolutionsCryptoSwift/Sources/devolutions_cryptoFFI/framework.modulemap ./framework-macos/lib$LIBNAME.framework/Modules/module.modulemap +cp ./DevolutionsCryptoSwift/Sources/devolutions_crypto_uniffiFFI/framework.modulemap ./framework-simulator/lib$LIBNAME.framework/Modules/module.modulemap +cp ./DevolutionsCryptoSwift/Sources/devolutions_crypto_uniffiFFI/framework.modulemap ./framework-ios/lib$LIBNAME.framework/Modules/module.modulemap +cp ./DevolutionsCryptoSwift/Sources/devolutions_crypto_uniffiFFI/framework.modulemap ./framework-macos/lib$LIBNAME.framework/Modules/module.modulemap mkdir ./framework-simulator/lib$LIBNAME.framework/Sources mkdir ./framework-ios/lib$LIBNAME.framework/Sources mkdir ./framework-macos/lib$LIBNAME.framework/Sources -cp ./bindings/devolutions_crypto.swift ./framework-simulator/lib$LIBNAME.framework/Sources -cp ./bindings/devolutions_crypto.swift ./framework-ios/lib$LIBNAME.framework/Sources -cp ./bindings/devolutions_crypto.swift ./framework-macos/lib$LIBNAME.framework/Sources +cp ./bindings/devolutions_crypto_uniffi.swift ./framework-simulator/lib$LIBNAME.framework/Sources +cp ./bindings/devolutions_crypto_uniffi.swift ./framework-ios/lib$LIBNAME.framework/Sources +cp ./bindings/devolutions_crypto_uniffi.swift ./framework-macos/lib$LIBNAME.framework/Sources mv "./bindings/ios-simulator/lib$LIBNAME.dylib" ./framework-simulator/lib$LIBNAME.framework/lib$LIBNAME mv "../../target/aarch64-apple-ios/release/lib$LIBNAMEOUTPUT.dylib" ./framework-ios/lib$LIBNAME.framework/lib$LIBNAME @@ -110,7 +110,7 @@ ditto -c -k --sequesterRsrc --keepParent "$XCFRAMEWORK_FOLDER" "$XCFRAMEWORK_FOL swift package compute-checksum "$XCFRAMEWORK_FOLDER.zip" # Move swift file to package -cp "./bindings/devolutions_crypto.swift" ./DevolutionsCryptoSwift/Sources/DevolutionsCryptoSwift/DevolutionsCryptoSwift.swift +cp "./bindings/devolutions_crypto_uniffi.swift" ./DevolutionsCryptoSwift/Sources/DevolutionsCryptoSwift/DevolutionsCryptoSwift.swift # Tests cd ./DevolutionsCryptoSwift @@ -124,7 +124,7 @@ mkdir package cp -R $XCFRAMEWORK_FOLDER ./package cp -R ./DevolutionsCryptoSwift/Sources ./package cp -R ./DevolutionsCryptoSwift/Tests ./package -rm ./package/Sources/devolutions_cryptoFFI/framework.modulemap +rm ./package/Sources/devolutions_crypto_uniffiFFI/framework.modulemap cp ./DevolutionsCryptoSwift/Package.swift ./package cp ./DevolutionsCryptoSwift.podspec ./package From 665eed5130abccf389e9cbe576fba1db43fab548 Mon Sep 17 00:00:00 2001 From: mmorrissette-devolutions Date: Thu, 23 Apr 2026 11:28:26 -0400 Subject: [PATCH 10/11] fix(kotlin): drop stale uniffi.devolutions_crypto imports in tests The imports referenced a package that does not exist under the current bindgen config (uniffi.toml sets package_name = org.devolutions.crypto). The tests live in that same package, so no import is needed: - DataType resolves locally - bare Exception resolves to kotlin.Exception, which still catches DevolutionsCryptoException (the generated flat error). --- .../lib/src/test/kotlin/org/devolutions/crypto/AsymmetricTest.kt | 1 - .../src/test/kotlin/org/devolutions/crypto/SecretSharingTest.kt | 1 - .../lib/src/test/kotlin/org/devolutions/crypto/SymmetricTest.kt | 1 - .../lib/src/test/kotlin/org/devolutions/crypto/UtilsTest.kt | 1 - 4 files changed, 4 deletions(-) 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 ba04522c0..482cb3464 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,7 +7,6 @@ import kotlin.test.Test import kotlin.test.assertContentEquals import kotlin.test.assertEquals import kotlin.test.assertFailsWith -import uniffi.devolutions_crypto.Exception class AsymmetricTest { @Test 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 0edcb8ecb..c6ef21740 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,7 +7,6 @@ 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 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 8c5c95e4f..996f5a802 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,7 +6,6 @@ package org.devolutions.crypto import kotlin.test.Test import kotlin.test.assertContentEquals import kotlin.test.assertFailsWith -import uniffi.devolutions_crypto.Exception class SymmetricTest { @Test 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 1685fd663..c545844f7 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,7 +6,6 @@ package org.devolutions.crypto import kotlin.test.Test import kotlin.test.assertContentEquals import kotlin.test.assertEquals -import uniffi.devolutions_crypto.DataType class UtilsTest { @Test From e1c337e082a28fa8b0a84269205e44e508fd5575 Mon Sep 17 00:00:00 2001 From: mmorrissette-devolutions Date: Thu, 23 Apr 2026 12:55:31 -0400 Subject: [PATCH 11/11] chore(uniffi): drop unused uniffi-builder-macro crate The builder macro was replaced by hand-written Arc> builders in the wrapper crate, leaving the macro crate unreferenced. --- Cargo.lock | 8 - Cargo.toml | 1 - .../uniffi-builder-macro/Cargo.toml | 12 -- .../uniffi-builder-macro/src/lib.rs | 146 ------------------ 4 files changed, 167 deletions(-) delete mode 100644 uniffi/devolutions-crypto-uniffi/uniffi-builder-macro/Cargo.toml delete mode 100644 uniffi/devolutions-crypto-uniffi/uniffi-builder-macro/src/lib.rs diff --git a/Cargo.lock b/Cargo.lock index 015b4dc39..7e63036bb 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1573,14 +1573,6 @@ dependencies = [ "uniffi", ] -[[package]] -name = "uniffi-builder-macro" -version = "0.1.0" -dependencies = [ - "quote", - "syn 2.0.110", -] - [[package]] name = "uniffi_bindgen" version = "0.31.1" diff --git a/Cargo.toml b/Cargo.toml index 26de8e326..efc26817c 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -7,7 +7,6 @@ members = [ "python", "uniffi/uniffi-bindgen", "uniffi/devolutions-crypto-uniffi", - "uniffi/devolutions-crypto-uniffi/uniffi-builder-macro", ] [workspace.dependencies] diff --git a/uniffi/devolutions-crypto-uniffi/uniffi-builder-macro/Cargo.toml b/uniffi/devolutions-crypto-uniffi/uniffi-builder-macro/Cargo.toml deleted file mode 100644 index e291025db..000000000 --- a/uniffi/devolutions-crypto-uniffi/uniffi-builder-macro/Cargo.toml +++ /dev/null @@ -1,12 +0,0 @@ -[package] -name = "uniffi-builder-macro" -version = "0.1.0" -edition = "2021" - -[lib] -path = "src/lib.rs" -proc-macro = true - -[dependencies] -quote = "1.0.37" -syn = { version = "2.0.79", features = ["full", "extra-traits"] } diff --git a/uniffi/devolutions-crypto-uniffi/uniffi-builder-macro/src/lib.rs b/uniffi/devolutions-crypto-uniffi/uniffi-builder-macro/src/lib.rs deleted file mode 100644 index 4a32cd5d2..000000000 --- a/uniffi/devolutions-crypto-uniffi/uniffi-builder-macro/src/lib.rs +++ /dev/null @@ -1,146 +0,0 @@ -use proc_macro::TokenStream; -use syn::spanned::Spanned; - -struct UniffiBuilderMacroInput { - output_struct: syn::Ident, - _comma: syn::Token![,], - defaults: syn::ExprPath, -} - -impl syn::parse::Parse for UniffiBuilderMacroInput { - fn parse(input: syn::parse::ParseStream) -> syn::Result { - Ok(Self { - output_struct: input.parse()?, - _comma: input.parse()?, - defaults: input.parse()?, - }) - } -} - -#[proc_macro_attribute] -#[allow(non_snake_case)] -pub fn UniffiBuilder(args: TokenStream, tokens: TokenStream) -> TokenStream { - // Get the name of the struct to output to - let args: UniffiBuilderMacroInput = match syn::parse(args) { - Ok(args) => args, - Err(e) => return e.to_compile_error().into(), - }; - - let output_struct_name = args.output_struct; - let defaults_module = args.defaults; - - // Parse the struct - let mut tree: syn::ItemStruct = match syn::parse(tokens) { - Ok(t) => t, - Err(e) => return e.to_compile_error().into(), - }; - - // Get the name of the struct - let struct_name = tree.ident.clone(); - - // Get the field and type of each fields - let ((field_names, field_types), field_attributes): ( - (Vec, Vec), - Vec>, - ) = tree - .fields - .iter() - .map(|f| { - let attribute = f - .attrs - .iter() - .find(|a| a.path().is_ident("builder_default")); - let attribute: Option = attribute.cloned(); - ((f.ident.clone().unwrap(), f.ty.clone()), attribute) - }) - .collect(); - - // Strip the fields from the fields that have custom default - let (field_names_for_default, field_default): (Vec, Vec) = tree - .fields - .iter() - .zip(field_attributes.iter()) - .map(|(f, attr)| { - let ident = f.ident.clone().unwrap(); - - let default: syn::Expr = if let Some(attr) = attr { - if let syn::Meta::NameValue(attr) = attr.meta.clone() { - let val = attr.value; - syn::parse_quote! { std::sync::Mutex::new({#val}) } - } else { - syn::Expr::Verbatim( - syn::Error::new( - attr.span(), - "The format for the attribute should be #[builder_default = code()]", - ) - .to_compile_error(), - ) - } - } else { - // Get the uppercased name of the field to get the corresponding default - let uppercased_ident: syn::Ident = - syn::parse_str(&ident.to_string().to_uppercase()).unwrap(); - syn::parse_quote! { std::sync::Mutex::new(#defaults_module::#uppercased_ident) } - }; - - (ident, default) - }) - .collect(); - - // Add mutex to the types - tree.fields.iter_mut().for_each(|field| { - let original_type = field.ty.clone(); - - // Strip the default attributes - field - .attrs - .retain(|a| !a.path().is_ident("builder_default")); - - field.ty = syn::parse_quote! { std::sync::Mutex<#original_type> }; - }); - - quote::quote! { - #tree - - impl Clone for #struct_name { - fn clone(&self) -> Self { - Self { - #(#field_names: std::sync::Mutex::new(self.#field_names.lock().unwrap().clone()),)* - } - } - } - - impl Default for #struct_name { - fn default() -> Self { - Self { - #(#field_names_for_default: #field_default,)* - } - } - } - - impl #struct_name { - pub fn new() -> Self { - Default::default() - } - - #( - pub fn #field_names(self: std::sync::Arc, value: #field_types) -> std::sync::Arc { - *self.#field_names.lock().unwrap() = value; - self - } - )* - - pub fn build(self: std::sync::Arc) -> std::sync::Arc<#output_struct_name> { - let builder = std::sync::Arc::<#struct_name>::unwrap_or_clone(self); - - #output_struct_name( - #output_struct_name::get_inner_builder() - #(.#field_names(builder.#field_names.into_inner().unwrap()))* - .build(), - ) - .into() - } - } - } - .into() -}