From 4baf42957422bde1c6ad29d97481cd37d1057255 Mon Sep 17 00:00:00 2001 From: Hatter Jiang Date: Thu, 9 Feb 2023 22:34:50 +0800 Subject: [PATCH] feat: claps --- Cargo.toml | 5 +++++ src/lib.rs | 2 -- src/main.rs | 46 ++++++++++++++++++++++++++++++++++++++++++++++ src/spec.rs | 36 ++++++++++++++++++++++++++++++++++++ 4 files changed, 87 insertions(+), 2 deletions(-) delete mode 100644 src/lib.rs create mode 100644 src/main.rs create mode 100644 src/spec.rs diff --git a/Cargo.toml b/Cargo.toml index 3378d01..04177eb 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -8,3 +8,8 @@ description = "A simple and tiny file encrypt tool" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html [dependencies] +clap = { version = "4.1.4", features = ["derive"] } +hex = "0.4.3" +rust_util = "0.6.41" +serde = { version = "1.0.152", features = ["derive"] } +serde_json = "1.0.93" diff --git a/src/lib.rs b/src/lib.rs deleted file mode 100644 index ead011a..0000000 --- a/src/lib.rs +++ /dev/null @@ -1,2 +0,0 @@ - -pub fn tiny_encrypt() {} diff --git a/src/main.rs b/src/main.rs new file mode 100644 index 0000000..693f318 --- /dev/null +++ b/src/main.rs @@ -0,0 +1,46 @@ +use std::path::PathBuf; + +use clap::{Parser, Subcommand}; +use rust_util::information; + +mod spec; + +#[derive(Debug, Parser)] +#[command(name = "tiny-encrypt-rs")] +#[command(about = "A tiny encrypt client in Rust", long_about = None)] +struct Cli { + #[command(subcommand)] + command: Commands, +} + +#[derive(Debug, Subcommand)] +enum Commands { + /// Encrypt file(s) + #[command(arg_required_else_help = true, short_flag = 'e')] + Encrypt { + /// Files need to be encrypted + files: Vec, + }, + /// Decrypt file(s) + #[command(arg_required_else_help = true, short_flag = 'd')] + Decrypt { + /// Files need to be decrypted + files: Vec, + }, + /// Show file info + #[command(arg_required_else_help = true, short_flag = 'i')] + Info { + file: PathBuf, + }, +} + +fn main() { + let args = Cli::parse(); + match args.command { + Commands::Encrypt { files } => { + files.iter().for_each(|f| information!("{:?}", f)); + } + Commands::Decrypt { .. } => todo!(), + Commands::Info { .. } => todo!() + } +} \ No newline at end of file diff --git a/src/spec.rs b/src/spec.rs new file mode 100644 index 0000000..0c9ef14 --- /dev/null +++ b/src/spec.rs @@ -0,0 +1,36 @@ +use serde::{Deserialize, Serialize}; + +// File format +// [MAGIC; 4 bytes][VERSION; 1 byte] +// [META_LENGTH; 4 bytes] +// [META; META_LENGTH bytes] +// [ENCRYPTED DATA; n bytes] + +pub const EXT: &'static str = "ers"; +pub const MAGIC: u16 = 0xECF0; + +pub const VERSION_1: u8 = 0x01; + +#[derive(Clone, Debug, Serialize, Deserialize)] +pub struct MetaBock { + pub meta_random_hex: String, + pub desc: Option, + pub encrypted_desc: String, + pub keys: Vec, + pub iv_nonce_hex: String, +} + +#[derive(Clone, Debug, Serialize, Deserialize)] +pub struct DescBlock { + pub file_id: Option, + pub author: Option, + pub description: Option, +} + +#[derive(Clone, Debug, Serialize, Deserialize)] +pub struct KeyBlock { + pub key_id: Option, + pub encrypted_key_hex: String, + pub key_verification_code_hex: String, + pub extended_information: Option, +} \ No newline at end of file