π End-to-end encrypted cloud for everything.
Dart 2faandroidauthye2eeencryptionend-to-end-encryptionfluttergolanggoogle-photosgoogle-photos-alternativeiosopensourcephotosprivacyprivacy-toolstypescriptzero-knowledge
Remove duplicated Space base64 helpers
Neeraj Guptacf5792d5942e
diff --git a/rust/Cargo.lock b/rust/Cargo.lockindex 760c12aa7c..69aab155a8 100644--- a/rust/Cargo.lock+++ b/rust/Cargo.lock@@ -2634,7 +2634,6 @@ dependencies = [name = "ente-space"version = "0.0.1"dependencies = [- "base64 0.22.1","ente-core","md-5 0.11.0","mockito",diff --git a/rust/bindings/wasm/ente-wasm/src/space.rs b/rust/bindings/wasm/ente-wasm/src/space.rsindex 7768bf43cc..aab43db8a9 100644--- a/rust/bindings/wasm/ente-wasm/src/space.rs+++ b/rust/bindings/wasm/ente-wasm/src/space.rs@@ -1,12 +1,14 @@//! WASM bindings for space flows.-use ente_core::http::Error as HttpError;+use ente_core::{+ crypto::{decode_b64, encode_b64},+ http::Error as HttpError,+};use ente_space::{AccountSpaceCtx, CreatedSpace, CreatedSpaceLink, DecryptedMessage, DecryptedPost,DecryptedSpaceProfile, MessageConversationActivity, MessageConversationPost, MessageResponse,OpenAccountSpaceCtxInput, OpenSpaceLinkCtxInput, PostResponse, ProfileAvatarResponse,ProfileCoverResponse, SpaceActorResponse, SpaceError as CoreSpaceError, SpaceLinkCtx,- crypto::{decode_b64, encode_b64},};use serde::{Deserialize, Serialize};use serde_wasm_bindgen as swb;@@ -50,7 +52,6 @@ impl From<CoreSpaceError> for WasmSpaceError {CoreSpaceError::Http(HttpError::Parse(_)) => ("parse", None),CoreSpaceError::Crypto(_) => ("crypto", None),CoreSpaceError::Auth(_) => ("auth", None),- CoreSpaceError::Base64(_) => ("base64", None),CoreSpaceError::InvalidInput(_) => ("invalid_input", None),CoreSpaceError::MissingPrivateKey => ("missing_private_key", None),CoreSpaceError::MissingEncryptedSpaceKey => ("missing_encrypted_space_key", None),@@ -299,7 +300,9 @@ struct FriendRequestJs {}fn decode_b64_field(value: &str) -> Result<Vec<u8>, WasmSpaceError> {- decode_b64(value).map_err(Into::into)+ decode_b64(value)+ .map_err(CoreSpaceError::from)+ .map_err(Into::into)}fn utf8_field(bytes: Vec<u8>, field: &str) -> Result<String, WasmSpaceError> {diff --git a/rust/space/Cargo.toml b/rust/space/Cargo.tomlindex 7a96052afd..928a514486 100644--- a/rust/space/Cargo.toml+++ b/rust/space/Cargo.toml@@ -4,7 +4,6 @@ version = "0.0.1"edition = "2024"[dependencies]-base64 = "0.22"ente-core.workspace = truemd-5 = "0.11"reqwest = { version = "0.12", default-features = false, features = ["http2", "charset", "system-proxy", "json", "rustls-tls-native-roots", "rustls-tls-webpki-roots"] }diff --git a/rust/space/src/client.rs b/rust/space/src/client.rsindex c37d1281fe..d04a11c130 100644--- a/rust/space/src/client.rs+++ b/rust/space/src/client.rs@@ -4,8 +4,8 @@ use std::{};use crate::crypto::{- ASSET_PAYLOAD_OVERHEAD_BYTES, SECRETBOX_PAYLOAD_OVERHEAD_BYTES, content_md5_base64, decode_b64,- decrypt_secretbox_payload, derive_space_link_auth_key, derive_space_link_wrap_key, encode_b64,+ ASSET_PAYLOAD_OVERHEAD_BYTES, SECRETBOX_PAYLOAD_OVERHEAD_BYTES, content_md5_base64,+ decrypt_secretbox_payload, derive_space_link_auth_key, derive_space_link_wrap_key,encrypt_asset_payload, encrypt_secretbox_payload, generate_key, generate_keypair,generate_space_link_access_key, open_with_keypair, seal_with_public_key,space_link_access_key_material,@@ -32,7 +32,10 @@ use crate::transport::{UpdatePostCaptionRequest, UpdateSpaceProfileRequest, UpdateSpaceProfileResponse,UpdateSpaceSlugRequest,};-use ente_core::http::Error as HttpError;+use ente_core::{+ crypto::{decode_b64, encode_b64},+ http::Error as HttpError,+};const UPLOAD_PURPOSE_AVATAR: &str = "avatar";const UPLOAD_PURPOSE_COVER: &str = "cover";const MESSAGE_KIND_REGULAR: &str = "regular";diff --git a/rust/space/src/crypto.rs b/rust/space/src/crypto.rsindex bb4a7806c5..152a8de752 100644--- a/rust/space/src/crypto.rs+++ b/rust/space/src/crypto.rs@@ -1,13 +1,12 @@-use base64::{Engine, engine::general_purpose::STANDARD};-use ente_core::crypto::{Key, Nonce, PublicKey, SecretKey, blob, hash, kdf, sealed, secretbox};+use ente_core::crypto::{+ Key, Nonce, PublicKey, SecretKey, blob, encode_b64, hash, kdf, sealed, secretbox,+};use md5::{Digest, Md5};use crate::error::{Result, SpaceError};-pub const SECRETBOX_NONCE_BYTES: usize = Nonce::BYTES;-pub const SECRETBOX_MAC_BYTES: usize = secretbox::MAC_BYTES;-pub const SECRETBOX_PAYLOAD_OVERHEAD_BYTES: usize = SECRETBOX_NONCE_BYTES + SECRETBOX_MAC_BYTES;-pub const ASSET_PAYLOAD_OVERHEAD_BYTES: usize = blob::HEADER_BYTES + blob::ABYTES;+pub(crate) const SECRETBOX_PAYLOAD_OVERHEAD_BYTES: usize = Nonce::BYTES + secretbox::MAC_BYTES;+pub(crate) const ASSET_PAYLOAD_OVERHEAD_BYTES: usize = blob::HEADER_BYTES + blob::ABYTES;const SPACE_LINK_ACCESS_KEY_LEN: usize = 12;const SPACE_LINK_ACCESS_KEY_ALPHABET: &[u8] =b"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";@@ -92,19 +91,11 @@ pub fn space_link_access_key_material(access_key: &str) -> Result<Vec<u8>> {hash::hash_default(trimmed.as_bytes()).map_err(Into::into)}-pub fn encode_b64(bytes: &[u8]) -> String {- STANDARD.encode(bytes)-}-pub fn content_md5_base64(bytes: &[u8]) -> String {let digest = Md5::digest(bytes);encode_b64(&digest)}-pub fn decode_b64(value: &str) -> Result<Vec<u8>> {- Ok(STANDARD.decode(value.trim())?)-}-pub fn derive_space_link_auth_key(access_key: &[u8]) -> Result<Vec<u8>> {let access_key = Key::try_from_slice(access_key)?;Ok(kdf::derive_subkey(&access_key, kdf::KEY_BYTES, 1, SPACE_LINK_AUTH_KDF_CONTEXT)?.to_vec())diff --git a/rust/space/src/error.rs b/rust/space/src/error.rsindex 3acf5c1e1e..084eabd2b6 100644--- a/rust/space/src/error.rs+++ b/rust/space/src/error.rs@@ -1,4 +1,3 @@-use base64::DecodeError;use ente_core::{auth::AuthError, crypto::CryptoError, http::Error as HttpError};use thiserror::Error;@@ -13,9 +12,6 @@ pub enum SpaceError {#[error(transparent)]Auth(#[from] AuthError),- #[error(transparent)]- Base64(#[from] DecodeError),-#[error("invalid input: {0}")]InvalidInput(String),