Compare commits

..

No commits in common. "3926be8aac97629578c04b498083e7be4d8e410d" and "950c26a35caf4ff1ab99fd03663b73f19d2d0cad" have entirely different histories.

2 changed files with 9 additions and 22 deletions

View file

@ -86,16 +86,11 @@ pub struct FormatOptions {
#[arg(short = 's', long)] #[arg(short = 's', long)]
/// format to base64 /// format to base64
base64: bool, base64: bool,
#[arg(short = 'r', long, default_value_t = 0, value_parser=numf_parser::<NumberType>)] #[arg(short = 'r', long, default_value_t = 0)]
/// output random numbers /// output random numbers
/// ///
/// Add a user defined amount of cryptographically pseudorandom numbers to the number list. /// Add a user defined amount of cryptographically pseudorandom numbers to the number list.
rand: NumberType, rand: usize,
#[arg(long, default_value_t = NumberType::MAX, value_parser=numf_parser::<NumberType>)]
/// max for the random numbers
///
/// Generated numbers will not be lower than this. Only has an effect with --rand set.
rand_max: NumberType,
#[arg(short = 'z', long)] #[arg(short = 'z', long)]
/// format to base32 /// format to base32
base32: bool, base32: bool,
@ -195,24 +190,14 @@ impl FormatOptions {
} }
/// get rand /// get rand
pub fn rand(&self) -> NumberType { pub fn rand(&self) -> usize {
self.rand self.rand
} }
/// set amount of extra random numbers manually /// set amount of extra random numbers manually
pub fn set_rand(&mut self, rand: NumberType) { pub fn set_rand(&mut self, rand: usize) {
self.rand = rand; self.rand = rand;
} }
/// get highes allowed random value
pub fn rand_max(&self) -> NumberType {
self.rand_max
}
/// set highes allowed random value
pub fn set_rand_max(&mut self, rand_max: NumberType) {
self.rand_max = rand_max;
}
} }
impl Default for FormatOptions { impl Default for FormatOptions {
@ -228,7 +213,6 @@ impl Default for FormatOptions {
dec: false, dec: false,
numbers: vec![], numbers: vec![],
rand: 0, rand: 0,
rand_max: NumberType::MAX
} }
} }
} }

View file

@ -10,7 +10,7 @@ use clap::{CommandFactory, Parser};
mod format; mod format;
use format::*; use format::*;
use numf::format::numf_parser; use numf::format::{numf_parser, NumberType};
fn main() -> anyhow::Result<()> { fn main() -> anyhow::Result<()> {
// try to read from stdin first, appending the numbers we read to the FormatOptions // try to read from stdin first, appending the numbers we read to the FormatOptions
@ -53,7 +53,10 @@ fn main() -> anyhow::Result<()> {
use rand::prelude::*; use rand::prelude::*;
let mut rand = rand::rngs::OsRng; let mut rand = rand::rngs::OsRng;
for _i in 0..options.rand() { for _i in 0..options.rand() {
options.push_number(rand.gen_range(0..options.rand_max())); let mut by: [u8; 16] = [0; 16];
rand.fill_bytes(&mut by);
let n: NumberType = libpt::bintols::join::array_to_unsigned(&by)?;
options.push_number(n);
} }
} }