Skip to content

Commit

Permalink
Make Serial and Name Optional
Browse files Browse the repository at this point in the history
  • Loading branch information
ashuio committed Dec 24, 2023
1 parent 4de643b commit 33e950a
Showing 1 changed file with 17 additions and 7 deletions.
24 changes: 17 additions & 7 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@ type Result<T> = ::std::result::Result<T, YubicoError>;

#[derive(Clone, Debug, PartialEq)]
pub struct Yubikey {
pub name: String,
pub serial: u32,
pub name: Option<String>,
pub serial: Option<u32>,
pub product_id: u16,
pub vendor_id: u16,
pub bus_id: u8,
Expand Down Expand Up @@ -95,8 +95,14 @@ impl Yubico {
for device in self.context.devices().unwrap().iter() {
let descr = device.device_descriptor().unwrap();
if descr.vendor_id() == VENDOR_ID {
let name = device.open()?.read_product_string_ascii(&descr)?;
let serial = self.read_serial_from_device(device.clone())?;
let name = match device.open()?.read_product_string_ascii(&descr) {
Ok(name) => Some(name),
Err(_) => None,
};
let serial = match self.read_serial_from_device(device.clone()) {
Ok(serial) => Some(serial),
Err(_) => None,
};
let yubikey = Yubikey {
name: name,
serial: serial,
Expand All @@ -118,8 +124,8 @@ impl Yubico {
for device in self.context.devices().unwrap().iter() {
let descr = device.device_descriptor().unwrap();
if descr.vendor_id() == VENDOR_ID {
let name = device.open()?.read_product_string_ascii(&descr)?;
let serial = self.read_serial_from_device(device.clone())?;
let name = device.open()?.read_product_string_ascii(&descr).ok();
let serial = self.read_serial_from_device(device.clone()).ok();
let yubikey = Yubikey {
name: name,
serial: serial,
Expand Down Expand Up @@ -284,16 +290,20 @@ impl Yubico {
(&mut challenge[..chall.len()]).copy_from_slice(chall);
let d = Frame::new(challenge, command);
let mut buf = [0; 8];

eprintln!("Step 1 done");
let mut response = [0; 36];
manager::wait(
&mut handle,
|f| !f.contains(manager::Flags::SLOT_WRITE_FLAG),
&mut buf,
)?;
eprintln!("Step 2 done");
manager::write_frame(&mut handle, &d)?;
eprintln!("Step 3 done");
manager::read_response(&mut handle, &mut response)?;
eprintln!("Step 4 done");
manager::close_device(handle, interfaces)?;
eprintln!("Step 5 done");

// Check response.
if crc16(&response[..18]) != CRC_RESIDUAL_OK {
Expand Down

0 comments on commit 33e950a

Please sign in to comment.