From 086e56bef0c94cd0d594168e86f149398316b148 Mon Sep 17 00:00:00 2001 From: ryan Date: Sun, 11 Feb 2024 01:04:13 -0500 Subject: [PATCH] keyfork-derive-util: minor refactor, tidy up publicness of modules --- crates/derive/keyfork-derive-key/src/main.rs | 4 +-- .../derive/keyfork-derive-openpgp/src/lib.rs | 3 +- .../derive/keyfork-derive-util/src/index.rs | 2 +- crates/derive/keyfork-derive-util/src/lib.rs | 32 +++++++++---------- .../keyfork-derive-util/src/public_key.rs | 1 + crates/keyfork-shard/src/openpgp.rs | 4 +-- 6 files changed, 24 insertions(+), 22 deletions(-) diff --git a/crates/derive/keyfork-derive-key/src/main.rs b/crates/derive/keyfork-derive-key/src/main.rs index e3ed5e2..21a2645 100644 --- a/crates/derive/keyfork-derive-key/src/main.rs +++ b/crates/derive/keyfork-derive-key/src/main.rs @@ -4,7 +4,7 @@ use std::{env, process::ExitCode, str::FromStr}; use keyfork_derive_util::{ request::{DerivationAlgorithm, DerivationError, DerivationRequest, DerivationResponse}, - DerivationPath, + DerivationPath, PathError, }; use keyforkd_client::Client; @@ -17,7 +17,7 @@ pub enum Error { /// The given path could not be parsed. #[error("Could not parse the given path: {0}")] - PathFormat(#[from] keyfork_derive_util::path::Error), + PathFormat(#[from] PathError), /// The request to derive data failed. #[error("Unable to perform key derivation request: {0}")] diff --git a/crates/derive/keyfork-derive-openpgp/src/lib.rs b/crates/derive/keyfork-derive-openpgp/src/lib.rs index acfcee0..2055734 100644 --- a/crates/derive/keyfork-derive-openpgp/src/lib.rs +++ b/crates/derive/keyfork-derive-openpgp/src/lib.rs @@ -5,6 +5,7 @@ use std::time::{Duration, SystemTime, SystemTimeError}; use derive_util::{ request::{DerivationResponse, TryFromDerivationResponseError}, DerivationIndex, ExtendedPrivateKey, PrivateKey, + IndexError, }; use ed25519_dalek::SigningKey; pub use keyfork_derive_util as derive_util; @@ -37,7 +38,7 @@ pub enum Error { /// A derivation index could not be created from the given index. #[error("Could not create derivation index: {0}")] - Index(#[from] keyfork_derive_util::index::Error), + Index(#[from] IndexError), /// A derivation operation could not be performed against the private key. #[error("Could not perform operation against private key: {0}")] diff --git a/crates/derive/keyfork-derive-util/src/index.rs b/crates/derive/keyfork-derive-util/src/index.rs index 0d5296b..98f688e 100644 --- a/crates/derive/keyfork-derive-util/src/index.rs +++ b/crates/derive/keyfork-derive-util/src/index.rs @@ -28,7 +28,7 @@ impl DerivationIndex { /// # Examples /// ```rust /// # use keyfork_derive_util::*; - /// let bip44 = DerivationIndex::new(44, true); + /// let bip44 = DerivationIndex::new(44, true).unwrap(); /// ``` /// /// Using a derivation index that is higher than 2^31 returns an error: diff --git a/crates/derive/keyfork-derive-util/src/lib.rs b/crates/derive/keyfork-derive-util/src/lib.rs index 8137889..ba170d4 100644 --- a/crates/derive/keyfork-derive-util/src/lib.rs +++ b/crates/derive/keyfork-derive-util/src/lib.rs @@ -1,27 +1,27 @@ #![allow(clippy::module_name_repetitions, clippy::must_use_candidate)] - #![doc = include_str!("../README.md")] pub mod extended_key; - -/// -pub mod index; -/// -pub mod path; -/// -pub mod private_key; -/// -pub mod public_key; -/// pub mod request; +mod index; +mod path; + +#[doc(hidden)] +pub mod private_key; + +#[doc(hidden)] +pub mod public_key; + #[cfg(test)] mod tests; +#[doc(inline)] +pub use crate::extended_key::{private_key::ExtendedPrivateKey, public_key::ExtendedPublicKey}; + pub use crate::{ - extended_key::{private_key::ExtendedPrivateKey, public_key::ExtendedPublicKey}, - index::DerivationIndex, - path::DerivationPath, - private_key::PrivateKey, - public_key::PublicKey, + index::{DerivationIndex, Error as IndexError}, + path::{DerivationPath, Error as PathError}, + private_key::{PrivateKey, PrivateKeyError}, + public_key::{PublicKey, PublicKeyError}, }; diff --git a/crates/derive/keyfork-derive-util/src/public_key.rs b/crates/derive/keyfork-derive-util/src/public_key.rs index eb84999..da9391b 100644 --- a/crates/derive/keyfork-derive-util/src/public_key.rs +++ b/crates/derive/keyfork-derive-util/src/public_key.rs @@ -147,6 +147,7 @@ pub struct TestPublicKey { impl TestPublicKey { #[doc(hidden)] + #[allow(dead_code)] pub fn from_bytes(b: &[u8]) -> Self { Self { key: b.try_into().unwrap(), diff --git a/crates/keyfork-shard/src/openpgp.rs b/crates/keyfork-shard/src/openpgp.rs index 520c246..36ab011 100644 --- a/crates/keyfork-shard/src/openpgp.rs +++ b/crates/keyfork-shard/src/openpgp.rs @@ -15,7 +15,7 @@ use aes_gcm::{ use hkdf::{Hkdf, InvalidLength as HkdfInvalidLength}; use keyfork_derive_openpgp::derive_util::{ request::{DerivationAlgorithm, DerivationRequest}, - DerivationPath, + DerivationPath, PathError, }; use keyfork_mnemonic_util::{Mnemonic, MnemonicFromStrError, MnemonicGenerationError, Wordlist}; use keyfork_prompt::{ @@ -125,7 +125,7 @@ pub enum Error { /// An error occurred while parsing a derivation path. #[error("Derivation path: {0}")] - DerivationPath(#[from] keyfork_derive_openpgp::derive_util::path::Error), + DerivationPath(#[from] PathError), /// An error occurred while requesting derivation. #[error("Derivation request: {0}")]