feat: claps
This commit is contained in:
@@ -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"
|
||||
|
||||
@@ -1,2 +0,0 @@
|
||||
|
||||
pub fn tiny_encrypt() {}
|
||||
46
src/main.rs
Normal file
46
src/main.rs
Normal file
@@ -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<PathBuf>,
|
||||
},
|
||||
/// Decrypt file(s)
|
||||
#[command(arg_required_else_help = true, short_flag = 'd')]
|
||||
Decrypt {
|
||||
/// Files need to be decrypted
|
||||
files: Vec<PathBuf>,
|
||||
},
|
||||
/// 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!()
|
||||
}
|
||||
}
|
||||
36
src/spec.rs
Normal file
36
src/spec.rs
Normal file
@@ -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<DescBlock>,
|
||||
pub encrypted_desc: String,
|
||||
pub keys: Vec<KeyBlock>,
|
||||
pub iv_nonce_hex: String,
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, Serialize, Deserialize)]
|
||||
pub struct DescBlock {
|
||||
pub file_id: Option<String>,
|
||||
pub author: Option<String>,
|
||||
pub description: Option<String>,
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, Serialize, Deserialize)]
|
||||
pub struct KeyBlock {
|
||||
pub key_id: Option<String>,
|
||||
pub encrypted_key_hex: String,
|
||||
pub key_verification_code_hex: String,
|
||||
pub extended_information: Option<String>,
|
||||
}
|
||||
Reference in New Issue
Block a user