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
use bc_xid::XIDPrivateKeyOptions;
use clap::ValueEnum;
#[derive(ValueEnum, Copy, Clone, Debug, PartialEq, Eq, Default)]
pub enum PrivateOptions {
/// Include the private key in plaintext
#[default]
Include,
/// Omit the private key
Omit,
/// Elide the private key (maintains digest tree)
Elide,
/// Encrypt the private key with a password
Encrypt,
}
impl PrivateOptions {
/// Check if this option requires encryption.
pub fn is_encrypt(&self) -> bool { matches!(self, PrivateOptions::Encrypt) }
}
impl From<PrivateOptions> for XIDPrivateKeyOptions {
fn from(options: PrivateOptions) -> Self {
match options {
PrivateOptions::Omit => XIDPrivateKeyOptions::Omit,
PrivateOptions::Include => XIDPrivateKeyOptions::Include,
PrivateOptions::Elide => XIDPrivateKeyOptions::Elide,
// The Encrypt variant needs additional parameters, so this is a
// placeholder. Callers should use the password_args module to
// construct the full PrivateKeyOptions::Encrypt variant.
PrivateOptions::Encrypt => XIDPrivateKeyOptions::Omit,
}
}
}