pub mod management;
pub mod ssh;
#[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::{AlgorithmId, RetiredSlotId, SlotId};
pub use yubikey::{PinPolicy, TouchPolicy};
pub struct Yubikey {
pub yk: 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())
}
}
impl From<yubikey::Error> for Error {
fn from(e: yubikey::Error) -> Self {
Error::InternalYubiKeyError(e.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),
}
}
}