Skip to content

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

Update core/rust src dir structure

Leendert de Borstf92ab3582d79
diff --git a/core/rust/README.md b/core/rust/README.md
index 440c362a6..502524834 100644
--- a/core/rust/README.md
+++ b/core/rust/README.md
@@ -53,9 +53,11 @@ Random identity (alias persona) generation: names from embedded per-language dic
### crypto
Argon2id key derivation, AES-256-GCM, RSA-OAEP key grants, the account key hierarchy and the SRP-6a handshake.
-### timestamp and error
-The vault datetime formats plus the `UpdatedAt` comparison the merge relies on, and the `VaultError`
-type with the JSON-in/JSON-out call helper the bindings share.
+### common
+Crate-wide helper utils.
+
+### bindings
+The host entry points: `wasm` (wasm-bindgen, browser) and `uniffi_api` (UniFFI, Swift and Kotlin).
## Building
diff --git a/core/rust/src/bindings/mod.rs b/core/rust/src/bindings/mod.rs
new file mode 100644
index 000000000..439dc08b8
--- /dev/null
+++ b/core/rust/src/bindings/mod.rs
@@ -0,0 +1,7 @@
+//! Host bindings: wasm-bindgen for the browser, UniFFI for Swift and Kotlin.
+
+#[cfg(feature = "wasm")]
+pub mod wasm;
+
+#[cfg(feature = "uniffi")]
+pub mod uniffi_api;
diff --git a/core/rust/src/uniffi_api.rs b/core/rust/src/bindings/uniffi_api.rs
similarity index 99%
rename from core/rust/src/uniffi_api.rs
rename to core/rust/src/bindings/uniffi_api.rs
index 3644f61a7..d732a5d46 100644
--- a/core/rust/src/uniffi_api.rs
+++ b/core/rust/src/bindings/uniffi_api.rs
@@ -5,7 +5,7 @@
use crate::crypto::argon2::Argon2Error;
use crate::crypto::srp::{SrpEphemeral, SrpError, SrpSession};
-use crate::error::{json_call, VaultError};
+use crate::common::error::{json_call, VaultError};
use crate::sqlite_host::{MemoryDatabase, SqlResult, SqlValue};
use crate::vault_codec::{self, CanonicalizeInput};
diff --git a/core/rust/src/wasm.rs b/core/rust/src/bindings/wasm.rs
similarity index 99%
rename from core/rust/src/wasm.rs
rename to core/rust/src/bindings/wasm.rs
index a842f1dd3..f7491c827 100644
--- a/core/rust/src/wasm.rs
+++ b/core/rust/src/bindings/wasm.rs
@@ -55,7 +55,7 @@ pub fn merge_canonical_js(input: JsValue) -> Result<JsValue, JsValue> {
/// Input: `PruneInput` JSON. Output: `PruneOutput` JSON.
#[wasm_bindgen(js_name = pruneVaultJson)]
pub fn prune_vault_json_js(input_json: &str) -> Result<String, JsValue> {
- crate::error::json_call(input_json, prune_vault).map_err(js_err)
+ crate::common::error::json_call(input_json, prune_vault).map_err(js_err)
}
/// Get the per-table SELECT queries used to build prune input.
diff --git a/core/rust/src/encoding.rs b/core/rust/src/common/encoding.rs
similarity index 98%
rename from core/rust/src/encoding.rs
rename to core/rust/src/common/encoding.rs
index 4a63ada6f..b48db1d53 100644
--- a/core/rust/src/encoding.rs
+++ b/core/rust/src/common/encoding.rs
@@ -3,7 +3,7 @@
use base64::engine::general_purpose::{STANDARD as BASE64, URL_SAFE_NO_PAD as BASE64_URL};
use base64::Engine;
-use crate::error::{VaultError, VaultResult};
+use crate::common::error::{VaultError, VaultResult};
/// Lowercase hex of a byte slice.
pub(crate) fn hex_encode_lower(bytes: &[u8]) -> String {
diff --git a/core/rust/src/error.rs b/core/rust/src/common/error.rs
similarity index 100%
rename from core/rust/src/error.rs
rename to core/rust/src/common/error.rs
diff --git a/core/rust/src/common/mod.rs b/core/rust/src/common/mod.rs
new file mode 100644
index 000000000..fe04303e1
--- /dev/null
+++ b/core/rust/src/common/mod.rs
@@ -0,0 +1,6 @@
+//! Crate-wide helpers the feature modules share: errors, byte encodings, randomness and timestamps.
+
+pub(crate) mod encoding;
+pub mod error;
+pub(crate) mod rng;
+pub mod timestamp;
diff --git a/core/rust/src/rng.rs b/core/rust/src/common/rng.rs
similarity index 97%
rename from core/rust/src/rng.rs
rename to core/rust/src/common/rng.rs
index e998b0532..168b1c86e 100644
--- a/core/rust/src/rng.rs
+++ b/core/rust/src/common/rng.rs
@@ -24,7 +24,7 @@ pub(crate) fn make_rng(seed: Option<&str>) -> StdRng {
/// Parse a 64-character hex string into a 32-byte seed, or `None` if it is malformed.
fn parse_seed_hex(hex: &str) -> Option<[u8; 32]> {
- crate::encoding::hex_decode(hex)?.try_into().ok()
+ crate::common::encoding::hex_decode(hex)?.try_into().ok()
}
/// Get an unbiased random index in `0..max` using rejection sampling over the given CSPRNG.
diff --git a/core/rust/src/timestamp.rs b/core/rust/src/common/timestamp.rs
similarity index 100%
rename from core/rust/src/timestamp.rs
rename to core/rust/src/common/timestamp.rs
diff --git a/core/rust/src/credential_matcher/mod.rs b/core/rust/src/credential_matcher/mod.rs
index 9ed4ca812..ff37aaf2d 100644
--- a/core/rust/src/credential_matcher/mod.rs
+++ b/core/rust/src/credential_matcher/mod.rs
@@ -246,8 +246,8 @@ fn extract_words(text: &str) -> Vec<String> {
}
/// JSON sibling of [`filter_credentials`]. Input: `CredentialMatcherInput`. Output: `CredentialMatcherOutput`.
-pub fn filter_credentials_json(input_json: &str) -> crate::error::VaultResult<String> {
- crate::error::json_call(input_json, |input| Ok(filter_credentials(input)))
+pub fn filter_credentials_json(input_json: &str) -> crate::common::error::VaultResult<String> {
+ crate::common::error::json_call(input_json, |input| Ok(filter_credentials(input)))
}
#[cfg(test)]
diff --git a/core/rust/src/crypto/aes_gcm.rs b/core/rust/src/crypto/aes_gcm.rs
index eb8132bc6..ac1a67019 100644
--- a/core/rust/src/crypto/aes_gcm.rs
+++ b/core/rust/src/crypto/aes_gcm.rs
@@ -4,9 +4,9 @@ use aes_gcm::aead::{Aead, KeyInit, Payload};
use aes_gcm::{Aes256Gcm, Nonce};
use zeroize::{Zeroize, Zeroizing};
-use crate::encoding::{base64_decode, base64_encode};
-use crate::error::{VaultError, VaultResult};
-use crate::rng::fill_random;
+use crate::common::encoding::{base64_decode, base64_encode};
+use crate::common::error::{VaultError, VaultResult};
+use crate::common::rng::fill_random;
const IV_LENGTH: usize = 12;
const KEY_LENGTH: usize = 32;
diff --git a/core/rust/src/crypto/key_chain.rs b/core/rust/src/crypto/key_chain.rs
index 33a7c6edc..82f0d2fbf 100644
--- a/core/rust/src/crypto/key_chain.rs
+++ b/core/rust/src/crypto/key_chain.rs
@@ -7,8 +7,8 @@ use zeroize::{Zeroize, ZeroizeOnDrop, Zeroizing};
use super::aes_gcm::{generate_key_base64, symmetric_decrypt_bytes, symmetric_encrypt, symmetric_encrypt_bytes};
use super::rsa_oaep::generate_rsa_key_pair;
-use crate::encoding::{base64_decode, base64_encode};
-use crate::error::VaultResult;
+use crate::common::encoding::{base64_decode, base64_encode};
+use crate::common::error::VaultResult;
/// The wrapped halves of an account key hierarchy: what the server stores.
#[derive(Debug, Clone, Serialize, Deserialize)]
diff --git a/core/rust/src/crypto/rsa_oaep.rs b/core/rust/src/crypto/rsa_oaep.rs
index a1ee0672b..723c58c3e 100644
--- a/core/rust/src/crypto/rsa_oaep.rs
+++ b/core/rust/src/crypto/rsa_oaep.rs
@@ -7,8 +7,8 @@ use sha2::Sha256;
use std::fmt;
use zeroize::{Zeroize, ZeroizeOnDrop, Zeroizing};
-use crate::encoding::{base64_decode, base64_encode, base64url_decode, base64url_encode};
-use crate::error::{VaultError, VaultResult};
+use crate::common::encoding::{base64_decode, base64_encode, base64url_decode, base64url_encode};
+use crate::common::error::{VaultError, VaultResult};
const MODULUS_BITS: usize = 2048;
diff --git a/core/rust/src/crypto/srp.rs b/core/rust/src/crypto/srp.rs
index 38d4fd60a..8b287e9f8 100644
--- a/core/rust/src/crypto/srp.rs
+++ b/core/rust/src/crypto/srp.rs
@@ -15,8 +15,8 @@ use srp::utils::{compute_k, compute_u};
use subtle::ConstantTimeEq;
use thiserror::Error;
-use crate::encoding::{hex_decode, hex_encode_upper as bytes_to_hex};
-use crate::rng::fill_random;
+use crate::common::encoding::{hex_decode, hex_encode_upper as bytes_to_hex};
+use crate::common::rng::fill_random;
/// Byte length of the 2048-bit group modulus N; all padded values use this size.
const N_BYTES: usize = 256;
diff --git a/core/rust/src/email_parser/mod.rs b/core/rust/src/email_parser/mod.rs
index 6b1e51377..db2d67114 100644
--- a/core/rust/src/email_parser/mod.rs
+++ b/core/rust/src/email_parser/mod.rs
@@ -3,7 +3,7 @@ use mail_parser::{GetHeader, Message, MessageParser, MessagePart, MimeHeaders};
use serde::Serialize;
use std::io::Read;
-use crate::error::{VaultError, VaultResult};
+use crate::common::error::{VaultError, VaultResult};
/// Header the server stamps on an attachment whose body it detached from the source at ingest, carrying the
/// index that body is stored and requested under. Reading the index from the message itself keeps it
diff --git a/core/rust/src/identity_generator/mod.rs b/core/rust/src/identity_generator/mod.rs
index a289ae1a0..fb7bacf74 100644
--- a/core/rust/src/identity_generator/mod.rs
+++ b/core/rust/src/identity_generator/mod.rs
@@ -20,8 +20,8 @@ use chrono::{Datelike, Days, NaiveDate, Utc};
use rand::RngCore;
use serde::{Deserialize, Serialize};
-use crate::error::{json_call, VaultError};
-use crate::rng::{make_rng, unbiased_index};
+use crate::common::error::{json_call, VaultError};
+use crate::common::rng::{make_rng, unbiased_index};
/// Gender value used in generated identities.
pub const GENDER_MALE: &str = "Male";
diff --git a/core/rust/src/identity_generator/username_email.rs b/core/rust/src/identity_generator/username_email.rs
index c70ab85b6..414a8cef4 100644
--- a/core/rust/src/identity_generator/username_email.rs
+++ b/core/rust/src/identity_generator/username_email.rs
@@ -1,7 +1,7 @@
//! Username and email prefix generation based on an identity's name and birth year.
use rand::RngCore;
-use crate::rng::unbiased_index;
+use crate::common::rng::unbiased_index;
const MIN_LENGTH: usize = 6;
const MAX_LENGTH: usize = 20;
diff --git a/core/rust/src/lib.rs b/core/rust/src/lib.rs
index a9cdf406a..647343165 100644
--- a/core/rust/src/lib.rs
+++ b/core/rust/src/lib.rs
@@ -14,13 +14,10 @@
//! - **password_generator**: Password and passphrase (Diceware) generation
//! - **identity_generator**: Random identity (alias persona) generation
//! - **crypto**: Argon2id derivation, AES-256-GCM, RSA-OAEP, the account key hierarchy and the SRP-6a handshake
-//! - **timestamp**: the vault datetime formats and the `UpdatedAt` comparison the merge relies on
-//! - **error**: the `VaultError` type and the JSON-in/JSON-out call helper the bindings share
+//! - **common**: `VaultError`, byte encodings, randomness and the vault timestamp formats
+//! - **bindings**: the wasm-bindgen and UniFFI entry points
-pub mod error;
-mod encoding;
-pub mod timestamp;
-mod rng;
+pub mod common;
pub mod vault_model;
pub mod vault_merge;
pub mod vault_codec;
@@ -35,15 +32,9 @@ pub mod crypto;
pub mod vault_sync;
pub mod sqlite_host;
-pub use error::VaultError;
+pub use common::error::VaultError;
-// WASM bindings
-#[cfg(feature = "wasm")]
-pub mod wasm;
-
-// UniFFI bindings for Swift/Kotlin
-#[cfg(feature = "uniffi")]
-pub mod uniffi_api;
+pub mod bindings;
// UniFFI scaffolding - generates the FFI glue code
#[cfg(feature = "uniffi")]
diff --git a/core/rust/src/password_generator/mod.rs b/core/rust/src/password_generator/mod.rs
index 7a3bfbc86..206d34e58 100644
--- a/core/rust/src/password_generator/mod.rs
+++ b/core/rust/src/password_generator/mod.rs
@@ -19,8 +19,8 @@ mod tests;
use serde::{Deserialize, Serialize};
-use crate::error::VaultError;
-use crate::rng::{make_rng, unbiased_index};
+use crate::common::error::VaultError;
+use crate::common::rng::{make_rng, unbiased_index};
/// Which generator to use.
#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize, Default)]
diff --git a/core/rust/src/sqlite_host.rs b/core/rust/src/sqlite_host/mod.rs
similarity index 98%
rename from core/rust/src/sqlite_host.rs
rename to core/rust/src/sqlite_host/mod.rs
index df70691ff..b2261c4a2 100644
--- a/core/rust/src/sqlite_host.rs
+++ b/core/rust/src/sqlite_host/mod.rs
@@ -9,8 +9,8 @@ use rusqlite::{params_from_iter, Connection, MAIN_DB};
use serde::{Deserialize, Serialize};
use serde_json::{json, Map, Value};
-use crate::encoding::base64_decode;
-use crate::error::{VaultError, VaultResult};
+use crate::common::encoding::base64_decode;
+use crate::common::error::{VaultError, VaultResult};
use crate::vault_codec::row::{inline_b64, inline_bytes};
/// One parameterized SQL statement, as the bindings and the sync engine hand it to a host.
diff --git a/core/rust/src/vault_codec/canonicalize.rs b/core/rust/src/vault_codec/canonicalize.rs
index 8275dc4a2..ebefdd831 100644
--- a/core/rust/src/vault_codec/canonicalize.rs
+++ b/core/rust/src/vault_codec/canonicalize.rs
@@ -24,7 +24,7 @@ use super::types::{
blob_spec_for, bucket_categories, bucket_category_for, is_bucketed_table, is_skip_table, is_unstamped_scope,
manifest_scoped_tables, row_identity, SCHEMA_VERSION,
};
-use crate::error::VaultResult;
+use crate::common::error::VaultResult;
use crate::vault_model::names::LOGOS_TABLE;
use crate::vault_model::{ids_equal, MANIFEST_ID_COL, OVERFLOW_TABLE};
@@ -33,8 +33,8 @@ use crate::vault_model::{ids_equal, MANIFEST_ID_COL, OVERFLOW_TABLE};
pub fn canonicalize_from_sqlite(input: CanonicalizeInput) -> VaultResult<CanonicalizedVault> {
let writing_spec = match input.manifests.first() {
Some(spec) if !spec.manifest_id.is_empty() => spec.clone(),
- Some(_) => return Err(crate::error::VaultError::General("canonicalize requires a manifest id on every manifest".to_string())),
- None => return Err(crate::error::VaultError::General("canonicalize input declares no manifests".to_string())),
+ Some(_) => return Err(crate::common::error::VaultError::General("canonicalize requires a manifest id on every manifest".to_string())),
+ None => return Err(crate::common::error::VaultError::General("canonicalize input declares no manifests".to_string())),
};
let writing_manifest_id = writing_spec.manifest_id.clone();
let writing_manifest_salt = writing_spec.manifest_salt.clone();
@@ -251,7 +251,7 @@ fn reject_unstamped_rows(tables: &HashMap<String, Vec<CodecRecord>>) -> VaultRes
let unstamped = rows.iter().filter(|row| is_unstamped(row)).count();
if unstamped > 0 {
let first = rows.iter().find(|row| is_unstamped(row)).and_then(|row| row.get("Id")).cloned().unwrap_or(Value::Null);
- return Err(crate::error::VaultError::General(format!(
+ return Err(crate::common::error::VaultError::General(format!(
"the codec refuses to write {} row(s) of {} that name no manifest (first: Id {}); every row must carry the manifest it belongs to",
unstamped, name, first
)));
@@ -296,7 +296,7 @@ fn extract_blob_cell(
None => return Ok(serde_json::Value::Null),
};
- let bytes = match crate::encoding::base64_decode(b64) {
+ let bytes = match crate::common::encoding::base64_decode(b64) {
Ok(b) if !b.is_empty() => b,
_ => return Ok(serde_json::Value::Null),
};
@@ -355,7 +355,7 @@ fn primary_key_of(identity: &str) -> &str {
pub fn extract_buckets(category: String, manifest_ids: Vec<String>, mut tables: HashMap<String, Vec<CodecRecord>>) -> VaultResult<Vec<DataBucket>> {
if manifest_ids.is_empty() {
let message = "extract_buckets declares no manifests; a bucket write needs the manifests it may be addressed to";
- return Err(crate::error::VaultError::General(message.to_string()));
+ return Err(crate::common::error::VaultError::General(message.to_string()));
}
let overflow = tables.remove(OVERFLOW_TABLE).map(|records| CodecOverflow::from_table_records(&records)).unwrap_or_default();
diff --git a/core/rust/src/vault_codec/compress.rs b/core/rust/src/vault_codec/compress.rs
index e7cdd0137..bcf3a18a6 100644
--- a/core/rust/src/vault_codec/compress.rs
+++ b/core/rust/src/vault_codec/compress.rs
@@ -6,7 +6,7 @@ use flate2::read::GzDecoder;
use flate2::write::GzEncoder;
use flate2::Compression;
-use crate::error::{VaultError, VaultResult};
+use crate::common::error::{VaultError, VaultResult};
/// gzip the given bytes.
pub fn gzip(bytes: &[u8]) -> VaultResult<Vec<u8>> {
diff --git a/core/rust/src/vault_codec/hash.rs b/core/rust/src/vault_codec/hash.rs
index 6a698dcd1..39c6c9e19 100644
--- a/core/rust/src/vault_codec/hash.rs
+++ b/core/rust/src/vault_codec/hash.rs
@@ -14,8 +14,8 @@
use sha2::{Digest, Sha256};
-use crate::encoding::{hex_decode, hex_encode_lower, uuid_from_bytes};
-use crate::error::{VaultError, VaultResult};
+use crate::common::encoding::{hex_decode, hex_encode_lower, uuid_from_bytes};
+use crate::common::error::{VaultError, VaultResult};
/// A UUIDv8 derived from a string: the first 16 bytes of its sha256, version and variant bits set.
pub fn derived_uuid(material: &str) -> String {
diff --git a/core/rust/src/vault_codec/materialize.rs b/core/rust/src/vault_codec/materialize.rs
index bcfeb2ac0..13fb8cfe2 100644
--- a/core/rust/src/vault_codec/materialize.rs
+++ b/core/rust/src/vault_codec/materialize.rs
@@ -21,7 +21,7 @@ use serde_json::json;
use super::manifest::{CodecOverflow, CodecRecord, CodecTableData, Manifest, MaterializeInput, MaterializedTables};
use super::row::blob_ref_of;
use super::types::{blob_spec_for, ensure_readable_schema_version, is_local_only_table, row_identity};
-use crate::error::{VaultError, VaultResult};
+use crate::common::error::{VaultError, VaultResult};
use crate::vault_model::names::ID_COL;
use crate::vault_model::{id_key, MANIFESTS_TABLE, MANIFEST_ID_COL, OVERFLOW_TABLE};
diff --git a/core/rust/src/vault_codec/mod.rs b/core/rust/src/vault_codec/mod.rs
index 4a99aa94e..7f7fcb227 100644
--- a/core/rust/src/vault_codec/mod.rs
+++ b/core/rust/src/vault_codec/mod.rs
@@ -23,8 +23,8 @@ mod validate;
use serde_json::json;
-use crate::encoding::{base64_decode, hex_encode_lower};
-use crate::error::{VaultError, VaultResult};
+use crate::common::encoding::{base64_decode, hex_encode_lower};
+use crate::common::error::{VaultError, VaultResult};
pub use types::SCHEMA_VERSION;
pub use canonicalize::{canonicalize_from_sqlite, extract_buckets};
@@ -59,7 +59,7 @@ pub fn logo_content_hash(bytes: &[u8]) -> String {
/// Generate a fresh 32-byte per-manifest blob-hashing salt as a lowercase hex string.
pub fn generate_manifest_salt() -> String {
let mut bytes = [0u8; 32];
- crate::rng::fill_random(&mut bytes);
+ crate::common::rng::fill_random(&mut bytes);
hex_encode_lower(&bytes)
}
diff --git a/core/rust/src/vault_codec/normalize.rs b/core/rust/src/vault_codec/normalize.rs
index 956c67548..a1b01c0c9 100644
--- a/core/rust/src/vault_codec/normalize.rs
+++ b/core/rust/src/vault_codec/normalize.rs
@@ -7,7 +7,7 @@ use serde_json::json;
use super::manifest::CodecRecord;
use super::row::{is_deleted, str_col, truthy};
use super::types::{is_guid, is_id_column};
-use crate::timestamp::updated_at;
+use crate::common::timestamp::updated_at;
use crate::vault_model::{id_key, MANIFEST_ID_COL, MULTI_VALUE_FIELD_KEYS, SINGLE_VALUE_FIELD_KEYS, SYNCABLE_TABLES};
use crate::vault_model::names::{
CHANGED_AT_COL, FIELD_DEFINITIONS_TABLE, FIELD_DEFINITION_ID_COL, FIELD_HISTORIES_TABLE, FIELD_KEY_COL,
diff --git a/core/rust/src/vault_codec/row.rs b/core/rust/src/vault_codec/row.rs
index beb27d071..edb0ab762 100644
--- a/core/rust/src/vault_codec/row.rs
+++ b/core/rust/src/vault_codec/row.rs
@@ -7,7 +7,7 @@ use std::collections::HashMap;
use serde_json::{json, Value};
use super::manifest::CodecRecord;
-use crate::encoding::base64_encode;
+use crate::common::encoding::base64_encode;
use crate::vault_model::names::{IS_DELETED_COL, KIND_COL, LOGO_KIND_FAVICON};
/// The key of an inline byte cell: `{ "__b64": <base64> }`.
diff --git a/core/rust/src/vault_codec/sharing.rs b/core/rust/src/vault_codec/sharing.rs
index 2f022e537..5e85db1fc 100644
--- a/core/rust/src/vault_codec/sharing.rs
+++ b/core/rust/src/vault_codec/sharing.rs
@@ -37,7 +37,7 @@ use super::manifest::{CodecRecord, Manifest, ManifestSpec};
use super::row::{is_deleted, rows_of, str_col};
use super::scoped_assets::{is_custom_logo, normalize_logo_scope, reconcile_logo_references};
use super::types::{is_bucketed_table, is_local_only_table, is_manifest_scoped, is_personal_table, manifest_scoped_tables, row_identity};
-use crate::error::{VaultError, VaultResult};
+use crate::common::error::{VaultError, VaultResult};
use crate::vault_model::names::{
ENCRYPTION_KEYS_TABLE, FIELD_DEFINITIONS_TABLE, FIELD_DEFINITION_ID_COL, FIELD_HISTORIES_TABLE, FIELD_VALUES_TABLE, FOLDERS_TABLE,
FOLDER_ID_COL, ID_COL, ITEMS_TABLE, ITEM_ID_COL, ITEM_TAGS_TABLE, LOGOS_TABLE, LOGO_ID_COL, PARENT_FOLDER_ID_COL, PUBLIC_KEY_COL,
diff --git a/core/rust/src/vault_codec/sharing_tests.rs b/core/rust/src/vault_codec/sharing_tests.rs
index 62ed5d643..ce396e357 100644
--- a/core/rust/src/vault_codec/sharing_tests.rs
+++ b/core/rust/src/vault_codec/sharing_tests.rs
@@ -1433,7 +1433,7 @@ fn manifest_specs_deserialize_from_camel_case_json() {
]
})
.to_string();
- let out_json = crate::error::json_call(&input_json, |input: CanonicalizeInput| canonicalize_from_sqlite(input)).unwrap();
+ let out_json = crate::common::error::json_call(&input_json, |input: CanonicalizeInput| canonicalize_from_sqlite(input)).unwrap();
let out: CanonicalizedVault = serde_json::from_str(&out_json).unwrap();
assert_eq!(out.rest().len(), 1);
assert_eq!(out.rest()[0].manifest.manifest_id, "m-1");
diff --git a/core/rust/src/vault_codec/test_support.rs b/core/rust/src/vault_codec/test_support.rs
index 652286446..4df9a7c8f 100644
--- a/core/rust/src/vault_codec/test_support.rs
+++ b/core/rust/src/vault_codec/test_support.rs
@@ -10,7 +10,7 @@ use crate::vault_model::{MANIFESTS_TABLE, MANIFEST_ID_COL};
/// Standard base64 of `bytes`, the inline byte spelling the tests hand the codec.
pub(crate) fn b64(bytes: &[u8]) -> String {
- crate::encoding::base64_encode(bytes)
+ crate::common::encoding::base64_encode(bytes)
}
/// A row from `(column, value)` pairs.
@@ -25,12 +25,12 @@ pub(crate) fn table(name: &str, records: Vec<CodecRecord>) -> CodecTableData {
/// The current instant in the ISO form the prune input takes.
pub(crate) fn now_iso() -> String {
- crate::timestamp::now_iso_utc()
+ crate::common::timestamp::now_iso_utc()
}
/// The instant `days` days ago in the ISO form the prune input takes.
pub(crate) fn days_ago_iso(days: i64) -> String {
- crate::timestamp::iso_utc(&(chrono::Utc::now() - chrono::Duration::days(days)))
+ crate::common::timestamp::iso_utc(&(chrono::Utc::now() - chrono::Duration::days(days)))
}
/// Stamp every row of a manifest-scoped table that carries no `ManifestId`, leaving rows that already name one alone.
diff --git a/core/rust/src/vault_codec/types.rs b/core/rust/src/vault_codec/types.rs
index b89a2b9eb..75a8ff08c 100644
--- a/core/rust/src/vault_codec/types.rs
+++ b/core/rust/src/vault_codec/types.rs
@@ -16,11 +16,11 @@ pub fn is_readable_schema_version(schema_version: u32) -> bool {
}
/// Refuse a manifest or data bucket written at a format version this build cannot read.
-pub(crate) fn ensure_readable_schema_version(schema_version: u32, label: &str) -> crate::error::VaultResult<()> {
+pub(crate) fn ensure_readable_schema_version(schema_version: u32, label: &str) -> crate::common::error::VaultResult<()> {
if is_readable_schema_version(schema_version) {
return Ok(());
}
- Err(crate::error::VaultError::General(format!("{} has format version {}, this build reads up to {}", label, schema_version, SCHEMA_VERSION)))
+ Err(crate::common::error::VaultError::General(format!("{} has format version {}, this build reads up to {}", label, schema_version, SCHEMA_VERSION)))
}
/// One identity component of a row, as a string: a GUID lowercased, any other string as-is,
diff --git a/core/rust/src/vault_merge/item_deletes.rs b/core/rust/src/vault_merge/item_deletes.rs
index c5c0a7548..3a87cb32d 100644
--- a/core/rust/src/vault_merge/item_deletes.rs
+++ b/core/rust/src/vault_merge/item_deletes.rs
@@ -13,7 +13,7 @@ use std::collections::{HashMap, HashSet};
use chrono::{DateTime, Utc};
use super::get_key;
-use crate::timestamp::updated_at;
+use crate::common::timestamp::updated_at;
use crate::vault_codec::row::is_deleted;
use crate::vault_codec::{is_bucketed_table, CodecRecord};
use crate::vault_model::names::{ID_COL, ITEMS_TABLE};
diff --git a/core/rust/src/vault_merge/mod.rs b/core/rust/src/vault_merge/mod.rs
index 793bc6db6..89e24e37b 100644
--- a/core/rust/src/vault_merge/mod.rs
+++ b/core/rust/src/vault_merge/mod.rs
@@ -12,8 +12,8 @@ use std::collections::{BTreeSet, HashMap, HashSet};
use serde::{Deserialize, Serialize};
-use crate::error::VaultResult;
-use crate::timestamp::updated_at;
+use crate::common::error::VaultResult;
+use crate::common::timestamp::updated_at;
use crate::vault_model::{id_key, TableConfig, SYNCABLE_TABLES};
use crate::vault_codec::{bucket_categories, ensure_readable_schema_version, identity_part, is_bucketed_table, tables_for_category, CodecRecord, DataBucket, Manifest};
diff --git a/core/rust/src/vault_pruner/mod.rs b/core/rust/src/vault_pruner/mod.rs
index 46a025a9f..5a35897bf 100644
--- a/core/rust/src/vault_pruner/mod.rs
+++ b/core/rust/src/vault_pruner/mod.rs
@@ -9,7 +9,7 @@ use chrono::{DateTime, Duration, Utc};
use serde::{Deserialize, Serialize};
use std::collections::{HashMap, HashSet};
-use crate::error::{VaultError, VaultResult};
+use crate::common::error::{VaultError, VaultResult};
use crate::sqlite_host::SqlStatement;
use crate::vault_codec::row::{has_bytes, is_deleted, logo_kind, str_col};
use crate::vault_codec::{CodecRecord, CodecTableData};
@@ -143,9 +143,9 @@ pub fn prune_vault(input: PruneInput) -> VaultResult<PruneOutput> {
let mut stats = PruneStats::default();
let mut statements: Vec<SqlStatement> = Vec::new();
- let now = crate::timestamp::parse_vault_datetime(&input.current_time)
+ let now = crate::common::timestamp::parse_vault_datetime(&input.current_time)
.ok_or_else(|| VaultError::General(format!("Invalid current_time format: {}", input.current_time)))?;
- let now_str = crate::timestamp::iso_utc(&now);
+ let now_str = crate::common::timestamp::iso_utc(&now);
let cutoff_date = now - Duration::days(input.retention_days as i64);
// Items table is required for both the trash purge and the logo orphan check.
@@ -174,7 +174,7 @@ fn expired_item_ids(items: &[CodecRecord], cutoff_date: DateTime<Utc>) -> Vec<(S
let mut expired = Vec::new();
for item in items.iter().filter(|item| !is_deleted(item)) {
let Some(deleted_at) = str_col(item, DELETED_AT_COL) else { continue };
- let Some(deleted_date) = crate::timestamp::parse_vault_datetime(deleted_at) else { continue };
+ let Some(deleted_date) = crate::common::timestamp::parse_vault_datetime(deleted_at) else { continue };
if deleted_date < cutoff_date {
if let Some(id) = str_col(item, ID_COL) {
expired.push((manifest_of(item).to_string(), id.to_string()));
diff --git a/core/rust/src/vault_pruner/tests.rs b/core/rust/src/vault_pruner/tests.rs
index 87484d63e..3c75291e3 100644
--- a/core/rust/src/vault_pruner/tests.rs
+++ b/core/rust/src/vault_pruner/tests.rs
@@ -191,7 +191,7 @@ fn test_prune_json_api() {
"currentTime": "{}"
}}"#, old_date, now_str);
- let output_json = crate::error::json_call(&input_json, prune_vault).unwrap();
+ let output_json = crate::common::error::json_call(&input_json, prune_vault).unwrap();
let output: PruneOutput = serde_json::from_str(&output_json).unwrap();
assert!(output.success);
diff --git a/core/rust/src/vault_sharing/tests.rs b/core/rust/src/vault_sharing/tests.rs
index 164a14c82..e192a49fa 100644
--- a/core/rust/src/vault_sharing/tests.rs
+++ b/core/rust/src/vault_sharing/tests.rs
@@ -152,7 +152,7 @@ fn the_json_boundary_round_trips() {
"heldRecords": [{ "manifestId": "MAN-1", "salt": "salt-1", "encryptedVek": "ignored", "canAdminister": true }]
}"#;
- let output: serde_json::Value = serde_json::from_str(&crate::error::json_call(input, |request| Ok(resolve_manifest_write_set(request))).unwrap()).unwrap();
+ let output: serde_json::Value = serde_json::from_str(&crate::common::error::json_call(input, |request| Ok(resolve_manifest_write_set(request))).unwrap()).unwrap();
assert_eq!(output["records"][1]["manifestId"], "MAN-1");
assert_eq!(output["records"][1]["isPersonal"], false);
assert_eq!(output["skipped"].as_array().unwrap().len(), 0);
diff --git a/core/rust/src/vault_sync/blob_keys.rs b/core/rust/src/vault_sync/blob_keys.rs
index df3489349..0226a5b09 100644
--- a/core/rust/src/vault_sync/blob_keys.rs
+++ b/core/rust/src/vault_sync/blob_keys.rs
@@ -3,8 +3,8 @@
use serde::{Deserialize, Serialize};
use crate::crypto;
-use crate::encoding::base64_decode;
-use crate::error::VaultResult;
+use crate::common::encoding::base64_decode;
+use crate::common::error::VaultResult;
/// A blob as the server stores it.
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
diff --git a/core/rust/src/vault_sync/db.rs b/core/rust/src/vault_sync/db.rs
index ebdef0bd2..87c8b7fd1 100644
--- a/core/rust/src/vault_sync/db.rs
+++ b/core/rust/src/vault_sync/db.rs
@@ -8,9 +8,9 @@ use super::errors::{SyncError, SyncResult};
use super::session::Host;
use super::types::{Ack, Command, Db, DbBytes, DbRows, LogLevel};
use super::legacy;
-use crate::encoding::{base64_decode, base64_encode, uuid_from_bytes};
+use crate::common::encoding::{base64_decode, base64_encode, uuid_from_bytes};
use crate::sqlite_host::SqlStatement;
-use crate::timestamp::{now_iso_utc, now_vault_datetime};
+use crate::common::timestamp::{now_iso_utc, now_vault_datetime};
use crate::vault_codec::row::{blob_ref_of, inline_bytes};
use crate::vault_codec::{is_skip_table, manifest_scoped_tables, CodecRecord, CodecTableData, MaterializedTables};
use crate::vault_model::{id_key, ids_equal, MANIFEST_ID_COL, UNSTAMPED_SCOPE_SENTINEL};
@@ -225,7 +225,7 @@ fn bind_value(value: &Value, blobs: &HashMap<String, Vec<u8>>) -> Value {
/// A random lowercase UUID v4.
pub(crate) fn new_id() -> String {
let mut bytes = [0u8; 16];
- crate::rng::fill_random(&mut bytes);
+ crate::common::rng::fill_random(&mut bytes);
uuid_from_bytes(bytes, 4)
}
diff --git a/core/rust/src/vault_sync/engine.rs b/core/rust/src/vault_sync/engine.rs
index cd159592e..3a1aef2c8 100644
--- a/core/rust/src/vault_sync/engine.rs
+++ b/core/rust/src/vault_sync/engine.rs
@@ -623,7 +623,7 @@ pub(crate) async fn rebuild_local_schema(ctx: &mut Ctx, stamp_unstamped_into: Op
let mut blob_map = HashMap::new();
for entry in &set.canonicalized.manifests {
for (hash, blob) in &entry.blobs {
- blob_map.insert(hash.clone(), crate::encoding::base64_decode(&blob.bytes_base64)?);
+ blob_map.insert(hash.clone(), crate::common::encoding::base64_decode(&blob.bytes_base64)?);
}
}
let manifests: Vec<_> = set.canonicalized.manifests.iter().map(|m| m.manifest.clone()).collect();
diff --git a/core/rust/src/vault_sync/errors.rs b/core/rust/src/vault_sync/errors.rs
index 86d10c165..2b5ba22bb 100644
--- a/core/rust/src/vault_sync/errors.rs
+++ b/core/rust/src/vault_sync/errors.rs
@@ -3,7 +3,7 @@
use serde::{Deserialize, Serialize};
use super::types::CommandKind;
-use crate::error::VaultError;
+use crate::common::error::VaultError;
/// Client error codes, shared with the client apps (`AppErrorCodes` in the client core).
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Serialize, Deserialize)]
diff --git a/core/rust/src/vault_sync/merge.rs b/core/rust/src/vault_sync/merge.rs
index 48e18242c..1d752101f 100644
--- a/core/rust/src/vault_sync/merge.rs
+++ b/core/rust/src/vault_sync/merge.rs
@@ -136,7 +136,7 @@ async fn merge_onto_opened_manifests(ctx: &mut Ctx, opened: &OpenedManifestSet,
for (hash, blob) in &canonicalized.blobs {
local_blobs.insert(hash.clone(), blob.clone());
if !blob_map.contains_key(hash) {
- blob_map.insert(hash.clone(), crate::encoding::base64_decode(&blob.bytes_base64)?);
+ blob_map.insert(hash.clone(), crate::common::encoding::base64_decode(&blob.bytes_base64)?);
}
}
}
@@ -194,7 +194,7 @@ fn collect_merged_blobs(manifests: &[Manifest], blob_map: &HashMap<String, Vec<u
if let Some(local) = local_blobs.get(&hash) {
blobs.insert(hash, local.clone());
} else if let Some(bytes) = blob_map.get(&hash) {
- blobs.insert(hash, BlobEntry { kind, bytes_base64: crate::encoding::base64_encode(bytes) });
+ blobs.insert(hash, BlobEntry { kind, bytes_base64: crate::common::encoding::base64_encode(bytes) });
}
}
}
diff --git a/core/rust/src/vault_sync/pull.rs b/core/rust/src/vault_sync/pull.rs
index 384b20222..b9a5dac7c 100644
--- a/core/rust/src/vault_sync/pull.rs
+++ b/core/rust/src/vault_sync/pull.rs
@@ -95,8 +95,8 @@ fn verify_decrypt_unpack(base64_ciphertext: &str, vek: &str, expected_ciphertext
return Err(SyncError::ServerVaultUnreadable(format!("{} ciphertext hash mismatch, refusing to load (possible storage corruption)", label)));
}
}
- let unreadable = |e: crate::error::VaultError| SyncError::ServerVaultUnreadable(format!("{}: {}", label, e));
- let encrypted = crate::encoding::base64_decode(base64_ciphertext).map_err(unreadable)?;
+ let unreadable = |e: crate::common::error::VaultError| SyncError::ServerVaultUnreadable(format!("{}: {}", label, e));
+ let encrypted = crate::common::encoding::base64_decode(base64_ciphertext).map_err(unreadable)?;
let plain = crypto::symmetric_decrypt_bytes(&encrypted, vek).map_err(unreadable)?;
match vault_codec::unpack_versioned_payload(&plain).map_err(unreadable)? {
UnpackedPayload::Readable(payload_json) => Ok(payload_json),
@@ -390,7 +390,7 @@ async fn empty_personal_manifest(ctx: &Ctx, dto: &ManifestDto, vek: &str) -> Syn
let manifest_salt = state::get::<String>(&ctx.host, state::VAULT_MANIFEST_SALT).await?.unwrap_or_else(vault_codec::generate_manifest_salt);
let tables = SYNCABLE_TABLE_NAMES.iter().map(|name| CodecTableData { name: name.to_string(), records: Vec::new() }).collect();
let spec = ManifestSpec { manifest_id: dto.manifest_id.clone(), manifest_salt, name: None };
- let canonicalized = vault_codec::canonicalize_from_sqlite(CanonicalizeInput { tables, canonicalized_at: crate::timestamp::now_iso_utc(), manifests: vec![spec], stamp_unstamped_into: None })?;
+ let canonicalized = vault_codec::canonicalize_from_sqlite(CanonicalizeInput { tables, canonicalized_at: crate::common::timestamp::now_iso_utc(), manifests: vec![spec], stamp_unstamped_into: None })?;
let manifest = canonicalized.manifests.into_iter().next().map(|m| m.manifest).ok_or_else(|| SyncError::Other("canonicalize returned no manifest for the empty vault".to_string()))?;
Ok(ResolvedManifest { manifest_id: dto.manifest_id.clone(), is_personal: true, manifest, vek: vek.to_string(), revision: dto.revision, blob_references: Vec::new(), content_fingerprint: String::new() })
}
diff --git a/core/rust/src/vault_sync/push.rs b/core/rust/src/vault_sync/push.rs
index fc78fbddc..1bd5f6bb4 100644
--- a/core/rust/src/vault_sync/push.rs
+++ b/core/rust/src/vault_sync/push.rs
@@ -70,7 +70,7 @@ pub(crate) async fn canonicalize_vault(ctx: &Ctx, stamp_unstamped_into: Option<S
let tables = db::read_tables(&ctx.host, Db::Local).await?;
let manifest_records = resolve_manifest_records(ctx).await?;
let manifests: Vec<ManifestSpec> = manifest_records.iter().map(|r| ManifestSpec { manifest_id: r.manifest_id.clone(), manifest_salt: r.salt.clone(), name: None }).collect();
- let canonicalized = vault_codec::canonicalize_from_sqlite(CanonicalizeInput { tables, canonicalized_at: crate::timestamp::now_iso_utc(), manifests, stamp_unstamped_into })?;
+ let canonicalized = vault_codec::canonicalize_from_sqlite(CanonicalizeInput { tables, canonicalized_at: crate::common::timestamp::now_iso_utc(), manifests, stamp_unstamped_into })?;
Ok(CanonicalizedSet { canonicalized, manifest_records })
}
@@ -511,7 +511,7 @@ fn collect_upload_blobs(candidates: &[Candidate]) -> SyncResult<UploadBlobs> {
continue;
}
blobs.order.push(hash.clone());
- blobs.entries.insert(hash.clone(), UploadBlobEntry { manifest_id: candidate.record.manifest_id.clone(), bytes: crate::encoding::base64_decode(&blob.bytes_base64)?, kind: blob.kind.clone(), vek: candidate.vek.clone(), from_personal: candidate.record.is_personal });
+ blobs.entries.insert(hash.clone(), UploadBlobEntry { manifest_id: candidate.record.manifest_id.clone(), bytes: crate::common::encoding::base64_decode(&blob.bytes_base64)?, kind: blob.kind.clone(), vek: candidate.vek.clone(), from_personal: candidate.record.is_personal });
}
}
Ok(blobs)
diff --git a/core/rust/src/vault_sync/session.rs b/core/rust/src/vault_sync/session.rs
index 0fbd16279..4b5dd7d26 100644
--- a/core/rust/src/vault_sync/session.rs
+++ b/core/rust/src/vault_sync/session.rs
@@ -11,7 +11,7 @@ use serde_json::Value;
use super::engine;
use super::errors::{SyncError, SyncResult};
use super::types::{Ack, Command, LogLevel, SyncRequest};
-use crate::error::{VaultError, VaultResult};
+use crate::common::error::{VaultError, VaultResult};
/// The exchange point between the engine's future and the host.
#[derive(Default)]
diff --git a/core/rust/src/vault_sync/state.rs b/core/rust/src/vault_sync/state.rs
index 7fc35cfc2..f9a93707b 100644
--- a/core/rust/src/vault_sync/state.rs
+++ b/core/rust/src/vault_sync/state.rs
@@ -174,14 +174,14 @@ const SQLITE_HEADER: &[u8] = b"SQLite format 3\0";
/// Decrypt a stored vault blob into the plaintext SQLite database.
pub(crate) fn decrypt_vault_blob(encrypted_blob: &str, key: &str) -> SyncResult<Vec<u8>> {
- let ciphertext = crate::encoding::base64_decode(encrypted_blob)?;
+ let ciphertext = crate::common::encoding::base64_decode(encrypted_blob)?;
let plaintext = crypto::symmetric_decrypt_bytes(&ciphertext, key).map_err(|e| SyncError::VaultDecryptFailed(e.to_string()))?;
if plaintext.starts_with(SQLITE_HEADER) {
return Ok(plaintext);
}
let not_a_database = || SyncError::VaultDecryptFailed("plaintext is neither a database nor base64 text".to_string());
let text = String::from_utf8(plaintext).map_err(|_| not_a_database())?;
- crate::encoding::base64_decode(text.trim()).map_err(|_| not_a_database())
+ crate::common::encoding::base64_decode(text.trim()).map_err(|_| not_a_database())
}
/// Encrypt a plaintext SQLite database for local storage.
diff --git a/core/rust/src/vault_sync/tests/mod.rs b/core/rust/src/vault_sync/tests/mod.rs
index 55bdb5980..a30b75619 100644
--- a/core/rust/src/vault_sync/tests/mod.rs
+++ b/core/rust/src/vault_sync/tests/mod.rs
@@ -33,7 +33,7 @@ fn request(operation: &str, key: &str, dirty: bool, mutation_sequence: u64) -> S
}
fn insert_item(conn: &rusqlite::Connection, id: &str, name: &str, manifest_id: &str) {
- let now = crate::timestamp::now_vault_datetime();
+ let now = crate::common::timestamp::now_vault_datetime();
conn.execute(
"INSERT INTO Items (Id, ManifestId, Name, ItemType, FolderId, CreatedAt, UpdatedAt, IsDeleted) VALUES (?, ?, ?, 'Login', NULL, ?, ?, 0)",
rusqlite::params![id, manifest_id, name, now, now],
@@ -171,7 +171,7 @@ fn new_account_starts_from_an_empty_vault_and_writes_its_first_revision() {
// The written manifest opens with the VEK and names the personal manifest.
let blob = body["manifests"][0]["manifestBlob"].as_str().unwrap();
- let plain = crypto::symmetric_decrypt_bytes(&crate::encoding::base64_decode(blob).unwrap(), &vek).unwrap();
+ let plain = crypto::symmetric_decrypt_bytes(&crate::common::encoding::base64_decode(blob).unwrap(), &vek).unwrap();
let manifest: Value = serde_json::from_str(&vault_codec::unpack_payload(&plain).unwrap()).unwrap();
assert_eq!(manifest["manifestId"], PERSONAL_MANIFEST_ID);
assert_eq!(manifest["manifestSalt"], host.state[state::VAULT_MANIFEST_SALT]);
@@ -299,7 +299,7 @@ fn dirty_client_pushes_only_what_changed() {
// The written manifest decrypts with the VEK and carries both items.
let blob = body["manifests"][0]["manifestBlob"].as_str().unwrap();
- let plain = crypto::symmetric_decrypt_bytes(&crate::encoding::base64_decode(blob).unwrap(), &vek).unwrap();
+ let plain = crypto::symmetric_decrypt_bytes(&crate::common::encoding::base64_decode(blob).unwrap(), &vek).unwrap();
let manifest: Value = serde_json::from_str(&vault_codec::unpack_payload(&plain).unwrap()).unwrap();
assert_eq!(manifest["tables"]["Items"].as_array().unwrap().len(), 2);
}
@@ -316,7 +316,7 @@ fn pushed_blobs_name_the_manifest_that_owns_them() {
host.respond("GET", "Vault", vault);
host.drive(&SyncSession::new(&request("fullSync", &vek, false, 0)).unwrap());
- let now = crate::timestamp::now_vault_datetime();
+ let now = crate::common::timestamp::now_vault_datetime();
host.local
.execute(
"INSERT INTO Logos (ManifestId, Id, Source, FileData, Kind, CreatedAt, UpdatedAt, IsDeleted) VALUES (?, ?, 'example.com', ?, 'favicon', ?, ?, 0)",
@@ -345,7 +345,7 @@ fn pushed_blobs_name_the_manifest_that_owns_them() {
assert_eq!(upload["blobs"][0]["hash"], missing_checks[0].body.as_ref().unwrap()["hashes"][0]);
// The bytes are encrypted with the blob's own key, which travels encrypted with the VEK.
- let ciphertext = crate::encoding::base64_decode(upload["blobs"][0]["encryptedDataBase64"].as_str().unwrap()).unwrap();
+ let ciphertext = crate::common::encoding::base64_decode(upload["blobs"][0]["encryptedDataBase64"].as_str().unwrap()).unwrap();
assert!(crypto::symmetric_decrypt_bytes(&ciphertext, &vek).is_err());
let blob_key = crypto::unwrap_key(upload["blobs"][0]["encryptedBlobKey"].as_str().unwrap(), &vek).unwrap();
assert_eq!(crypto::symmetric_decrypt_bytes(&ciphertext, &blob_key).unwrap(), vec![1u8, 2, 3, 4]);
@@ -421,14 +421,14 @@ fn outdated_push_merges_the_server_change_and_retries() {
assert_eq!(posts.last().unwrap().body.as_ref().unwrap()["manifests"][0]["currentRevision"], 8);
let merged: Value = {
let blob = posts.last().unwrap().body.as_ref().unwrap()["manifests"][0]["manifestBlob"].as_str().unwrap();
- let plain = crypto::symmetric_decrypt_bytes(&crate::encoding::base64_decode(blob).unwrap(), &vek).unwrap();
+ let plain = crypto::symmetric_decrypt_bytes(&crate::common::encoding::base64_decode(blob).unwrap(), &vek).unwrap();
serde_json::from_str(&vault_codec::unpack_payload(&plain).unwrap()).unwrap()
};
assert_eq!(merged["tables"]["Items"].as_array().unwrap().len(), 3);
}
fn insert_item_stats(conn: &rusqlite::Connection, item_id: &str, use_count: i64) {
- let now = crate::timestamp::now_vault_datetime();
+ let now = crate::common::timestamp::now_vault_datetime();
conn.execute(
"INSERT INTO ItemStats (ManifestId, Id, UseCount, AutofillCount, CopyCount, PasskeyAuthCount, CreatedAt, UpdatedAt, IsDeleted) VALUES (?, ?, ?, 0, 0, 0, ?, ?, 0)",
rusqlite::params![PERSONAL_MANIFEST_ID, item_id, use_count, now, now],
@@ -489,7 +489,7 @@ fn outdated_bucket_only_push_merges_the_server_bucket_instead_of_overwriting_it(
let accepted = posts.last().unwrap().body.as_ref().unwrap();
assert_eq!(accepted["buckets"][0]["currentRevision"], 8);
let bucket: Value = {
- let plain = crypto::symmetric_decrypt_bytes(&crate::encoding::base64_decode(accepted["buckets"][0]["blob"].as_str().unwrap()).unwrap(), &vek).unwrap();
+ let plain = crypto::symmetric_decrypt_bytes(&crate::common::encoding::base64_decode(accepted["buckets"][0]["blob"].as_str().unwrap()).unwrap(), &vek).unwrap();
serde_json::from_str(&vault_codec::unpack_payload(&plain).unwrap()).unwrap()
};
assert_eq!(bucket["tables"]["ItemStats"].as_array().unwrap().len(), 2, "the other device's stats must survive: {}", bucket);
@@ -684,7 +684,7 @@ fn manifest_migration_of_a_dirty_pre_format_session_keeps_the_local_vault() {
let posts: Vec<_> = host.requests_to("Vault").into_iter().filter(|r| r.method == "POST").collect();
let body = posts[0].body.as_ref().unwrap();
assert_eq!(body["manifests"][0]["currentRevision"], 3, "the baseline still comes from the server");
- let manifest_json = crypto::symmetric_decrypt_bytes(&crate::encoding::base64_decode(body["manifests"][0]["manifestBlob"].as_str().unwrap()).unwrap(), &host.vault_key).unwrap();
+ let manifest_json = crypto::symmetric_decrypt_bytes(&crate::common::encoding::base64_decode(body["manifests"][0]["manifestBlob"].as_str().unwrap()).unwrap(), &host.vault_key).unwrap();
assert!(vault_codec::unpack_payload(&manifest_json).unwrap().contains("Local item"), "the push carries the local changes");
}
diff --git a/core/rust/src/vault_sync/tests/test_host.rs b/core/rust/src/vault_sync/tests/test_host.rs
index 67600c9f3..9d9a8d058 100644
--- a/core/rust/src/vault_sync/tests/test_host.rs
+++ b/core/rust/src/vault_sync/tests/test_host.rs
@@ -6,7 +6,7 @@ use rusqlite::{Connection, MAIN_DB};
use serde_json::{json, Map, Value};
use crate::crypto;
-use crate::encoding::{base64_decode, base64_encode};
+use crate::common::encoding::{base64_decode, base64_encode};
use crate::sqlite_host::{self, SqlStatement};
use crate::vault_sync::types::{Command, Db};
use crate::vault_sync::session::SyncSession;
diff --git a/core/rust/src/vault_sync/tests/unloaded_blobs.rs b/core/rust/src/vault_sync/tests/unloaded_blobs.rs
index e7b8966c3..556318dc1 100644
--- a/core/rust/src/vault_sync/tests/unloaded_blobs.rs
+++ b/core/rust/src/vault_sync/tests/unloaded_blobs.rs
@@ -32,7 +32,7 @@ impl ServerBlob {
fn server_db(host: &TestHost) -> rusqlite::Connection {
let db = test_host::open_schema_db(&host.schema_sql);
insert_item(&db, ITEM_ID, "Server item", PERSONAL_MANIFEST_ID);
- let now = crate::timestamp::now_vault_datetime();
+ let now = crate::common::timestamp::now_vault_datetime();
db.execute("INSERT INTO Logos (ManifestId, Id, Source, FileData, Kind, CreatedAt, UpdatedAt, IsDeleted) VALUES (?, 'bbbbbbbb-0000-4000-8000-000000000001', 'example.com', ?, 'favicon', ?, ?, 0)", rusqlite::params![PERSONAL_MANIFEST_ID, vec![1u8, 2, 3, 4], now, now]).unwrap();
db.execute("UPDATE Items SET LogoId = 'bbbbbbbb-0000-4000-8000-000000000001'", []).unwrap();
db.execute("INSERT INTO Attachments (ManifestId, Id, ItemId, Filename, Blob, CreatedAt, UpdatedAt, IsDeleted) VALUES (?, 'cccccccc-0000-4000-8000-000000000001', ?, 'passport.pdf', ?, ?, ?, 0)", rusqlite::params![PERSONAL_MANIFEST_ID, ITEM_ID, vec![9u8; 64], now, now]).unwrap();
@@ -54,7 +54,7 @@ fn snapshot(conn: &rusqlite::Connection, vek: &str, blob_key: &str, salt: &str,
.blobs
.iter()
.map(|(hash, b)| {
- let encrypted = blob_keys::encrypt_blob(&crate::encoding::base64_decode(&b.bytes_base64).unwrap(), blob_key).unwrap();
+ let encrypted = blob_keys::encrypt_blob(&crate::common::encoding::base64_decode(&b.bytes_base64).unwrap(), blob_key).unwrap();
ServerBlob { hash: hash.clone(), kind: b.kind.clone(), ciphertext: encrypted.encrypted_data_base64, encrypted_blob_key: encrypted.encrypted_blob_key }
})
.collect();
@@ -222,7 +222,7 @@ fn a_key_migration_push_is_refused_while_a_personal_blob_is_not_loaded() {
let kek = crypto::generate_key_base64();
let mut host = TestHost::new(&kek);
insert_item(&host.local, ITEM_ID, "Old item", PERSONAL_MANIFEST_ID);
- let now = crate::timestamp::now_vault_datetime();
+ let now = crate::common::timestamp::now_vault_datetime();
host.local.execute("INSERT INTO Attachments (ManifestId, Id, ItemId, Filename, Blob, BlobHash, CreatedAt, UpdatedAt, IsDeleted) VALUES (?, 'cccccccc-0000-4000-8000-000000000001', ?, 'passport.pdf', NULL, 'hash-of-a-blob-that-is-not-loaded', ?, ?, 0)", rusqlite::params![PERSONAL_MANIFEST_ID, ITEM_ID, now, now]).unwrap();
host.store_local_as_blob();
host.state.insert(state::SERVER_MANIFEST_REVISIONS.to_string(), json!({ PERSONAL_MANIFEST_ID: 3 }));