Skip to content

Commit

Permalink
Extract vault crypto
Browse files Browse the repository at this point in the history
  • Loading branch information
bancek committed Dec 1, 2023
1 parent c55be50 commit 01de9d2
Show file tree
Hide file tree
Showing 44 changed files with 770 additions and 563 deletions.
25 changes: 21 additions & 4 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
members = [
"vault-core-tests",
"vault-core",
"vault-crypto",
"vault-fake-remote",
"vault-file-icon",
"vault-mobile",
Expand Down
1 change: 1 addition & 0 deletions vault-core-tests/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ similar-asserts = "1.5.0"
tokio = { version = "1.32.0", features = ["full"] }
uuid = { version = "1.4.1", features = ["v4", "fast-rng"] }
vault-core = { path = "../vault-core" }
vault-crypto = { path = "../vault-crypto" }
vault-fake-remote = { path = "../vault-fake-remote" }
vault-native = { path = "../vault-native" }
vault-store = { path = "../vault-store" }
11 changes: 4 additions & 7 deletions vault-core-tests/src/fixtures/repo_fixture.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,16 @@ use std::sync::Arc;

use futures::io::Cursor;
use vault_core::{
cipher::Cipher,
repo_files::{
self,
state::{RepoFile, RepoFilesUploadConflictResolution, RepoFilesUploadResult},
},
repos::state::RepoUnlockMode,
types::{
DecryptedName, DecryptedPath, EncryptedName, EncryptedPath, MountId, RemotePath,
RepoFileId, RepoId,
},
types::{DecryptedPath, EncryptedName, EncryptedPath, MountId, RemotePath, RepoFileId, RepoId},
utils::repo_encrypted_path_utils,
Vault,
};
use vault_crypto::Cipher;
use vault_fake_remote::fake_remote::context::Context;

use crate::{fake_remote::FakeRemote, fixtures::user_fixture::UserFixture};
Expand Down Expand Up @@ -104,11 +101,11 @@ impl RepoFixture {
}

pub fn encrypt_filename(&self, name: &str) -> EncryptedName {
self.cipher.encrypt_filename(&DecryptedName(name.into()))
EncryptedName(self.cipher.encrypt_filename(name))
}

pub fn encrypt_path(&self, path: &str) -> EncryptedPath {
self.cipher.encrypt_path(&DecryptedPath(path.into()))
EncryptedPath(self.cipher.encrypt_path(path))
}

pub fn get_file_id(&self, path: &str) -> RepoFileId {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -377,7 +377,9 @@ fn test_download_size_decryption_error() {
assert_eq!(
res,
Err(TransferError::DecryptSizeError(
DecryptSizeError::EncryptedFileTooShort
DecryptSizeError::DecryptSizeError(
vault_crypto::errors::DecryptSizeError::EncryptedFileTooShort
)
))
);

Expand Down Expand Up @@ -413,7 +415,9 @@ fn test_download_size_decryption_error() {
if let Some(location) = details.location.as_mut() {
location.content.status = Status::Error {
error: TransferError::DecryptSizeError(
DecryptSizeError::EncryptedFileTooShort,
DecryptSizeError::DecryptSizeError(
vault_crypto::errors::DecryptSizeError::EncryptedFileTooShort
)
),
loaded: false,
};
Expand Down
15 changes: 10 additions & 5 deletions vault-core-tests/tests/integration/repo_files_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,9 @@ fn test_encrypted_decrypted_same_name() {
fn test_invalid_name() {
with_repo(|fixture| {
async move {
fixture
// upload fails because after upload it tries to decrypt the name
// and the name is invalid
let _ = fixture
.vault
.repo_files_service
.clone()
Expand All @@ -256,8 +258,7 @@ fn test_invalid_name() {
RepoFilesUploadConflictResolution::Error,
None,
)
.await
.unwrap();
.await;

fixture
.vault
Expand Down Expand Up @@ -306,12 +307,16 @@ fn test_invalid_name() {
.0
)),
path: RepoFilePath::DecryptError {
error: DecryptFilenameError::InvalidName(InvalidNameError::new("A\n/\n")),
error: DecryptFilenameError::InvalidNameError(InvalidNameError::new(
"A\n/\n"
)),
},
name: RepoFileName::DecryptError {
encrypted_name: EncryptedName("A\\n/\\n".into()),
encrypted_name_lower: "a\\n/\\n".into(),
error: DecryptFilenameError::InvalidName(InvalidNameError::new("A\n/\n")),
error: DecryptFilenameError::InvalidNameError(InvalidNameError::new(
"A\n/\n"
)),
},
ext: None,
content_type: None,
Expand Down
8 changes: 1 addition & 7 deletions vault-core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,11 @@ version = "0.1.0"
edition = "2021"

[dependencies]
# eme-mode 0.2.1 does not compile with aes 0.8.1
aes = { version = "0.7.5", features = ["ctr"] }
async_zip_futures = { version = "0.0.12", features = ["chrono"] }
async-trait = "0.1.73"
bytes = "1.5.0"
chrono = { version = "0.4.31", default-features = false, features = ["clock"] }
data-encoding = "2.4.0"
# eme-mode 0.3 is not correct for inputs longer than 16 bytes
eme-mode = "0.2.1"
futures = { version = "0.3.28", features = ["executor"] }
http = "0.2.9"
http-body = "0.4.5"
Expand All @@ -23,8 +19,6 @@ phf = { version = "0.11.2", features = ["macros"] }
pin-project-lite = "0.2.13"
rand_core = "0.6.4"
rust-ini = "0.19.0"
# scrypt > 0.6 limits key len to 64, but we need 80, let's keep 0.2, it works
scrypt = { version = "0.2", default-features = false }
serde = { version = "1.0.188", features = ["derive"] }
serde_json = "1.0.107"
serde_urlencoded = "0.7.1"
Expand All @@ -33,8 +27,8 @@ thiserror = "1.0.49"
url = "2.4.1"
urlencoding = "2.1.3"
uuid = { version = "1.4.1", features = ["v4", "fast-rng"] }
vault-crypto = { path = "../vault-crypto" }
vault-store = { path = "../vault-store" }
xsalsa20poly1305 = "0.9.1"

[dev-dependencies]
futures-test = "0.3.28"
Expand Down
Loading

0 comments on commit 01de9d2

Please sign in to comment.