keyfork/keyfork-derive-path-data/src/lib.rs

27 lines
870 B
Rust
Raw Normal View History

2023-11-05 06:29:10 +00:00
use keyfork_derive_util::{DerivationIndex, DerivationPath};
pub static OPENPGP: DerivationIndex = DerivationIndex::new_unchecked(7366512, true);
pub enum Target {
OpenPGP(DerivationIndex),
}
impl std::fmt::Display for Target {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match self {
Self::OpenPGP(account) => {
write!(f, "OpenPGP key (account {account})")
}
}
}
}
/// Determine the closest [`Target`] for the given path. This method is intended to be used by
/// `keyforkd` to provide an optional textual prompt to what a client is attempting to derive.
pub fn guess_target(path: &DerivationPath) -> Option<Target> {
Some(match Vec::from_iter(path.iter())[..] {
[t, index] if t == &OPENPGP => Target::OpenPGP(index.clone()),
_ => return None,
})
}