Skip to content

Commit a74236f

Browse files
committed
Add an optional way to output the key in base64 and/or in base58
1 parent 33ede64 commit a74236f

File tree

4 files changed

+53
-11
lines changed

4 files changed

+53
-11
lines changed

Cargo.lock

+25
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

+1
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ rpassword = "7.2.0"
1818
scrypt = "0.11.0"
1919
lazy_static = "1.4.0"
2020
base64 = "0.21.3"
21+
bs58 = "0.5.0"
2122

2223
[dependencies.pbr]
2324
git = "https://github.com/lbeder/pb.git"

README.md

+4-3
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,8 @@ Options:
3535
-l, --length <LENGTH> Length of the derived result (must be greater than 9 and less than or equal to 64) [default: 16]
3636
--offset <OFFSET> Start the derivation from this index. In order to use it, you also have to specify the intermediary offset data in hex format [default: 0]
3737
--offset-data <OFFSET_DATA> Start the derivation with this intermediary data in hex format
38-
--base64 Encode/decode the output/input as BASE64
38+
--base64 Output the result in Base64 (in addition to hex)
39+
--base58 Output the result in Base58 (in addition to hex)
3940
-h, --help Print help
4041
```
4142

@@ -151,7 +152,7 @@ Enter your secret again: 🔑
151152

152153
Processing: 100 / 100 [=======================================================================================================================================] 100.00 %
153154

154-
Key is (please highlight to see): ff08101f061aa670158601bf5be5efa6
155+
Key (hex) is (please highlight to see): ff08101f061aa670158601bf5be5efa6
155156

156157
Finished in 3m 29s
157158
```
@@ -187,7 +188,7 @@ Resuming from iteration 60 with intermediary offset data 2262d7c10e3806a4926a895
187188
188189
Processing: 40 / 40 [===============================================================================================================================] 100.00 %
189190
190-
Key is (please highlight to see): ff08101f061aa670158601bf5be5efa6
191+
Key (hex) is (please highlight to see): ff08101f061aa670158601bf5be5efa6
191192
192193
Finished in 1m 25s
193194
```

src/main.rs

+23-8
Original file line numberDiff line numberDiff line change
@@ -67,8 +67,11 @@ enum Commands {
6767
#[arg(long, help = "Start the derivation with this intermediary data in hex format")]
6868
offset_data: Option<String>,
6969

70-
#[arg(long, action = clap::ArgAction::SetTrue, help = "Encode/decode the output/input as BASE64")]
70+
#[arg(long, action = clap::ArgAction::SetTrue, help = "Output the result in Base64 (in addition to hex)")]
7171
base64: bool,
72+
73+
#[arg(long, action = clap::ArgAction::SetTrue, help = "Output the result in Base58 (in addition to hex)")]
74+
base58: bool,
7275
},
7376

7477
#[command(about = "Print test vectors")]
@@ -133,6 +136,7 @@ fn main() {
133136
offset,
134137
offset_data,
135138
base64,
139+
base58,
136140
}) => {
137141
println!(
138142
"Parameters: {} (log_n: {}, r: {}, p: {}, length: {})",
@@ -218,15 +222,26 @@ fn main() {
218222
pb.inc();
219223
});
220224

221-
let res = if *base64 {
222-
general_purpose::STANDARD_NO_PAD.encode(&key)
223-
} else {
224-
hex::encode(&key)
225-
};
226-
227225
println!();
228226
println!();
229-
println!("Key is (please highlight to see): {}", res.black().on_black());
227+
println!(
228+
"Key (hex) is (please highlight to see): {}",
229+
hex::encode(&key).black().on_black()
230+
);
231+
232+
if *base64 {
233+
println!(
234+
"Key (base64) is (please highlight to see): {}",
235+
general_purpose::STANDARD.encode(&key).black().on_black()
236+
);
237+
}
238+
239+
if *base58 {
240+
println!(
241+
"Key (base58) is (please highlight to see): {}",
242+
bs58::encode(&key).into_string().black().on_black()
243+
);
244+
}
230245

231246
pb.finish_println(&format!(
232247
"Finished in {}\n",

0 commit comments

Comments
 (0)