From 4b4b85931f86cd94f5432df340c1c78ee019f768 Mon Sep 17 00:00:00 2001 From: ryan Date: Sun, 5 Nov 2023 01:29:10 -0500 Subject: [PATCH] cargo fmt --- keyfork-derive-openpgp/src/main.rs | 2 +- keyfork-derive-path-data/src/lib.rs | 2 +- .../src/extended_key/private_key.rs | 2 +- keyfork-derive-util/src/path.rs | 7 +- keyfork-derive-util/src/public_key.rs | 4 +- keyfork-derive-util/src/tests.rs | 8 +- keyfork-mnemonic-util/src/lib.rs | 25 ++-- keyfork-pinentry/src/lib.rs | 2 +- keyfork-slip10-test-data/src/lib.rs | 132 +++++++++++++----- keyfork/src/cli/mnemonic.rs | 2 +- keyfork/src/main.rs | 4 +- keyforkd-client/src/tests.rs | 7 +- keyforkd/src/service.rs | 7 +- 13 files changed, 138 insertions(+), 66 deletions(-) diff --git a/keyfork-derive-openpgp/src/main.rs b/keyfork-derive-openpgp/src/main.rs index 07328f5..6c514bf 100644 --- a/keyfork-derive-openpgp/src/main.rs +++ b/keyfork-derive-openpgp/src/main.rs @@ -1,4 +1,4 @@ -use std::{env, str::FromStr, process::ExitCode}; +use std::{env, process::ExitCode, str::FromStr}; use keyfork_derive_util::{ request::{DerivationAlgorithm, DerivationRequest}, diff --git a/keyfork-derive-path-data/src/lib.rs b/keyfork-derive-path-data/src/lib.rs index 1b89174..104069e 100644 --- a/keyfork-derive-path-data/src/lib.rs +++ b/keyfork-derive-path-data/src/lib.rs @@ -1,4 +1,4 @@ -use keyfork_derive_util::{DerivationPath, DerivationIndex}; +use keyfork_derive_util::{DerivationIndex, DerivationPath}; pub static OPENPGP: DerivationIndex = DerivationIndex::new_unchecked(7366512, true); diff --git a/keyfork-derive-util/src/extended_key/private_key.rs b/keyfork-derive-util/src/extended_key/private_key.rs index d8e864f..ef94c8a 100644 --- a/keyfork-derive-util/src/extended_key/private_key.rs +++ b/keyfork-derive-util/src/extended_key/private_key.rs @@ -1,4 +1,4 @@ -use crate::{DerivationIndex, DerivationPath, PrivateKey, PublicKey, ExtendedPublicKey}; +use crate::{DerivationIndex, DerivationPath, ExtendedPublicKey, PrivateKey, PublicKey}; use hmac::{Hmac, Mac}; use serde::{Deserialize, Serialize}; diff --git a/keyfork-derive-util/src/path.rs b/keyfork-derive-util/src/path.rs index 0fa69a5..dfad0cc 100644 --- a/keyfork-derive-util/src/path.rs +++ b/keyfork-derive-util/src/path.rs @@ -122,11 +122,14 @@ mod tests { Ok(()) } - #[test] fn add_vec() -> Result<(), Box> { let path = DerivationPath::from_str("m")?; - let other_path = [DerivationIndex::new(72, true)?, DerivationIndex::new(47, false)?, DerivationIndex::new((i32::MAX) as u32, false)?]; + let other_path = [ + DerivationIndex::new(72, true)?, + DerivationIndex::new(47, false)?, + DerivationIndex::new((i32::MAX) as u32, false)?, + ]; let path = path + &other_path[..]; assert_eq!(path, DerivationPath::from_str("m/72'/47/2147483647")?); diff --git a/keyfork-derive-util/src/public_key.rs b/keyfork-derive-util/src/public_key.rs index 9e3e4a9..b91d3e1 100644 --- a/keyfork-derive-util/src/public_key.rs +++ b/keyfork-derive-util/src/public_key.rs @@ -35,7 +35,9 @@ pub trait PublicKey: Sized { let hash = Sha256::new().chain_update(self.to_bytes()).finalize(); let hash = Ripemd160::new().chain_update(hash).finalize(); // Note: Safety assured by type returned from Ripemd160 - hash[..4].try_into().expect("Ripemd160 returned too little data") + hash[..4] + .try_into() + .expect("Ripemd160 returned too little data") } } diff --git a/keyfork-derive-util/src/tests.rs b/keyfork-derive-util/src/tests.rs index 0200794..82616ac 100644 --- a/keyfork-derive-util/src/tests.rs +++ b/keyfork-derive-util/src/tests.rs @@ -59,10 +59,7 @@ fn secp256k1() { fn ed25519() { use ed25519_dalek::SigningKey; - let tests = test_data() - .unwrap() - .remove(&"ed25519".to_string()) - .unwrap(); + let tests = test_data().unwrap().remove(&"ed25519".to_string()).unwrap(); for per_seed in tests { let seed = &per_seed.seed; @@ -110,7 +107,8 @@ fn panics_with_unhardened_derivation() { let seed = hex!("000102030405060708090a0b0c0d0e0f"); let xkey = ExtendedPrivateKey::::new(seed).unwrap(); - xkey.derive_path(&DerivationPath::from_str("m/0").unwrap()).unwrap(); + xkey.derive_path(&DerivationPath::from_str("m/0").unwrap()) + .unwrap(); } #[cfg(feature = "ed25519")] diff --git a/keyfork-mnemonic-util/src/lib.rs b/keyfork-mnemonic-util/src/lib.rs index 726b227..6534fa4 100644 --- a/keyfork-mnemonic-util/src/lib.rs +++ b/keyfork-mnemonic-util/src/lib.rs @@ -1,8 +1,8 @@ -use std::{collections::HashMap, str::FromStr, sync::Arc, error::Error, fmt::Display}; +use std::{collections::HashMap, error::Error, fmt::Display, str::FromStr, sync::Arc}; -use sha2::{Digest, Sha256, Sha512}; -use pbkdf2::pbkdf2; use hmac::Hmac; +use pbkdf2::pbkdf2; +use sha2::{Digest, Sha256, Sha512}; /// The error type representing a failure to create a [`Mnemonic`]. These errors only occur during /// [`Mnemonic`] creation. @@ -30,7 +30,7 @@ impl Display for MnemonicGenerationError { } MnemonicGenerationError::InvalidPbkdf2Length => { f.write_str("Invalid length from PBKDF2") - }, + } } } } @@ -207,7 +207,7 @@ impl Mnemonic { bits[index * 11 + bit] = (word & (1 << (10 - bit))) > 0; } } - + // remove checksum bits bits.truncate(bits.len() - bits.len() % 32); @@ -222,7 +222,10 @@ impl Mnemonic { .collect() } - pub fn seed<'a>(&self, passphrase: impl Into>) -> Result, MnemonicGenerationError> { + pub fn seed<'a>( + &self, + passphrase: impl Into>, + ) -> Result, MnemonicGenerationError> { let passphrase = passphrase.into(); let mut seed = [0u8; 64]; @@ -293,8 +296,14 @@ mod tests { let their_mnemonic = bip39::Mnemonic::from_entropy(&entropy[..256 / 8]).unwrap(); assert_eq!(my_mnemonic.to_string(), their_mnemonic.to_string()); assert_eq!(my_mnemonic.seed(None).unwrap(), their_mnemonic.to_seed("")); - assert_eq!(my_mnemonic.seed("testing").unwrap(), their_mnemonic.to_seed("testing")); - assert_ne!(my_mnemonic.seed("test1").unwrap(), their_mnemonic.to_seed("test2")); + assert_eq!( + my_mnemonic.seed("testing").unwrap(), + their_mnemonic.to_seed("testing") + ); + assert_ne!( + my_mnemonic.seed("test1").unwrap(), + their_mnemonic.to_seed("test2") + ); } #[test] diff --git a/keyfork-pinentry/src/lib.rs b/keyfork-pinentry/src/lib.rs index b901041..44d1713 100644 --- a/keyfork-pinentry/src/lib.rs +++ b/keyfork-pinentry/src/lib.rs @@ -390,7 +390,7 @@ impl<'a> MessageDialog<'a> { binary, title: None, ok: None, - timeout: None + timeout: None, } } diff --git a/keyfork-slip10-test-data/src/lib.rs b/keyfork-slip10-test-data/src/lib.rs index ecab2cf..1384cc3 100644 --- a/keyfork-slip10-test-data/src/lib.rs +++ b/keyfork-slip10-test-data/src/lib.rs @@ -219,37 +219,67 @@ pub fn test_data() -> Result>, Box Result>, Box