1#![forbid(unsafe_code)]
2
3pub mod cli;
4
5mod file;
6mod io;
7mod password;
8mod enc;
9mod dec;
10mod chaff;
11
12#[cfg(test)]
13mod tests;
14
15const DEFINITE_BAR_STYLE: &str = "[{elapsed_precise}] {binary_bytes_per_sec} {bar} {binary_bytes}/{binary_total_bytes} ({eta})";
16const INDEFINITE_BAR_STYLE: &str = "[{elapsed_precise}] {binary_bytes_per_sec} ({eta})";
17
18#[inline]
19fn handle_err(result: Result<(), ()>) -> std::process::ExitCode {
20 match result {
21 Ok(()) => std::process::ExitCode::SUCCESS,
22 Err(()) => std::process::ExitCode::FAILURE
23 }
24}
25
26async fn run_with_io<B: io::IoBundle>(cli: cli::Cli, io: B) -> std::process::ExitCode {
27 match cli.command {
28 cli::Command::Enc(args) => handle_err(enc::enc(args, io).await),
29 cli::Command::Dec(args) => handle_err(dec::dec_file(args, io).await),
30 cli::Command::Fetch(args) => handle_err(dec::dec_fetch(args, io).await),
31 cli::Command::Chaff(args) => handle_err(chaff::chaff(args).await),
32 }
33}
34
35pub async fn run(cli: cli::Cli) -> std::process::ExitCode {
36 run_with_io(cli, io::InteractiveIo).await
37}