From b7fd2ef8e5aa0d758f1b6e4a2b2013078e4509e1 Mon Sep 17 00:00:00 2001 From: ryan Date: Tue, 12 Sep 2023 00:29:01 -0500 Subject: [PATCH] keyfork-mnemonic-generate: alter signature of generate_mnemonic to take size as input --- keyfork-mnemonic-generate/Cargo.toml | 2 +- keyfork-mnemonic-generate/src/lib.rs | 16 +++------------- keyfork-mnemonic-generate/src/main.rs | 13 ++++++++++++- 3 files changed, 16 insertions(+), 15 deletions(-) diff --git a/keyfork-mnemonic-generate/Cargo.toml b/keyfork-mnemonic-generate/Cargo.toml index e5ab679..ab628f2 100644 --- a/keyfork-mnemonic-generate/Cargo.toml +++ b/keyfork-mnemonic-generate/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "keyfork-mnemonic-generate" -version = "0.1.1" +version = "0.2.0" description = "A tool to generate BIP-0039 mnemonics." license = "GPL-3.0" repository = "https://git.distrust.co/public/keyfork" diff --git a/keyfork-mnemonic-generate/src/lib.rs b/keyfork-mnemonic-generate/src/lib.rs index 5810b6f..f766602 100644 --- a/keyfork-mnemonic-generate/src/lib.rs +++ b/keyfork-mnemonic-generate/src/lib.rs @@ -1,5 +1,5 @@ use std::{ - env, + env::vars, error::Error, fs::{read_dir, read_to_string, File}, io::Read, @@ -78,24 +78,14 @@ fn ensure_offline() { } } -pub fn generate_mnemonic() -> Result { - if !env::vars() +pub fn generate_mnemonic(bit_size: usize) -> Result { + if !vars() .any(|(name, _)| name == "SHOOT_SELF_IN_FOOT" || name == "INSECURE_HARDWARE_ALLOWED") { ensure_safe_kernel_version(); ensure_offline(); } - let bit_size: usize = env::args() - .nth(1) - .unwrap_or(String::from("256")) - .parse() - .expect("Expected integer bit size"); - assert!( - bit_size == 128 || bit_size == 256, - "Only 12 or 24 word mnemonics are supported" - ); - let mut rng = Entropy::new()?; let entropy = &mut [0u8; 256 / 8]; rng.read_into(&mut entropy[..])?; diff --git a/keyfork-mnemonic-generate/src/main.rs b/keyfork-mnemonic-generate/src/main.rs index 055576d..ade3f68 100644 --- a/keyfork-mnemonic-generate/src/main.rs +++ b/keyfork-mnemonic-generate/src/main.rs @@ -1,7 +1,18 @@ +use std::env::args; use keyfork_mnemonic_generate::*; fn main() -> Result<()> { - let mnemonic = generate_mnemonic()?; + let bit_size: usize = args() + .nth(1) + .unwrap_or(String::from("256")) + .parse() + .expect("Expected integer bit size"); + assert!( + bit_size == 128 || bit_size == 256, + "Only 12 or 24 word mnemonics are supported" + ); + + let mnemonic = generate_mnemonic(bit_size)?; println!("{mnemonic}");