Skip to content

Commit

Permalink
feature!: a fuck ton. (#6)
Browse files Browse the repository at this point in the history
* feature!: to be honest, it's a big commit and i've forgotten most of it
  • Loading branch information
greendoescode authored Jun 25, 2024
1 parent 42709b0 commit c5773a7
Show file tree
Hide file tree
Showing 54 changed files with 230 additions and 1,136 deletions.
919 changes: 0 additions & 919 deletions Cargo.lock

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions crates/volaris-cli/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "volaris-cli"
version = "0.0.1"
version = "0.0.2"
authors = ["brxken128 <[email protected]>", "greendoescode <[email protected]>"]
readme = "README.md"
edition = "2021"
Expand All @@ -19,8 +19,8 @@ maintenance = { status = "actively-developed" }
blake3 = "1.3.3"
rand = "0.8.5"

domain = { package = "volaris-domain", version = "0.0.1", path = "../volaris-domain" }
core = { package = "volaris-core", path = "../volaris-core", version = "0.0.1" }
tools = { package = "volaris-tools", version = "0.0.1", path = "../volaris-tools" }
corecrypto = { package = "volaris-crypto", path = "../volaris-crypto", version = "0.0.1" }

clap = { version = "3.2.21", features = ["cargo"] }
anyhow = "1.0.65"
Expand Down
2 changes: 1 addition & 1 deletion crates/volaris-cli/README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# Volaris
![GitHub License](https://img.shields.io/github/license/volarisapp/Volaris) ![GitHub Issues](https://img.shields.io/github/issues/volarisapp/Volaris) ![GitHub Stars](https://img.shields.io/github/stars/volarisapp/Volaris)
![GitHub License](https://img.shields.io/github/license/volar-is/Volaris) ![GitHub Issues](https://img.shields.io/github/issues/volar-is/Volaris) ![GitHub Stars](https://img.shields.io/github/stars/volar-is/Volaris)

## Introduction

Expand Down
4 changes: 2 additions & 2 deletions crates/volaris-cli/src/cli/prompt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ use crate::{
question, warn,
};

use core::protected::Protected;
use core::Zeroize;
use corecrypto::protected::Protected;
use corecrypto::Zeroize;

// this handles user-interactivity, specifically getting a "yes" or "no" answer from the user
// it requires the question itself, if the default is true/false
Expand Down
4 changes: 2 additions & 2 deletions crates/volaris-cli/src/global/parameters.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ use crate::global::structs::PackParams;
use crate::warn;
use anyhow::{Context, Result};
use clap::ArgMatches;
use core::header::{HashingAlgorithm, ARGON2ID_LATEST, BLAKE3BALLOON_LATEST};
use core::primitives::Algorithm;
use corecrypto::header::{HashingAlgorithm, ARGON2ID_LATEST, BLAKE3BALLOON_LATEST};
use corecrypto::primitives::Algorithm;

use super::states::{Compression, DirectoryMode, Key, KeyParams, PrintMode};
use super::structs::KeyManipulationParams;
Expand Down
4 changes: 2 additions & 2 deletions crates/volaris-cli/src/global/states.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@

use anyhow::{Context, Result};
use clap::ArgMatches;
use core::protected::Protected;
use corecrypto::protected::Protected;

use crate::cli::prompt::get_password;
use crate::warn;
use core::key::generate_passphrase;
use corecrypto::key::generate_passphrase;

#[derive(PartialEq, Eq, Clone, Copy)]
pub enum DirectoryMode {
Expand Down
2 changes: 1 addition & 1 deletion crates/volaris-cli/src/global/structs.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use core::header::HashingAlgorithm;
use corecrypto::header::HashingAlgorithm;

use crate::global::states::{ForceMode, HashMode};

Expand Down
8 changes: 4 additions & 4 deletions crates/volaris-cli/src/subcommands/decrypt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,16 @@ use crate::global::structs::CryptoParams;

use anyhow::Result;

use domain::storage::Storage;
use tools::storage::Storage;

// this function is for decrypting a file in stream mode
// it handles any user-facing interactiveness, opening files, or redirecting to memory mode if
// the header says so (backwards-compat)
// it also manages using a detached header file if selected
// it creates the stream object and uses the convenience function provided by volaris-core
// it creates the stream object and uses the convenience function provided by volaris-crypto
pub fn stream_mode(input: &str, output: &str, params: &CryptoParams) -> Result<()> {
// TODO: It is necessary to raise it to a higher level
let stor = Arc::new(domain::storage::FileStorage);
let stor = Arc::new(tools::storage::FileStorage);

// 1. validate and prepare options
if input == output {
Expand All @@ -41,7 +41,7 @@ pub fn stream_mode(input: &str, output: &str, params: &CryptoParams) -> Result<(
.or_else(|_| stor.write_file(output))?;

// 2. decrypt file
domain::decrypt::execute(domain::decrypt::Request {
tools::decrypt::execute(tools::decrypt::Request {
header_reader: header_file.as_ref().and_then(|h| h.try_reader().ok()),
reader: input_file.try_reader()?,
writer: output_file.try_writer()?,
Expand Down
14 changes: 7 additions & 7 deletions crates/volaris-cli/src/subcommands/encrypt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,24 +2,24 @@ use crate::cli::prompt::overwrite_check;
use crate::global::states::{EraseMode, HashMode, HeaderLocation, PasswordState};
use crate::global::structs::CryptoParams;
use anyhow::Result;
use core::header::{HeaderType, HEADER_VERSION};
use core::primitives::{Algorithm, Mode};
use corecrypto::header::{HeaderType, HEADER_VERSION};
use corecrypto::primitives::{Algorithm, Mode};
use std::process::exit;
use std::sync::Arc;

use domain::storage::Storage;
use tools::storage::Storage;

// this function is for encrypting a file in stream mode
// it handles any user-facing interactiveness, opening files
// it creates the stream object and uses the convenience function provided by volaris-core
// it creates the stream object and uses the convenience function provided by volaris-crypto
pub fn stream_mode(
input: &str,
output: &str,
params: &CryptoParams,
algorithm: Algorithm,
) -> Result<()> {
// TODO: It is necessary to raise it to a higher level
let stor = Arc::new(domain::storage::FileStorage);
let stor = Arc::new(tools::storage::FileStorage);

// 1. validate and prepare options
if input == output {
Expand Down Expand Up @@ -50,7 +50,7 @@ pub fn stream_mode(
};

// 2. encrypt file
let req = domain::encrypt::Request {
let req = tools::encrypt::Request {
reader: input_file.try_reader()?,
writer: output_file.try_writer()?,
header_writer: header_file.as_ref().and_then(|f| f.try_writer().ok()),
Expand All @@ -62,7 +62,7 @@ pub fn stream_mode(
},
hashing_algorithm: params.hashing_algorithm,
};
domain::encrypt::execute(req)?;
tools::encrypt::execute(req)?;

// 3. flush result
if let Some(header_file) = header_file {
Expand Down
12 changes: 6 additions & 6 deletions crates/volaris-cli/src/subcommands/erase.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use anyhow::Result;
use domain::storage::Storage;
use tools::storage::Storage;
use std::sync::Arc;

use crate::global::states::ForceMode;
Expand All @@ -12,7 +12,7 @@ use crate::cli::prompt::get_answer;
#[allow(clippy::module_name_repetitions)]
pub fn secure_erase(input: &str, passes: i32, force: ForceMode) -> Result<()> {
// TODO: It is necessary to raise it to a higher level
let stor = Arc::new(domain::storage::FileStorage);
let stor = Arc::new(tools::storage::FileStorage);

let file = stor.read_file(input)?;
if file.is_dir()
Expand All @@ -26,17 +26,17 @@ pub fn secure_erase(input: &str, passes: i32, force: ForceMode) -> Result<()> {
}

if file.is_dir() {
domain::erase_dir::execute(
tools::erase_dir::execute(
stor,
domain::erase_dir::Request {
tools::erase_dir::Request {
entry: file,
passes,
},
)?;
} else {
domain::erase::execute(
tools::erase::execute(
stor,
domain::erase::Request {
tools::erase::Request {
path: input,
passes,
},
Expand Down
6 changes: 3 additions & 3 deletions crates/volaris-cli/src/subcommands/hashing.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@ pub fn hash_stream(files: &[String]) -> Result<()> {
let mut input_file = std::fs::File::open(input)
.with_context(|| format!("Unable to open file: {}", input))?;

let hash = domain::hash::execute(
domain::hasher::Blake3Hasher::default(),
domain::hash::Request {
let hash = tools::hash::execute(
tools::hasher::Blake3Hasher::default(),
tools::hash::Request {
reader: RefCell::new(&mut input_file),
},
)?;
Expand Down
24 changes: 12 additions & 12 deletions crates/volaris-cli/src/subcommands/header.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@ use std::{
use crate::cli::prompt::overwrite_check;
use crate::global::states::ForceMode;
use anyhow::{Context, Result};
use core::header::HashingAlgorithm;
use core::header::{Header, HeaderVersion};
use domain::storage::Storage;
use domain::utils::hex_encode;
use corecrypto::header::HashingAlgorithm;
use corecrypto::header::{Header, HeaderVersion};
use tools::storage::Storage;
use tools::utils::hex_encode;

pub fn details(input: &str) -> Result<()> {
let mut input_file =
Expand Down Expand Up @@ -65,7 +65,7 @@ pub fn details(input: &str) -> Result<()> {
// it's used for extracting an encrypted file's header for backups and such
// it implements a check to ensure the header is valid
pub fn dump(input: &str, output: &str, force: ForceMode) -> Result<()> {
let stor = std::sync::Arc::new(domain::storage::FileStorage);
let stor = std::sync::Arc::new(tools::storage::FileStorage);
let input_file = stor.read_file(input)?;

if !overwrite_check(output, force)? {
Expand All @@ -76,12 +76,12 @@ pub fn dump(input: &str, output: &str, force: ForceMode) -> Result<()> {
.create_file(output)
.or_else(|_| stor.write_file(output))?;

let req = domain::header::dump::Request {
let req = tools::header::dump::Request {
reader: input_file.try_reader()?,
writer: output_file.try_writer()?,
};

domain::header::dump::execute(req)?;
tools::header::dump::execute(req)?;

stor.flush_file(&output_file)?;

Expand All @@ -94,7 +94,7 @@ pub fn dump(input: &str, output: &str, force: ForceMode) -> Result<()> {
// this does not work for files encrypted *with* a detached header
// it implements a check to ensure the header is valid before restoring to a file
pub fn restore(input: &str, output: &str) -> Result<()> {
let stor = std::sync::Arc::new(domain::storage::FileStorage);
let stor = std::sync::Arc::new(tools::storage::FileStorage);

let input_file = stor.read_file(input)?;

Expand All @@ -106,12 +106,12 @@ pub fn restore(input: &str, output: &str) -> Result<()> {
.with_context(|| format!("Unable to open output file: {}", output))?,
);

let req = domain::header::restore::Request {
let req = tools::header::restore::Request {
reader: input_file.try_reader()?,
writer: &output_file,
};

domain::header::restore::execute(req)?;
tools::header::restore::execute(req)?;

Ok(())
}
Expand All @@ -129,11 +129,11 @@ pub fn strip(input: &str) -> Result<()> {
.with_context(|| format!("Unable to open input file: {}", input))?,
);

let req = domain::header::strip::Request {
let req = tools::header::strip::Request {
handle: &input_file,
};

domain::header::strip::execute(req)?;
tools::header::strip::execute(req)?;

Ok(())
}
12 changes: 6 additions & 6 deletions crates/volaris-cli/src/subcommands/key.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ use crate::global::states::Key;
use crate::global::states::PasswordState;
use crate::global::structs::KeyManipulationParams;
use anyhow::{Context, Result};
use core::header::Header;
use core::header::HeaderVersion;
use corecrypto::header::Header;
use corecrypto::header::HeaderVersion;
use std::cell::RefCell;
use std::fs::OpenOptions;
use std::io::Seek;
Expand Down Expand Up @@ -45,7 +45,7 @@ pub fn add(input: &str, params: &KeyManipulationParams) -> Result<()> {

let raw_key_new = params.key_new.get_secret(&PasswordState::Validate)?;

domain::key::add::execute(domain::key::add::Request {
tools::key::add::execute(tools::key::add::Request {
handle: &input_file,
hash_algorithm: params.hashing_algorithm,
raw_key_old,
Expand Down Expand Up @@ -89,7 +89,7 @@ pub fn change(input: &str, params: &KeyManipulationParams) -> Result<()> {

let raw_key_new = params.key_new.get_secret(&PasswordState::Validate)?;

domain::key::change::execute(domain::key::change::Request {
tools::key::change::execute(tools::key::change::Request {
handle: &input_file,
hash_algorithm: params.hashing_algorithm,
raw_key_old,
Expand Down Expand Up @@ -127,7 +127,7 @@ pub fn delete(input: &str, key_old: &Key) -> Result<()> {

let raw_key_old = key_old.get_secret(&PasswordState::Direct)?;

domain::key::delete::execute(domain::key::delete::Request {
tools::key::delete::execute(tools::key::delete::Request {
handle: &input_file,
raw_key_old,
})?;
Expand Down Expand Up @@ -162,7 +162,7 @@ pub fn verify(input: &str, key: &Key) -> Result<()> {

let raw_key = key.get_secret(&PasswordState::Direct)?;

domain::key::verify::execute(domain::key::verify::Request {
tools::key::verify::execute(tools::key::verify::Request {
handle: &input_file,
raw_key,
})?;
Expand Down
12 changes: 6 additions & 6 deletions crates/volaris-cli/src/subcommands/pack.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ use std::process::exit;
use std::sync::Arc;

use anyhow::Result;
use core::header::{HeaderType, HEADER_VERSION};
use core::primitives::{Algorithm, Mode};
use corecrypto::header::{HeaderType, HEADER_VERSION};
use corecrypto::primitives::{Algorithm, Mode};

use crate::global::states::{HashMode, HeaderLocation, PasswordState};
use crate::{
Expand All @@ -14,7 +14,7 @@ use crate::{
structs::{CryptoParams, PackParams},
},
};
use domain::storage::Storage;
use tools::storage::Storage;

use crate::cli::prompt::overwrite_check;

Expand All @@ -33,7 +33,7 @@ pub struct Request<'a> {
// it erases the temporary archive afterwards, to stop any residual data from remaining
pub fn execute(req: &Request) -> Result<()> {
// TODO: It is necessary to raise it to a higher level
let stor = Arc::new(domain::storage::FileStorage);
let stor = Arc::new(tools::storage::FileStorage);

// 1. validate and prepare options
if req.input_file.iter().any(|f| f == req.output_file) {
Expand Down Expand Up @@ -92,9 +92,9 @@ pub fn execute(req: &Request) -> Result<()> {
};

// 2. compress and encrypt files
domain::pack::execute(
tools::pack::execute(
stor.clone(),
domain::pack::Request {
tools::pack::Request {
compress_files,
compression_method,
writer: output_file.try_writer()?,
Expand Down
8 changes: 4 additions & 4 deletions crates/volaris-cli/src/subcommands/unpack.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use std::sync::Arc;

use anyhow::Result;

use domain::storage::Storage;
use tools::storage::Storage;

use crate::global::{
states::{HeaderLocation, PasswordState, PrintMode},
Expand All @@ -24,7 +24,7 @@ pub fn unpack(
params: CryptoParams, // params for decrypt function
) -> Result<()> {
// TODO: It is necessary to raise it to a higher level
let stor = Arc::new(domain::storage::FileStorage);
let stor = Arc::new(tools::storage::FileStorage);

let input_file = stor.read_file(input)?;
let header_file = match &params.header_location {
Expand All @@ -34,9 +34,9 @@ pub fn unpack(

let raw_key = params.key.get_secret(&PasswordState::Direct)?;

domain::unpack::execute(
tools::unpack::execute(
stor,
domain::unpack::Request {
tools::unpack::Request {
header_reader: header_file.as_ref().and_then(|h| h.try_reader().ok()),
reader: input_file.try_reader()?,
output_dir_path: PathBuf::from(output),
Expand Down
Loading

0 comments on commit c5773a7

Please sign in to comment.