Skip to content

Privacy-first password manager with built-in email aliasing. Fully encrypted and self-hostable.

Remove unused blob diff logic (#2159)

Leendert de Borst511a6386d7d7
diff --git a/core/rust/src/ffi.rs b/core/rust/src/ffi.rs
index 9820e8919..522f1716f 100644
--- a/core/rust/src/ffi.rs
+++ b/core/rust/src/ffi.rs
@@ -271,15 +271,6 @@ pub unsafe extern "C" fn vault_codec_validate_data_bucket_ffi(input_json: *const
codec_json_ffi(input_json, "input_json", crate::vault_codec::validate_data_bucket_json)
}
-/// Blob upload diff. Input: `{ "manifest": <manifest>, "knownHashes": [..] }`. Output: JSON array of hashes.
-///
-/// # Safety
-/// `input_json` must be a valid null-terminated C string; free the result with `free_string`.
-#[no_mangle]
-pub unsafe extern "C" fn vault_codec_which_blobs_to_upload_ffi(input_json: *const c_char) -> *mut c_char {
- codec_json_ffi(input_json, "input_json", crate::vault_codec::which_blobs_to_upload_json)
-}
-
/// Generate a fresh per-user salt (lowercase hex).
///
/// # Safety
diff --git a/core/rust/src/lib.rs b/core/rust/src/lib.rs
index 12e1ec48d..79c6ecdeb 100644
--- a/core/rust/src/lib.rs
+++ b/core/rust/src/lib.rs
@@ -26,7 +26,7 @@ pub use vault_merge::{
pub use vault_codec::{
compute_ciphertext_hash, canonicalize_from_sqlite,
extract_bucket, generate_user_salt, unpack_payload, materialize_as_sqlite, pack_payload,
- validate_manifest, validate_data_bucket, which_blobs_to_upload, BlobEntry,
+ validate_manifest, validate_data_bucket, BlobEntry,
CanonicalizeInput, CanonicalizedVault, CodecRecord, CodecTableData, DataBucket, Manifest,
MaterializeInput, MaterializedTables, ValidationResult,
};
diff --git a/core/rust/src/uniffi_api.rs b/core/rust/src/uniffi_api.rs
index e28e2c8c7..84ce5dfb7 100644
--- a/core/rust/src/uniffi_api.rs
+++ b/core/rust/src/uniffi_api.rs
@@ -208,13 +208,6 @@ pub fn vault_codec_compute_ciphertext_hash(base64_ciphertext: String) -> String
crate::vault_codec::compute_ciphertext_hash(&base64_ciphertext)
}
-/// Return the manifest's referenced blob hashes not present in `knownHashes`.
-/// Input: `{ "manifest": <manifest>, "knownHashes": [..] }`.
-#[uniffi::export]
-pub fn vault_codec_which_blobs_to_upload(input_json: String) -> Result<String, VaultError> {
- crate::vault_codec::which_blobs_to_upload_json(&input_json)
-}
-
// ═══════════════════════════════════════════════════════════════════════════════
// SRP (Secure Remote Password) Functions
// ═══════════════════════════════════════════════════════════════════════════════
diff --git a/core/rust/src/vault_codec/mod.rs b/core/rust/src/vault_codec/mod.rs
index f6d661ed4..edb248361 100644
--- a/core/rust/src/vault_codec/mod.rs
+++ b/core/rust/src/vault_codec/mod.rs
@@ -1,6 +1,6 @@
//! Vault codec: logic for translating between the canonical manifest-v1 storage format (as persisted on the server)
//! and local vault formats (e.g., SQLite, or others), including integrity envelope (canonical hash),
-//! gzip packing/unpacking, structural validation, and blob-upload diff detection.
+//! gzip packing/unpacking, and structural validation.
//!
//! This module defines the *format* codec that maps between canonical artifacts (manifest, data buckets,
//! content-addressed blobs) and platform-specific representations, without embedding knowledge of encryption
@@ -16,8 +16,6 @@ mod materialize;
mod types;
mod validate;
-use std::collections::HashSet;
-
use base64::engine::general_purpose::STANDARD as BASE64;
use base64::Engine;
use serde_json::json;
@@ -134,31 +132,6 @@ pub fn compute_ciphertext_hash(base64_ciphertext: &str) -> String {
}
}
-// ─────────────────────────────────────────────────────────────────────────────
-// blob diff
-// ─────────────────────────────────────────────────────────────────────────────
-
-/// Return the manifest's referenced blob hashes that are NOT already known.
-pub fn which_blobs_to_upload(manifest: &Manifest, known_hashes: Vec<String>) -> Vec<String> {
- let known: HashSet<String> = known_hashes.into_iter().collect();
- let mut seen: HashSet<String> = HashSet::new();
- let mut out: Vec<String> = Vec::new();
-
- for rows in manifest.tables.values() {
- for row in rows {
- for value in row.values() {
- if let Some(hash) = value.get("__blobRef").and_then(|v| v.as_str()) {
- if !known.contains(hash) && seen.insert(hash.to_string()) {
- out.push(hash.to_string());
- }
- }
- }
- }
- }
-
- out
-}
-
// ─────────────────────────────────────────────────────────────────────────────
// JSON-string siblings (FFI / UniFFI interface)
// ─────────────────────────────────────────────────────────────────────────────
@@ -199,19 +172,5 @@ pub fn validate_data_bucket_json(data_bucket_json: &str) -> VaultResult<String>
Ok(serde_json::to_string(&validate_data_bucket(&b))?)
}
-/// JSON-string sibling of [`which_blobs_to_upload`]. Input:
-/// `{ "manifest": <manifest>, "knownHashes": [..] }`.
-pub fn which_blobs_to_upload_json(input_json: &str) -> VaultResult<String> {
- #[derive(serde::Deserialize)]
- #[serde(rename_all = "camelCase")]
- struct Input {
- manifest: Manifest,
- #[serde(default)]
- known_hashes: Vec<String>,
- }
- let input: Input = serde_json::from_str(input_json)?;
- Ok(serde_json::to_string(&which_blobs_to_upload(&input.manifest, input.known_hashes))?)
-}
-
#[cfg(test)]
mod tests;
diff --git a/core/rust/src/vault_codec/tests.rs b/core/rust/src/vault_codec/tests.rs
index 1285b63c7..3a69fe190 100644
--- a/core/rust/src/vault_codec/tests.rs
+++ b/core/rust/src/vault_codec/tests.rs
@@ -215,20 +215,6 @@ fn validate_manifest_ok_for_clean_vault() {
assert!(validate_manifest(&manifest).ok);
}
-#[test]
-fn which_blobs_to_upload_excludes_known() {
- let favicon = vec![0x09, 0x08, 0x07];
- let out = canonicalize_from_sqlite(basic_input(vec![CodecTableData {
- name: "Logos".to_string(),
- records: vec![row(&[("Id", json!("l1")), ("FileData", json!({ "__b64": b64(&favicon) }))])],
- }]))
- .unwrap();
- let hash = out.blobs.keys().next().unwrap().clone();
-
- assert_eq!(which_blobs_to_upload(&out.manifest, vec![]), vec![hash.clone()]);
- assert!(which_blobs_to_upload(&out.manifest, vec![hash]).is_empty());
-}
-
#[test]
fn generate_user_salt_is_64_hex_chars() {
let salt = generate_user_salt();
@@ -255,11 +241,6 @@ fn forward_compat_unknown_manifest_fields_preserved() {
assert_eq!(reser["futureField"], json!({ "nested": true }));
}
-/// Rows of `table` in the materialized output (empty if absent).
-fn materialized_rows<'a>(m: &'a MaterializedTables, table: &str) -> &'a [CodecRecord] {
- m.tables.iter().find(|t| t.name == table).map(|t| t.records.as_slice()).unwrap_or(&[])
-}
-
#[test]
fn canonicalize_dedupes_duplicate_logo_sources_and_remaps_items() {
// Two clients minted distinct Ids for the same domain; Items point at each. Canonicalize must
@@ -300,58 +281,50 @@ fn canonicalize_dedupes_duplicate_logo_sources_and_remaps_items() {
}
#[test]
-fn materialize_dedupes_duplicate_logo_sources_from_legacy_manifest() {
- // A manifest already on the server carrying duplicate Source rows must materialize cleanly
- // (self-heal on pull) rather than exploding on the UNIQUE(Source) index.
- let mut manifest = canonicalize_from_sqlite(basic_input(vec![
- CodecTableData { name: "Items".to_string(), records: vec![] },
+fn canonicalize_dedup_tiebreak_keeps_highest_id_when_no_favicon() {
+ // When neither duplicate carries favicon bytes, the survivor is chosen deterministically by Id
+ // (highest wins); the Item pointing at the dropped row is remapped to it.
+ let out = canonicalize_from_sqlite(basic_input(vec![
+ CodecTableData {
+ name: "Logos".to_string(),
+ records: vec![
+ row(&[("Id", json!("logo-a")), ("Source", json!("github.com"))]),
+ row(&[("Id", json!("logo-b")), ("Source", json!("github.com"))]),
+ ],
+ },
+ CodecTableData {
+ name: "Items".to_string(),
+ records: vec![row(&[("Id", json!("i1")), ("LogoId", json!("logo-a"))])],
+ },
]))
- .unwrap()
- .manifest;
- manifest.tables.insert(
- "Logos".to_string(),
- vec![
- row(&[("Id", json!("logo-a")), ("Source", json!("github.com"))]),
- row(&[("Id", json!("logo-b")), ("Source", json!("github.com"))]),
- ],
- );
- manifest.tables.insert(
- "Items".to_string(),
- vec![row(&[("Id", json!("i1")), ("LogoId", json!("logo-b"))])],
- );
+ .unwrap();
- let re = materialize_as_sqlite(MaterializeInput { manifest, data_buckets: vec![] }).unwrap();
- let logos = materialized_rows(&re, "Logos");
- assert_eq!(logos.len(), 1, "duplicate Source collapsed on materialize");
- let survivor = logos[0]["Id"].as_str().unwrap().to_string();
- // The Item's LogoId now points at whichever row survived (deterministically the smaller Id, logo-a).
- assert_eq!(survivor, "logo-a");
- assert_eq!(materialized_rows(&re, "Items")[0]["LogoId"], json!("logo-a"));
+ let logos = &out.manifest.tables["Logos"];
+ assert_eq!(logos.len(), 1, "duplicate Source collapsed to one row");
+ assert_eq!(logos[0]["Id"], json!("logo-b"), "highest Id survives the tiebreak");
+ assert_eq!(out.manifest.tables["Items"][0]["LogoId"], json!("logo-b"), "Item remapped to survivor");
}
#[test]
-fn materialize_nulls_dangling_logo_reference() {
- // An Item pointing at a logo Id that no longer exists (e.g. collapsed away by a cross-client merge)
- // is nulled — matching FK_Items_Logos_LogoId ON DELETE SET NULL — so foreign_key_check passes.
- let mut manifest = canonicalize_from_sqlite(basic_input(vec![
- CodecTableData { name: "Items".to_string(), records: vec![] },
+fn canonicalize_nulls_dangling_logo_reference() {
+ // An Item pointing at a logo Id that doesn't exist (e.g. collapsed away by a cross-client merge) is
+ // nulled — matching FK_Items_Logos_LogoId ON DELETE SET NULL — so materialize's foreign_key_check passes.
+ let out = canonicalize_from_sqlite(basic_input(vec![
+ CodecTableData {
+ name: "Logos".to_string(),
+ records: vec![row(&[("Id", json!("logo-a")), ("Source", json!("github.com"))])],
+ },
+ CodecTableData {
+ name: "Items".to_string(),
+ records: vec![
+ row(&[("Id", json!("i1")), ("LogoId", json!("logo-a"))]),
+ row(&[("Id", json!("i2")), ("LogoId", json!("ghost"))]),
+ ],
+ },
]))
- .unwrap()
- .manifest;
- manifest.tables.insert(
- "Logos".to_string(),
- vec![row(&[("Id", json!("logo-a")), ("Source", json!("github.com"))])],
- );
- manifest.tables.insert(
- "Items".to_string(),
- vec![
- row(&[("Id", json!("i1")), ("LogoId", json!("logo-a"))]),
- row(&[("Id", json!("i2")), ("LogoId", json!("ghost"))]),
- ],
- );
+ .unwrap();
- let re = materialize_as_sqlite(MaterializeInput { manifest, data_buckets: vec![] }).unwrap();
- let items = materialized_rows(&re, "Items");
+ let items = &out.manifest.tables["Items"];
let i1 = items.iter().find(|r| r["Id"] == json!("i1")).unwrap();
let i2 = items.iter().find(|r| r["Id"] == json!("i2")).unwrap();
assert_eq!(i1["LogoId"], json!("logo-a"), "valid reference untouched");
diff --git a/core/rust/src/wasm.rs b/core/rust/src/wasm.rs
index 3290bee09..6ddc3bc30 100644
--- a/core/rust/src/wasm.rs
+++ b/core/rust/src/wasm.rs
@@ -203,17 +203,6 @@ pub fn vault_codec_compute_ciphertext_hash_js(base64_ciphertext: &str) -> String
vault_codec::compute_ciphertext_hash(base64_ciphertext)
}
-/// Return the manifest's referenced blob hashes not present in `known_hashes`.
-#[wasm_bindgen(js_name = vaultCodecWhichBlobsToUpload)]
-pub fn vault_codec_which_blobs_to_upload_js(manifest: JsValue, known_hashes: JsValue) -> Result<JsValue, JsValue> {
- let m: Manifest = serde_wasm_bindgen::from_value(manifest)
- .map_err(|e| JsValue::from_str(&format!("Failed to parse manifest: {}", e)))?;
- let known: Vec<String> = serde_wasm_bindgen::from_value(known_hashes)
- .map_err(|e| JsValue::from_str(&format!("Failed to parse known hashes: {}", e)))?;
- serde_wasm_bindgen::to_value(&vault_codec::which_blobs_to_upload(&m, known))
- .map_err(|e| JsValue::from_str(&format!("Failed to serialize result: {}", e)))
-}
-
// ═══════════════════════════════════════════════════════════════════════════════
// Credential Matcher WASM Bindings
// ═══════════════════════════════════════════════════════════════════════════════