pub mod ssh;
mod management;
#[derive(Debug)]
pub enum Error {
Unprovisioned,
WrongKeyType,
Unsupported,
InvalidManagementKey,
ParsingError,
NoSuchYubikey,
InternalYubiKeyError(String),
}
impl std::error::Error for Error {}
type Result<T> = std::result::Result<T, Error>;
pub use yubikey_piv::key::{AlgorithmId, RetiredSlotId, SlotId};
pub struct Yubikey {
yk: yubikey_piv::yubikey::YubiKey,
}
impl std::fmt::Debug for Yubikey {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
writeln!(f, "YubiKey: {}", self.yk.serial().to_string())
}
}
impl std::fmt::Display for Error {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match *self {
Error::Unprovisioned => write!(f, "Slot is unprovisioned for signing"),
Error::WrongKeyType => write!(f, "Wrong key type was provided for requested signing operation"),
Error::Unsupported => write!(f, "This key is not supported the way you tried to use it"),
Error::InvalidManagementKey => write!(f, "Could not use the management key as provided"),
Error::ParsingError => write!(f, "Could not parse data"),
Error::NoSuchYubikey => write!(f, "Could not find the requested Yubikey"),
Error::InternalYubiKeyError(ref err) => write!(f, "Yubikey error: {}", err),
}
}
}