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
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
use clap::{Arg, ArgAction::SetTrue, Command};
pub fn parse_args() -> (clap::ArgMatches, String) {
let mut app = command!()
.subcommand(
Command::new("generate")
.about("Generate public and private keys")
.arg(
Arg::new("pk_path")
.short('p')
.long("public-key-path")
.num_args(1)
.value_name("PUBLIC_KEY_PATH")
.help("path to the new public key"),
)
.arg(
Arg::new("sk_path")
.short('s')
.long("secret-key-path")
.num_args(1)
.value_name("SECRET_KEY_PATH")
.help("path to the new secret key"),
)
.arg(
Arg::new("force")
.short('f')
.long("force")
.action(SetTrue)
.help("force generate a new keypair"),
)
.arg(
Arg::new("comment")
.short('c')
.long("comment")
.num_args(1)
.value_name("COMMENT")
.help("add a one-line untrusted comment"),
)
.arg(
Arg::new("passwordless")
.short('W')
.long("passwordless")
.action(SetTrue)
.help("don't use a password for the secret key"),
)
.arg(
Arg::new("unencrypted")
.long("unencrypted")
.action(SetTrue)
.help("generate an unencrypted secret key"),
),
)
.subcommand(
Command::new("verify")
.about("Verify a signed file with a given public key")
.arg(
Arg::new("public_key")
.short('P')
.long("public-key-string")
.num_args(1)
.value_name("PUBLIC_KEY_STRING")
.conflicts_with("pk_path")
.help("public key string"),
)
.arg(
Arg::new("pk_path")
.short('p')
.long("public-key-path")
.num_args(1)
.value_name("PUBLIC_KEY_PATH")
.help("path to public key file"),
)
.arg(
Arg::new("sig_file")
.short('x')
.long("sig-file")
.num_args(1)
.value_name("SIG_FILE")
.help("signature file to be verified"),
)
.arg(
Arg::new("quiet")
.short('q')
.long("quiet")
.action(SetTrue)
.help("quiet mode, suppress output"),
)
.arg(
Arg::new("allow-legacy")
.short('l')
.long("allow-legacy")
.action(SetTrue)
.help("accept legacy signatures"),
)
.arg(
Arg::new("output")
.short('o')
.long("output")
.action(SetTrue)
.help("output the file content after verification"),
)
.arg(
Arg::new("file")
.index(1)
.num_args(1)
.required(true)
.value_name("FILE")
.help("file to be verified"),
),
)
.subcommand(
Command::new("sign")
.about("Sign a file with a given private key")
.arg(
Arg::new("public_key")
.short('P')
.long("public-key-string")
.num_args(1)
.value_name("PUBLIC_KEY_STRING")
.conflicts_with("pk_path")
.help("public key string"),
)
.arg(
Arg::new("pk_path")
.short('p')
.long("public-key-file")
.num_args(1)
.value_name("PUBLIC_KEY_FILE")
.help("path to public key file"),
)
.arg(
Arg::new("sk_path")
.short('s')
.long("secret-key-file")
.num_args(1)
.value_name("SECRET_KEY_FILE")
.help("secret key to be used to sign"),
)
.arg(
Arg::new("sig_file")
.short('x')
.long("sig-file")
.num_args(1)
.value_name("SIG_FILE")
.help("signature file"),
)
.arg(
Arg::new("data")
.index(1)
.num_args(1)
.value_name("FILE")
.required(true)
.help("file to sign"),
)
.arg(
Arg::new("trusted-comment")
.short('t')
.long("trusted-comment")
.num_args(1)
.value_name("TRUSTED_COMMENT")
.help("add a one-line trusted comment"),
)
.arg(
Arg::new("untrusted-comment")
.short('c')
.long("untrusted-comment")
.num_args(1)
.value_name("UNTRUSTED_COMMENT")
.help("add a one-line untrusted comment"),
)
.arg(
Arg::new("hash")
.short('H')
.long("hash")
.required(false)
.action(SetTrue)
.help("ignored (for backwards compatibility only)"),
)
.arg(
Arg::new("passwordless")
.short('W')
.long("passwordless")
.action(SetTrue)
.help("don't use a password for the secret key"),
),
);
let help_usage = app.render_usage().to_string();
let matches = app.get_matches();
(matches, help_usage)
}