Merge pull request #74 from iqlusioninc/cli/reader-name
cli: print reader name as part of `status` command
This commit is contained in:
@@ -36,7 +36,7 @@ impl ReadersCmd {
|
|||||||
|
|
||||||
for (i, reader) in readers_iter.enumerate() {
|
for (i, reader) in readers_iter.enumerate() {
|
||||||
let name = reader.name();
|
let name = reader.name();
|
||||||
let mut yubikey = match reader.open() {
|
let yubikey = match reader.open() {
|
||||||
Ok(yk) => yk,
|
Ok(yk) => yk,
|
||||||
Err(_) => continue,
|
Err(_) => continue,
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -19,6 +19,7 @@ impl StatusCmd {
|
|||||||
let mut s = STDOUT.lock();
|
let mut s = STDOUT.lock();
|
||||||
s.reset().unwrap();
|
s.reset().unwrap();
|
||||||
|
|
||||||
|
self.attr(&mut s, "name", yk.name()).unwrap();
|
||||||
self.attr(&mut s, "version", yk.version()).unwrap();
|
self.attr(&mut s, "version", yk.version()).unwrap();
|
||||||
self.attr(&mut s, "serial", yk.serial()).unwrap();
|
self.attr(&mut s, "serial", yk.serial()).unwrap();
|
||||||
|
|
||||||
|
|||||||
+10
-3
@@ -157,6 +157,7 @@ impl Display for Version {
|
|||||||
#[cfg_attr(not(feature = "untested"), allow(dead_code))]
|
#[cfg_attr(not(feature = "untested"), allow(dead_code))]
|
||||||
pub struct YubiKey {
|
pub struct YubiKey {
|
||||||
pub(crate) card: Card,
|
pub(crate) card: Card,
|
||||||
|
pub(crate) name: String,
|
||||||
pub(crate) pin: Option<CachedPin>,
|
pub(crate) pin: Option<CachedPin>,
|
||||||
pub(crate) version: Version,
|
pub(crate) version: Version,
|
||||||
pub(crate) serial: Serial,
|
pub(crate) serial: Serial,
|
||||||
@@ -192,7 +193,7 @@ impl YubiKey {
|
|||||||
let mut readers = Readers::open()?;
|
let mut readers = Readers::open()?;
|
||||||
|
|
||||||
for reader in readers.iter()? {
|
for reader in readers.iter()? {
|
||||||
let mut yubikey = match reader.open() {
|
let yubikey = match reader.open() {
|
||||||
Ok(yk) => yk,
|
Ok(yk) => yk,
|
||||||
Err(_) => continue,
|
Err(_) => continue,
|
||||||
};
|
};
|
||||||
@@ -238,17 +239,22 @@ impl YubiKey {
|
|||||||
Ok(Transaction::new(&mut self.card)?)
|
Ok(Transaction::new(&mut self.card)?)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Get the name of the associated PC/SC card reader
|
||||||
|
pub fn name(&self) -> &str {
|
||||||
|
&self.name
|
||||||
|
}
|
||||||
|
|
||||||
/// Get the YubiKey's PIV application version.
|
/// Get the YubiKey's PIV application version.
|
||||||
///
|
///
|
||||||
/// This always uses the cached version queried when the key is initialized.
|
/// This always uses the cached version queried when the key is initialized.
|
||||||
pub fn version(&mut self) -> Version {
|
pub fn version(&self) -> Version {
|
||||||
self.version
|
self.version
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Get YubiKey device serial number.
|
/// Get YubiKey device serial number.
|
||||||
///
|
///
|
||||||
/// This always uses the cached version queried when the key is initialized.
|
/// This always uses the cached version queried when the key is initialized.
|
||||||
pub fn serial(&mut self) -> Serial {
|
pub fn serial(&self) -> Serial {
|
||||||
self.serial
|
self.serial
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -637,6 +643,7 @@ impl<'a> TryFrom<&'a Reader<'_>> for YubiKey {
|
|||||||
|
|
||||||
let yubikey = YubiKey {
|
let yubikey = YubiKey {
|
||||||
card,
|
card,
|
||||||
|
name: String::from(reader.name()),
|
||||||
pin: None,
|
pin: None,
|
||||||
version,
|
version,
|
||||||
serial,
|
serial,
|
||||||
|
|||||||
@@ -20,7 +20,7 @@ fn init_yubikey() -> Mutex<YubiKey> {
|
|||||||
env_logger::builder().format_timestamp(None).init();
|
env_logger::builder().format_timestamp(None).init();
|
||||||
}
|
}
|
||||||
|
|
||||||
let mut yubikey = YubiKey::open().unwrap();
|
let yubikey = YubiKey::open().unwrap();
|
||||||
trace!("serial: {}", yubikey.serial());
|
trace!("serial: {}", yubikey.serial());
|
||||||
trace!("version: {}", yubikey.version());
|
trace!("version: {}", yubikey.version());
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user