Skip to content

Commit 36a0022

Browse files
committed
Upgrade to clap 4.1 and convert to clap-derive
1 parent ef27f5e commit 36a0022

File tree

2 files changed

+31
-23
lines changed

2 files changed

+31
-23
lines changed

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ phf = "0.11"
4545
rusticata-macros = "4.0"
4646

4747
[dev-dependencies]
48-
clap = { version="3.2" }
48+
clap = { version="4.1", features = ["derive"]}
4949
hex-literal = "0.3"
5050
pretty_assertions = "1.0"
5151

examples/get-ciphersuite-info.rs

Lines changed: 30 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,30 @@
44
*
55
*/
66

7-
use clap::{App, Arg};
7+
use clap::Parser;
88
use std::num::ParseIntError;
99
use tls_parser::TlsCipherSuite;
1010

11+
#[derive(Parser)]
12+
struct CmdOptions {
13+
/// List all known ciphersuites
14+
#[arg(short = 'L', long)]
15+
list: bool,
16+
/// Display details (algorithms, mode, ...)
17+
#[arg(short, long)]
18+
long: bool,
19+
/// Use JSON for output
20+
#[arg(short = 'j', long)]
21+
to_json: bool,
22+
23+
/// Ciphersuite IANA identifier (decimal or hexadecimal prefix by 0x)
24+
#[arg(short, long, value_name = "id")]
25+
id: Option<String>,
26+
/// Ciphersuite IANA name
27+
#[arg(short, long, value_name = "name")]
28+
name: Option<String>,
29+
}
30+
1131
fn parse_u16(s: &str) -> Result<u16, ParseIntError> {
1232
if s.starts_with("0x") {
1333
let s = s.trim_start_matches("0x");
@@ -67,37 +87,25 @@ fn find_by_name(name: &str, show_details: bool, to_json: bool) {
6787
}
6888

6989
fn main() {
70-
let matches = App::new("get-ciphersuite-info")
71-
.arg(Arg::with_name("id").short('i').long("id").takes_value(true))
72-
.arg(
73-
Arg::with_name("name")
74-
.short('n')
75-
.long("name")
76-
.takes_value(true),
77-
)
78-
.arg(Arg::with_name("list").short('L').long("list"))
79-
.arg(Arg::with_name("json").short('j').long("json"))
80-
.arg(Arg::with_name("long").short('l').long("long"))
81-
.get_matches();
90+
let options = CmdOptions::parse();
8291

83-
let show_details = matches.is_present("long");
84-
let to_json = matches.is_present("json");
92+
let show_details = options.long;
8593

86-
if matches.is_present("list") {
94+
if options.list {
8795
let mut id_list = tls_parser::CIPHERS.keys().collect::<Vec<_>>();
8896
id_list.sort();
8997
for &id in &id_list {
9098
let cipher = TlsCipherSuite::from_id(*id).expect("could not get cipher");
91-
print_ciphersuite(cipher, show_details, to_json);
99+
print_ciphersuite(cipher, show_details, options.to_json);
92100
}
93101
return;
94102
}
95103

96-
if let Some(str_id) = matches.value_of("id") {
97-
let id = parse_u16(str_id).expect("Could not parse cipher ID");
98-
find_by_id(id, show_details, to_json);
99-
} else if let Some(name) = matches.value_of("name") {
100-
find_by_name(name, show_details, to_json);
104+
if let Some(str_id) = options.id {
105+
let id = parse_u16(&str_id).expect("Could not parse cipher ID");
106+
find_by_id(id, show_details, options.to_json);
107+
} else if let Some(name) = options.name {
108+
find_by_name(&name, show_details, options.to_json);
101109
} else {
102110
eprintln!("Missing command");
103111
}

0 commit comments

Comments
 (0)