cli: add status command

Provides equivalent functionality to `yubico-piv-tool`
This commit is contained in:
Tony Arcieri
2019-12-09 17:51:05 -08:00
parent 283e6fe363
commit 78d5f33695
12 changed files with 189 additions and 34 deletions
+12 -1
View File
@@ -32,7 +32,8 @@
use crate::{error::Error, yubikey::YubiKey};
use getrandom::getrandom;
use std::fmt::{self, Debug};
use std::fmt::{self, Debug, Display};
use subtle_encoding::hex;
/// CCCID size
pub const CCCID_SIZE: usize = 14;
@@ -116,3 +117,13 @@ impl Debug for CCC {
write!(f, "CCC({:?})", &self.0[..])
}
}
impl Display for CCC {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(
f,
"{}",
String::from_utf8(hex::encode(&self.0[..])).unwrap()
)
}
}
+12 -1
View File
@@ -32,7 +32,8 @@
use crate::{error::Error, yubikey::YubiKey};
use getrandom::getrandom;
use std::fmt::{self, Debug};
use std::fmt::{self, Debug, Display};
use subtle_encoding::hex;
/// CHUID size
pub const CHUID_SIZE: usize = 59;
@@ -149,6 +150,16 @@ impl CHUID {
}
}
impl Display for CHUID {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(
f,
"{}",
String::from_utf8(hex::encode(&self.0[..])).unwrap()
)
}
}
impl Debug for CHUID {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(f, "CHUID({:?})", &self.0[..])
+7 -1
View File
@@ -156,7 +156,13 @@ pub mod settings;
mod transaction;
pub mod yubikey;
pub use self::{error::Error, key::Key, mgm::MgmKey, readers::Readers, yubikey::YubiKey};
pub use self::{
error::Error,
key::Key,
mgm::MgmKey,
readers::Readers,
yubikey::{Serial, YubiKey},
};
/// Object identifiers
pub type ObjectId = u32;
+9 -1
View File
@@ -43,6 +43,7 @@ use pcsc::Card;
use std::{
convert::TryFrom,
fmt::{self, Display},
str::FromStr,
};
#[cfg(feature = "untested")]
@@ -103,6 +104,14 @@ impl From<Serial> for u32 {
}
}
impl FromStr for Serial {
type Err = Error;
fn from_str(s: &str) -> Result<Self, Error> {
u32::from_str(s).map(Serial).map_err(|_| Error::ParseError)
}
}
impl Display for Serial {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(f, "{}", self.0)
@@ -350,7 +359,6 @@ impl YubiKey {
}
/// Get the number of PIN retries
#[cfg(feature = "untested")]
pub fn get_pin_retries(&mut self) -> Result<u8, Error> {
let txn = self.begin_transaction()?;