-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.rs
78 lines (77 loc) · 2.87 KB
/
main.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
use clap::Parser;
use rcli::{
process_csv, process_decode, process_encode, process_genpass, process_http_serve,
process_text_generate, process_text_sign, process_text_verify, Base64SubCommand,
HttpSubCommand, Opts, SubCommand, TextSignFormat, TextSubCommand,
};
use std::fs;
use zxcvbn::zxcvbn;
#[tokio::main]
async fn main() -> anyhow::Result<()> {
tracing_subscriber::fmt::init();
let opts = Opts::parse();
match opts.cmd {
SubCommand::Csv(opts) => {
let output = if let Some(output) = opts.output {
output.clone()
} else {
format!("output.{}", opts.format)
};
process_csv(&opts.input, output, opts.format)?
}
SubCommand::GenPass(opts) => {
let password = process_genpass(
opts.length,
opts.uppercase,
opts.lowercase,
opts.numbers,
opts.symbol,
)?;
println!("{}", password);
// output password strength in stderr
let estimate = zxcvbn(&password, &[]);
eprintln!("Password strength: {}", estimate.score());
}
SubCommand::Base64(subcmd) => match subcmd {
Base64SubCommand::Encode(opts) => {
let encoded = process_encode(&opts.input, opts.format)?;
println!("{}", encoded);
}
Base64SubCommand::Decode(opts) => {
let decoded = process_decode(&opts.input, opts.format)?;
let decoded = String::from_utf8(decoded)?;
println!("{}", decoded);
}
},
SubCommand::Text(subcmd) => match subcmd {
TextSubCommand::Sign(opts) => {
let sig = process_text_sign(&opts.input, &opts.key, opts.format)?;
println!("{}", sig);
}
TextSubCommand::Verify(opts) => {
let verified = process_text_verify(&opts.input, &opts.key, opts.format, &opts.sig)?;
println!("{}", verified);
}
TextSubCommand::Generate(opts) => {
let key = process_text_generate(opts.format)?;
match opts.format {
TextSignFormat::Blake3 => {
let name = opts.output.join("blake3.txt");
fs::write(name, &key[0])?;
}
TextSignFormat::Ed25519 => {
let name = opts.output;
fs::write(name.join("ed25519.sk"), &key[0])?;
fs::write(name.join("ed25519.pk"), &key[1])?;
}
}
}
},
SubCommand::Http(cmd) => match cmd {
HttpSubCommand::Serve(opts) => {
process_http_serve(opts.dir, opts.port).await?;
}
},
}
Ok(())
}