π End-to-end encrypted cloud for everything.
Dart 2faandroidauthye2eeencryptionend-to-end-encryptionfluttergolanggoogle-photosgoogle-photos-alternativeiosopensourcephotosprivacyprivacy-toolstypescriptzero-knowledge
Merge branch 'rust-crypto' into rust-core-impl
Prateek Sunal58c835f2b8ed
diff --cc rust/README.mdindex 8901d6c914,7ecf3d2ced..9bd0e3e3b0--- a/rust/README.md+++ b/rust/README.md@@@ -1,41 -1,173 +1,70 @@@# Rust in Ente- This directory hosts Rust crates used across Ente clients.+ ```+ βββββββββββββββββββββββββββββββββββββββββ+ β rust/core/ β+ β (ente-core crate) β+ β β+ β Pure Rust - NO FFI annotations β+ β Stateless business logic β+ β Fully testable with cargo test β+ βββββββββββββββββββββββββββββββββββββββββ+ β+ ββββββββββββββββββββββββββββββΌβββββββββββββββββββββββββββββ+ β β β+ βΌ βΌ βΌ+ βββββββββββββββββββββββββββββ βββββββββββββββββββββββββββββ ββββββββββββββββββββββββββ+ β mobile/packages/rust/ β β web/packages/wasm/ β β rust/cli/ β+ β (ente_rust crate) β β (ente-wasm crate) β β β+ β β β β β CLI binary, depends β+ β Shared #[frb] wrappers β β #[wasm_bindgen] wrappers β β on ente-core β+ β for all mobile apps β β for all web apps β β β+ βββββββββββββββββββββββββββββ βββββββββββββββββββββββββββββ ββββββββββββββββββββββββββ+ β β β+ β ββββββββββββββββ β+ βΌ βΌ βΌ+ βββββββββββββββββββ ββββββββββββββ βββββββββββββββββββββββββββββ+ β Photos App β β Other apps β β Web Apps β+ β β β (Auth ...) β β (Photos, Auth, etc.) β+ βββββββββββββββββββ ββββββββββββββ βββββββββββββββββββββββββββββ+ β²+ β+ βββββββββββββββββββββββββββββ+ β mobile/apps/photos/rust/ β+ β (ente_photos_rust crate) β+ β β+ β App-specific #[frb]: β+ β usearch, ML, etc. β+ βββββββββββββββββββββββββββββ+ ```- ## Crates+ ## Contents (this repo)- ### `rust/core/` (ente-core)-- `rust/core/` (`ente-core`) - shared, pure Rust code used by clients (crypto primitives, plus small HTTP/URL helpers).++- `rust/core/` (`ente-core`) - shared, pure Rust code used by clients (crypto + auth, plus small HTTP/URL helpers).+ - `rust/cli/` - Rust CLI (work-in-progress).- Pure Rust shared logic (crypto + auth) that is wire-compatible with the existing JS/Dart- implementations.+ ## Directory Structure- - Source: `rust/core/src/`- - Docs:- - `rust/core/docs/crypto.md`- - `rust/core/docs/auth.md`+ ```+ rust/+ βββ cli/ # CLI package+ β βββ src/-β β βββ main.rs-β βββ Cargo.toml-β βββ Cargo.lock-β++β βββ Cargo.toml+ βββ core/ # Pure Rust business logic+ βββ src/- β βββ lib.rs- β βββ urls.rs++ βββ docs/+ βββ Cargo.toml # crate name: ente-core--web/packages/wasm/ # WASM bindings (lives in web workspace)-βββ src/-β βββ lib.rs # #[wasm_bindgen] wrappers around ente-core-βββ Cargo.toml # crate name: ente-wasm-βββ package.json # includes wasm-pack as devDependency-βββ pkg/ # generated output (gitignored)--mobile/packages/rust/ # Shared FRB bindings for all mobile apps-βββ rust/-β βββ src/-β β βββ api/ # #[frb] wrappers around ente-core-β βββ Cargo.toml # crate name: ente_rust-βββ lib/ # Generated Dart bindings-βββ pubspec.yaml # Flutter plugin package--mobile/apps/photos/rust/ # Photos app-specific FRB bindings-βββ src/-β βββ lib.rs-β βββ api/ # #[frb] app-specific code (usearch, ML)-β βββ *.rs-βββ Cargo.toml # crate name: ente_photos_rust+ ```-**Crates:**--- `ente-core` - shared business logic (pure Rust, no FFI)-- `ente-wasm` - wasm-bindgen wrappers for web-- `ente_rust` - shared FRB wrappers for mobile (Dart class: `EnteRust`)-- `ente_photos_rust` - Photos app-specific FRB (Dart class: `EntePhotosRust`)--## Tooling--### [wasm-bindgen](https://github.com/wasm-bindgen/wasm-bindgen)--A Rust library that provides the `#[wasm_bindgen]` attribute macro. When you annotate a function with `#[wasm_bindgen]`, it:--1. Marks the function for export to JavaScript-2. Handles type conversions between Rust and JS (e.g., `String` β JS string, `i64` β `BigInt`)-3. Generates metadata that the wasm-bindgen CLI uses to create JS/TS glue code--The library itself is lightweight - just macros and runtime types.--### [wasm-pack](https://github.com/drager/wasm-pack)--A CLI tool that orchestrates the WASM build process:--1. Runs `cargo build --target wasm32-unknown-unknown`-2. Invokes `wasm-bindgen` CLI to generate JS/TS bindings from the compiled WASM-3. Outputs everything to a `pkg/` directory ready for npm/bundlers--wasm-pack is installed via npm as a devDependency, so `yarn install` handles it.--### [Flutter Rust Bridge (FRB)](https://github.com/fzyzcjy/flutter_rust_bridge)--Used for Flutter integration. FRB is used on two crates:--- **`ente_rust`** (`mobile/packages/rust/`) - Shared wrappers around `ente-core`, used by multiple mobile apps (Photos, Auth, etc.)-- **`ente_photos_rust`** (`mobile/apps/photos/rust/`) - Photos app-specific functionality (usearch, ML)--Both depend on `ente-core` and use `#[frb]` annotations to generate Dart bindings.-## Development-### Commands-**ente-core (rust/core/):**```sh-cargo fmt # format-cargo clippy # lint-cargo build # build-cargo test # test-```--**ente-wasm (web/packages/wasm/):**--```sh-yarn install # installs wasm-pack-yarn build # runs wasm-pack build --target bundler-```--Or from web/ root:--```sh-yarn build:wasm # builds the WASM package+cargo fmt+cargo clippy+cargo build+cargo test```- ## Integrations-> [!TIP]->-> For active Rust development, use watch mode in a separate terminal:->-> ```sh-> cargo install cargo-watch-> cd web/-> cargo watch -w ../rust/core -w packages/wasm/src -s "yarn build:wasm"-> ```--- - Web (wasm-bindgen): `web/packages/wasm/` wraps `ente-core` for web apps.- - Mobile (FRB): `mobile/packages/rust/` wraps `ente-core` for Flutter apps.-**ente_rust (mobile/packages/rust/):**--- ## CLI (added in a follow-up PR)-```sh-cargo install flutter_rust_bridge_codegen-flutter_rust_bridge_codegen generate-```--- A Rust CLI lives in `rust/cli/` and will depend on `ente-core`.-`flutter_rust_bridge_codegen generate` needs to be run either manually (or in watch mode, `flutter_rust_bridge_codegen generate --watch`) whenever the Rust source changes to get the bindings to update.--- ## Validation + Fuzzing (added in a follow-up PR)-**ente_photos_rust (mobile/apps/photos/rust/):**--- Validation suite + benchmarks (vs libsodium) and fuzz targets will live under:- - `rust/validation/`- - `rust/core/fuzz/`-```sh-flutter_rust_bridge_codegen generate-flutter test-```++See `rust/core/README.md` for module docs.