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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
|
use clap::{ArgEnum, Args, Parser, Subcommand};
use crate::sq_cli::types::IoArgs;
#[derive(Parser, Debug)]
#[clap(
name = "autocrypt",
about = "Communicates certificates using Autocrypt",
long_about = "Communicates certificates using Autocrypt
Autocrypt is a standard for mail user agents to provide convenient
end-to-end encryption of emails. This subcommand provides a limited
way to produce and consume headers that are used by Autocrypt to
communicate certificates between clients.
See https://autocrypt.org/
",
subcommand_required = true,
arg_required_else_help = true
)]
pub struct Command {
#[clap(subcommand)]
pub subcommand: Subcommands,
}
#[derive(Debug, Subcommand)]
pub enum Subcommands {
Decode(DecodeCommand),
EncodeSender(EncodeSenderCommand),
}
#[derive(Debug, Args)]
#[clap(
about = "Reads Autocrypt-encoded certificates",
long_about = "Reads Autocrypt-encoded certificates
Given an autocrypt header (or an key-gossip header), this command
extracts the certificate encoded within it.
The converse operation is \"sq autocrypt encode-sender\".
",
after_help = "EXAMPLES:
# Extract all certificates from a mail
$ sq autocrypt decode autocrypt.eml
"
)]
pub struct DecodeCommand {
#[clap(flatten)]
pub io: IoArgs,
#[clap(short = 'B', long, help = "Emits binary data")]
pub binary: bool,
}
//#[derive(Subcommand)]
#[derive(Debug, Args)]
#[clap(
name = "encode-sender",
about = "Encodes a certificate into an Autocrypt header",
long_about = "Encodes a certificate into an Autocrypt header
A certificate can be encoded and included in a header of an email
message. This command encodes the certificate, adds the senders email
address (which must match the one used in the \"From\" header), and the
senders \"prefer-encrypt\" state (see the Autocrypt spec for more
information).
The converse operation is \"sq autocrypt decode\".
",
after_help = "EXAMPLES:
# Encodes a certificate
$ sq autocrypt encode-sender juliet.pgp
# Encodes a certificate with an explicit sender address
$ sq autocrypt encode-sender --email juliet@example.org juliet.pgp
# Encodes a certificate while indicating the willingness to encrypt
$ sq autocrypt encode-sender --prefer-encrypt mutual juliet.pgp
"
)]
pub struct EncodeSenderCommand {
#[clap(flatten)]
pub io: IoArgs,
// TODO the help message looks like "primary userid" might be the default
// email. clarify
#[clap(
long = "email",
value_name = "ADDRESS",
help = "Sets the address [default: primary userid]"
)]
pub address: Option<String>,
#[clap(
long = "prefer-encrypt",
value_name = "PREFER-ENCRYPT",
default_value_t = PreferEncryptArgs::NoPreference,
help = "Sets the prefer-encrypt attribute",
arg_enum,
)]
pub prefer_encrypt: PreferEncryptArgs,
}
#[derive(ArgEnum, Debug, Clone)]
pub enum PreferEncryptArgs {
#[clap(name = "nopreference")]
NoPreference,
Mutual,
}
impl std::fmt::Display for PreferEncryptArgs {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match self {
PreferEncryptArgs::Mutual => write!(f, "mutual"),
PreferEncryptArgs::NoPreference => write!(f, "nopreference"),
}
}
}
|