#[macro_use]
mod macros;
mod config;
mod connection;
mod device;
mod timeout;
pub use self::{
config::UsbConfig,
connection::UsbConnection,
device::{Device, Devices},
timeout::UsbTimeout,
};
use crate::connector::{Connection, ConnectionError, Connector};
use crate::serial_number::SerialNumber;
pub const YUBICO_VENDOR_ID: u16 = 0x1050;
pub const YUBIHSM2_PRODUCT_ID: u16 = 0x0030;
pub const YUBIHSM2_INTERFACE_NUM: u8 = 0;
pub const YUBIHSM2_BULK_OUT_ENDPOINT: u8 = 1;
pub const YUBIHSM2_BULK_IN_ENDPOINT: u8 = 0x81;
#[derive(Clone, Default, Debug)]
pub struct UsbConnector(UsbConfig);
impl UsbConnector {
pub fn create(config: &UsbConfig) -> Result<Self, ConnectionError> {
Ok(UsbConnector(config.clone()))
}
}
impl Connector for UsbConnector {
fn connect(&self) -> Result<Box<Connection>, ConnectionError> {
Ok(Box::new(UsbConnection::open(&self.0)?))
}
fn healthcheck(&self) -> Result<(), ConnectionError> {
Ok(())
}
fn serial_number(&self) -> Result<SerialNumber, ConnectionError> {
Ok(UsbConnection::open(&self.0)?.device().serial_number)
}
}
impl Into<Box<Connector>> for UsbConnector {
fn into(self) -> Box<Connector> {
Box::new(self)
}
}