Skip to content

armgit / ente

Public Imported from GitHub
0

πŸ’š End-to-end encrypted cloud for everything.

Merge branch 'rust-crypto' into rust-core-impl

Prateek Sunal58c835f2b8ed
diff --cc rust/README.md
index 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.