keyfork-mnemonic-generate: alter signature of generate_mnemonic to take size as input
This commit is contained in:
parent
76d369a6d5
commit
b7fd2ef8e5
|
@ -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"
|
||||
|
|
|
@ -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<Mnemonic> {
|
||||
if !env::vars()
|
||||
pub fn generate_mnemonic(bit_size: usize) -> Result<Mnemonic> {
|
||||
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[..])?;
|
||||
|
|
|
@ -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}");
|
||||
|
||||
|
|
Loading…
Reference in New Issue