export_test_vectors/
main.rs1mod vectors;
2use inner::*;
3
4fn main() {
6 inner::main();
7}
8
9mod inner {
10 use super::vectors;
11 use std::{
12 env,
13 fs::File,
14 io::{self, Write},
15 str::FromStr,
16 };
17
18 #[derive(Debug)]
19 pub enum Mode {
20 Hex,
21 B10,
22 }
23
24 impl FromStr for Mode {
25 type Err = ();
26
27 fn from_str(input: &str) -> Result<Self, Self::Err> {
28 match input.to_lowercase().as_str() {
29 "b10" => Ok(Mode::B10),
30 "hex" => Ok(Mode::Hex),
31 _ => Err(()),
32 }
33 }
34 }
35
36 #[derive(Debug)]
37 pub enum ParamType {
38 Legacy,
39 Kimchi,
40 }
41
42 impl FromStr for ParamType {
43 type Err = ();
44
45 fn from_str(input: &str) -> Result<Self, Self::Err> {
46 match input.to_lowercase().as_str() {
47 "legacy" => Ok(ParamType::Legacy),
48 "kimchi" => Ok(ParamType::Kimchi),
49 _ => Err(()),
50 }
51 }
52 }
53
54 pub(crate) fn main() {
55 let args: Vec<String> = env::args().collect();
56 match args.len() {
57 4 => {
58 let mode: Mode = args
60 .get(1)
61 .expect("missing mode")
62 .parse()
63 .expect("invalid mode");
64 let param_type: ParamType = args
65 .get(2)
66 .expect("missing param type")
67 .parse()
68 .expect("invalid param type");
69 let output_file = args.get(3).expect("missing file");
70
71 let vectors = vectors::generate(mode, param_type);
73
74 let writer: Box<dyn Write> = match output_file.as_str() {
76 "-" => Box::new(io::stdout()),
77 _ => Box::new(File::create(output_file).expect("could not create file")),
78 };
79 serde_json::to_writer_pretty(writer, &vectors).expect("could not write to file");
80 }
81 _ => {
82 println!(
83 "usage: cargo run -p export_test_vectors -- [{:?}|{:?}] [legacy|kimchi] <OUTPUT_FILE>",
84 Mode::Hex,
85 Mode::B10,
86 );
87 }
88 }
89 }
90}