Clean up verbose logging
This commit is contained in:
parent
9029d35a6b
commit
589f0bb52b
2 changed files with 22 additions and 25 deletions
|
@ -1,4 +1,4 @@
|
|||
use std::{collections::HashMap, fs::File, io::BufReader, path::Path};
|
||||
use std::{collections::HashMap, fmt::Display, fs::File, io::BufReader, path::Path};
|
||||
|
||||
use anyhow::Result;
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
@ -10,16 +10,12 @@ pub fn load_keys<P: AsRef<Path> + std::fmt::Display>(
|
|||
) -> Result<Keys> {
|
||||
let keys = {
|
||||
if let Some(path) = path {
|
||||
if verbose {
|
||||
println!("Loading keys file {}", path);
|
||||
}
|
||||
|
||||
let file = File::open(&path)?;
|
||||
let reader = BufReader::new(file);
|
||||
let keys: Keys = from_reader(reader)?;
|
||||
|
||||
if verbose {
|
||||
println!("Loaded keys from {} successfully", path);
|
||||
println!("Loaded keys from {}", path);
|
||||
}
|
||||
|
||||
keys
|
||||
|
@ -39,13 +35,13 @@ pub struct Keys {
|
|||
pub bink: HashMap<String, Bink>,
|
||||
}
|
||||
|
||||
#[derive(Serialize, Deserialize)]
|
||||
#[derive(Serialize, Deserialize, Debug)]
|
||||
pub struct Product {
|
||||
#[serde(rename = "BINK")]
|
||||
pub bink: Vec<String>,
|
||||
}
|
||||
|
||||
#[derive(Serialize, Deserialize)]
|
||||
#[derive(Serialize, Deserialize, Debug)]
|
||||
pub struct Bink {
|
||||
pub p: String,
|
||||
pub a: String,
|
||||
|
@ -58,8 +54,23 @@ pub struct Bink {
|
|||
pub private: String,
|
||||
}
|
||||
|
||||
#[derive(Serialize, Deserialize)]
|
||||
#[derive(Serialize, Deserialize, Debug)]
|
||||
pub struct Point {
|
||||
pub x: String,
|
||||
pub y: String,
|
||||
}
|
||||
|
||||
impl Display for Bink {
|
||||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||
writeln!(f, " P: {}", self.p)?;
|
||||
writeln!(f, " a: {}", self.a)?;
|
||||
writeln!(f, " b: {}", self.b)?;
|
||||
writeln!(f, "Gx: {}", self.g.x)?;
|
||||
writeln!(f, "Gy: {}", self.g.y)?;
|
||||
writeln!(f, "Kx: {}", self.public.x)?;
|
||||
writeln!(f, "Ky: {}", self.public.y)?;
|
||||
writeln!(f, " n: {}", self.n)?;
|
||||
writeln!(f, " k: {}", self.private)?;
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
|
|
@ -52,11 +52,6 @@ fn generate(args: &GenerateArgs, verbose: bool) -> Result<()> {
|
|||
let private_key = &bink.private;
|
||||
|
||||
let curve = initialize_curve(bink, &bink_id, verbose)?;
|
||||
if verbose {
|
||||
println!(" n: {gen_order}");
|
||||
println!(" k: {private_key}");
|
||||
println!();
|
||||
}
|
||||
let private_key = PrivateKey::new(gen_order, private_key)?;
|
||||
|
||||
if u32::from_str_radix(&bink_id, 16)? < 0x40 {
|
||||
|
@ -96,18 +91,9 @@ fn initialize_curve(bink: &Bink, bink_id: &str, verbose: bool) -> Result<Ellipti
|
|||
|
||||
if verbose {
|
||||
println!("-----------------------------------------------------------");
|
||||
println!(
|
||||
"Loaded the following elliptic curve parameters: BINK[{}]",
|
||||
bink_id
|
||||
);
|
||||
println!("Elliptic curve parameters for BINK ID {bink_id}:");
|
||||
println!("-----------------------------------------------------------");
|
||||
println!(" P: {p}");
|
||||
println!(" a: {a}");
|
||||
println!(" b: {b}");
|
||||
println!("Gx: {gx}");
|
||||
println!("Gy: {gy}");
|
||||
println!("Kx: {kx}");
|
||||
println!("Ky: {ky}");
|
||||
println!("{bink}");
|
||||
}
|
||||
|
||||
EllipticCurve::new(p, a, b, gx, gy, kx, ky)
|
||||
|
|
Loading…
Add table
Reference in a new issue