onetime_cli/config.rs
1use std::path::PathBuf;
2
3/// Configuration passed to [`encrypt_file`](crate::encrypt_file) or [`decrypt_file`](crate::decrypt_file)
4#[derive(Clone)]
5pub struct Config {
6 /// File to be encrypted
7 pub file: PathBuf,
8
9 /// Suffix for the name of the first input/output file
10 pub suffix1: String,
11
12 /// Suffix for the name of the second input/output file
13 pub suffix2: String,
14
15 /// Buffer size in bytes
16 pub buffer: u32,
17
18 /// Delete input file after encryption
19 pub rm: bool,
20
21 /// Don't print anything to stdout
22 pub quiet: bool,
23}
24
25impl Config {
26 /// Constructs a new `Config` with the given file(-path).
27 /// Other fields are filled with default values.
28 pub fn new(file: &str) -> Self {
29 Self {
30 file: PathBuf::from(file),
31 ..Config::default()
32 }
33 }
34
35 /// Constructs a new `Config` with the given file(-path)
36 /// and suffixes. Other fields are filled with
37 /// default values.
38 pub fn new_with_suffixes(file: &str, suffix1: &str, suffix2: &str) -> Self {
39 Self {
40 file: PathBuf::from(file),
41 suffix1: suffix1.to_string(),
42 suffix2: suffix2.to_string(),
43 ..Config::default()
44 }
45 }
46
47 fn default() -> Self {
48 Self {
49 file: PathBuf::new(),
50 suffix1: "otp.0".to_string(),
51 suffix2: "otp.1".to_string(),
52 buffer: 1048576,
53 rm: false,
54 quiet: true,
55 }
56 }
57}