Skip to content

Commit b4eccf9

Browse files
committed
Move code to dump secrets to output media into a module.
This refactor gets the code responsible for dumping secrets to the printer out of the HSM module. Additionally this moves all code driving user interaction out of the HSM module. This commit also defines a new type for the Feldman Verifier. This is useful for passing things around w/o having to specify a pile of generics. This uncovered a bug on the `verify_shares` test case that required we regenerate some test data.
1 parent eb834fa commit b4eccf9

File tree

6 files changed

+382
-300
lines changed

6 files changed

+382
-300
lines changed

src/bin/printer-test.rs

Lines changed: 10 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,15 @@
22
// License, v. 2.0. If a copy of the MPL was not distributed with this
33
// file, You can obtain one at https://mozilla.org/MPL/2.0/.
44

5-
use std::{fs::OpenOptions, path::PathBuf};
5+
use std::path::PathBuf;
66

77
use anyhow::Result;
88
use clap::{Parser, Subcommand};
99
use hex::ToHex;
10-
use oks::hsm::Alphabet;
10+
use oks::{
11+
hsm::{Alphabet, Share},
12+
secret_writer::PrinterSecretWriter,
13+
};
1114
use rand::{thread_rng, Rng};
1215
use zeroize::Zeroizing;
1316

@@ -38,36 +41,28 @@ enum Command {
3841

3942
fn main() -> Result<()> {
4043
let args = Args::parse();
44+
let secret_writer = PrinterSecretWriter::new(Some(args.print_dev));
4145

4246
match args.command {
4347
Command::RecoveryKeyShare {
4448
share_idx,
4549
share_count,
4650
data_len,
4751
} => {
48-
let mut print_file = OpenOptions::new()
49-
.create(true)
50-
.write(true)
51-
.truncate(true)
52-
.open(args.print_dev)?;
53-
5452
let share_data: Vec<u8> =
5553
(0..data_len).map(|x| (x % 256) as u8).collect();
54+
let share = Share::try_from(&share_data[..])?;
55+
let share = Zeroizing::new(share);
5656

5757
println!("Data: {}", share_data.encode_hex::<String>());
5858

59-
oks::hsm::print_share(
60-
&mut print_file,
61-
share_idx,
62-
share_count,
63-
&share_data,
64-
)
59+
secret_writer.share(share_idx, share_count, &share)
6560
}
6661
Command::HsmPassword { length } => {
6762
let password = Alphabet::new()
6863
.get_random_string(|| Ok(thread_rng().gen::<u8>()), length)?;
6964
let password = Zeroizing::new(password);
70-
oks::hsm::print_password(&args.print_dev, &password)
65+
secret_writer.password(&password)
7166
}
7267
}
7368
}

0 commit comments

Comments
 (0)