π End-to-end encrypted cloud for everything.
Dart 2faandroidauthye2eeencryptionend-to-end-encryptionfluttergolanggoogle-photosgoogle-photos-alternativeiosopensourcephotosprivacyprivacy-toolstypescriptzero-knowledge
Add UniFFI cast binding crate
Manav Rathi591cc9794c99
diff --git a/rust/Cargo.lock b/rust/Cargo.lockindex 074a08b5d5..9bbe934e1b 100644--- a/rust/Cargo.lock+++ b/rust/Cargo.lock@@ -2296,6 +2296,15 @@ dependencies = ["zeroize",]+[[package]]+name = "ente-cast-uniffi"+version = "0.0.0"+dependencies = [+ "ente-core",+ "thiserror 2.0.18",+ "uniffi",+]+[[package]]name = "ente-contacts"version = "0.0.0"diff --git a/rust/Cargo.toml b/rust/Cargo.tomlindex 8b88a310fe..6353b134d4 100644--- a/rust/Cargo.toml+++ b/rust/Cargo.toml@@ -7,6 +7,7 @@ members = ["bindings/ffi/crypto","bindings/frb/ente-rust","bindings/frb/photos",+ "bindings/uniffi/cast","bindings/uniffi/ensu","bindings/wasm/ente-wasm","bindings/wasm/core",diff --git a/rust/bindings/uniffi/cast/Cargo.toml b/rust/bindings/uniffi/cast/Cargo.tomlnew file mode 100644index 0000000000..f4cf65119b--- /dev/null+++ b/rust/bindings/uniffi/cast/Cargo.toml@@ -0,0 +1,12 @@+[package]+name = "ente-cast-uniffi"+edition = "2024"++[lib]+name = "cast"+crate-type = ["staticlib", "cdylib"]++[dependencies]+ente-core.workspace = true+thiserror = "2"+uniffi = { version = "0.31.0" }diff --git a/rust/bindings/uniffi/cast/src/lib.rs b/rust/bindings/uniffi/cast/src/lib.rsnew file mode 100644index 0000000000..32ef0685a8--- /dev/null+++ b/rust/bindings/uniffi/cast/src/lib.rs@@ -0,0 +1,73 @@+uniffi::setup_scaffolding!("cast");++use ente_core::crypto;+use thiserror::Error;++#[derive(Debug, Error, uniffi::Error)]+pub enum CastError {+ #[error("{0}")]+ Message(String),+}++impl From<crypto::CryptoError> for CastError {+ fn from(err: crypto::CryptoError) -> Self {+ CastError::Message(err.to_string())+ }+}++#[derive(Debug, Clone, uniffi::Record)]+pub struct CastKeyPair {+ pub public_key: Vec<u8>,+ pub private_key: Vec<u8>,+}++#[uniffi::export]+pub fn generate_key_pair() -> CastKeyPair {+ let private_key = crypto::SecretKey::generate();+ let public_key = private_key.public_key();+ CastKeyPair {+ public_key: public_key.as_bytes().to_vec(),+ private_key: private_key.as_bytes().to_vec(),+ }+}++#[uniffi::export]+pub fn open_sealed_box(+ ciphertext: Vec<u8>,+ public_key: Vec<u8>,+ private_key: Vec<u8>,+) -> Result<Vec<u8>, CastError> {+ let public_key = crypto::PublicKey::try_from_slice(&public_key)?;+ let private_key = crypto::SecretKey::try_from_slice(&private_key)?;+ Ok(crypto::sealed::open(+ &ciphertext,+ &public_key,+ &private_key,+ )?)+}++#[uniffi::export]+pub fn open_secret_box(+ ciphertext: Vec<u8>,+ nonce: Vec<u8>,+ key: Vec<u8>,+) -> Result<Vec<u8>, CastError> {+ let nonce = crypto::Nonce::try_from_slice(&nonce)?;+ let key = crypto::Key::try_from_slice(&key)?;+ Ok(crypto::secretbox::decrypt(&ciphertext, &nonce, &key)?)+}++#[uniffi::export]+pub fn decrypt_secret_stream(+ encrypted_data: Vec<u8>,+ header: Vec<u8>,+ key: Vec<u8>,+) -> Result<Vec<u8>, CastError> {+ let header = crypto::Header::try_from_slice(&header)?;+ let key = crypto::Key::try_from_slice(&key)?;+ Ok(crypto::stream::decrypt_file_data(+ &encrypted_data,+ &header,+ &key,+ )?)+}diff --git a/rust/bindings/uniffi/cast/uniffi.toml b/rust/bindings/uniffi/cast/uniffi.tomlnew file mode 100644index 0000000000..efafe96454--- /dev/null+++ b/rust/bindings/uniffi/cast/uniffi.toml@@ -0,0 +1,8 @@+[bindings.swift]+link_frameworks = ["Foundation"]++[bindings.kotlin]+package_name = "io.ente.cast.bindings"+cdylib_name = "cast"+android = true+kotlin_target_version = "1.9.0"