#[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::{self, Connectable, Connection};
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) -> Box<dyn Connectable> {
Box::new(UsbConnector(config.clone()))
}
}
impl Connectable for UsbConnector {
fn box_clone(&self) -> Box<dyn Connectable> {
Box::new(UsbConnector(self.0.clone()))
}
fn connect(&self) -> Result<Box<dyn Connection>, connector::Error> {
Ok(Box::new(UsbConnection::open(&self.0)?))
}
}
impl Into<Box<Connectable>> for UsbConnector {
fn into(self) -> Box<Connectable> {
Box::new(self)
}
}