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
extern crate clap;
use self::clap::{Arg, App, SubCommand};
pub fn parse_args<'a>() -> clap::ArgMatches<'a> {
let matches = App::new("rsign")
.version("0.1.1")
.author("Daniel Rangel <daniel@rangel.in>")
.about("Rust implementation of minisign")
.subcommand(SubCommand::with_name("generate")
.about("Generate public and private keys")
.arg(Arg::with_name("pk_path")
.short("p")
.long("public-key-path")
.takes_value(true)
.value_name("PUBLIC_KEY_PATH")
.help("path to the new public key"))
.arg(Arg::with_name("sk_path")
.short("s")
.long("secret-key-path")
.takes_value(true)
.value_name("SECRET_KEY_PATH")
.help("path to the new secret key"))
.arg(Arg::with_name("force")
.short("f")
.long("force")
.help("force generate a new keypair"))
.arg(Arg::with_name("comment")
.takes_value(true)
.help("add a one-line untrusted comment")
.value_name("COMMENT")
.short("c")
.long("comment")))
.subcommand(SubCommand::with_name("verify")
.about("Verify a signed file with a given public key")
.arg(Arg::with_name("public_key")
.short("P")
.long("public-key-string")
.takes_value(true)
.conflicts_with("pk_path")
.help("public key string")
.value_name("PUBLIC_KEY_STRING"))
.arg(Arg::with_name("pk_path")
.short("p")
.long("public-key-path")
.takes_value(true)
.value_name("PUBLIC_KEY_PATH")
.help("path to public key file"))
.arg(Arg::with_name("sig_file")
.takes_value(true)
.help("signature file to be verified")
.value_name("SIG_FILE")
.short("x")
.long("sig-file"))
.arg(Arg::with_name("quiet")
.help("quiet mode, supress output")
.takes_value(false)
.short("q")
.long("quiet"))
.arg(Arg::with_name("output")
.help("output the file content after verification")
.takes_value(false)
.short("o")
.long("output"))
.arg(Arg::with_name("file")
.index(1)
.takes_value(true)
.required(true)
.help("file to be verified")
.value_name("FILE")
.short("m")
.long("file-name")))
.subcommand(SubCommand::with_name("sign")
.about("Sign a file with a given private key")
.arg(Arg::with_name("public_key")
.short("P")
.long("public-key-string")
.takes_value(true)
.conflicts_with("pk_path")
.help("public key string")
.value_name("PUBLIC_KEY_STRING"))
.arg(Arg::with_name("pk_path")
.short("p")
.long("public-key-file")
.takes_value(true)
.value_name("PUBLIC_KEY_FILE")
.help("path to public key file"))
.arg(Arg::with_name("sk_path")
.short("s")
.long("secret-key-file")
.takes_value(true)
.value_name("SECRET_KEY_FILE")
.help("secret key to be used to sign"))
.arg(Arg::with_name("sig_file")
.takes_value(true)
.help("signature file")
.value_name("SIG_FILE")
.short("x")
.long("sig-file"))
.arg(Arg::with_name("message")
.index(1)
.takes_value(true)
.required(true)
.help("file to sign")
.value_name("FILE")
.short("m")
.long("message-file"))
.arg(Arg::with_name("trusted-comment")
.help("add a one-line trusted comment")
.value_name("TRUSTED_COMMENT")
.short("t")
.long("trusted-comment"))
.arg(Arg::with_name("untrusted-comment")
.help("add a one-line untrusted comment")
.value_name("UNTRUSTED_COMMENT")
.short("c")
.long("untrusted-comment"))
.arg(Arg::with_name("hash")
.required(false)
.short("H")
.long("hash")
.help("pre-hash in order to sign large files (>1G)")))
.get_matches();
matches
}