feat: optimize code
This commit is contained in:
@@ -36,29 +36,31 @@ impl Command for CommandImpl {
|
|||||||
}
|
}
|
||||||
|
|
||||||
let mut yubi = Yubico::new();
|
let mut yubi = Yubico::new();
|
||||||
if let Ok(device) = yubi.find_yubikey() {
|
let device = match yubi.find_yubikey() {
|
||||||
success!("Found key, Vendor ID: {:?} Product ID {:?}", device.vendor_id, device.product_id);
|
Ok(device) => device,
|
||||||
|
Err(_) => {
|
||||||
let config = Config::default()
|
warning!("YubiKey not found");
|
||||||
.set_vendor_id(device.vendor_id)
|
return Ok(Some(1));
|
||||||
.set_product_id(device.product_id)
|
|
||||||
.set_command(yubico_manager::config::Command::Configuration2);
|
|
||||||
|
|
||||||
let hmac_key: HmacKey = HmacKey::from_slice(&secret_bytes);
|
|
||||||
let button_press = sub_arg_matches.is_present("button-press");
|
|
||||||
information!("Button press: {}", button_press);
|
|
||||||
|
|
||||||
let mut device_config = DeviceModeConfig::default();
|
|
||||||
device_config.challenge_response_hmac(&hmac_key, false, button_press);
|
|
||||||
|
|
||||||
if let Err(err) = yubi.write_config(config, &mut device_config) {
|
|
||||||
failure!("Config device failed: {:?}", err);
|
|
||||||
} else {
|
|
||||||
success!("Device configured");
|
|
||||||
}
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
success!("Found key, Vendor ID: {:?} Product ID {:?}", device.vendor_id, device.product_id);
|
||||||
|
let config = Config::default()
|
||||||
|
.set_vendor_id(device.vendor_id)
|
||||||
|
.set_product_id(device.product_id)
|
||||||
|
.set_command(yubico_manager::config::Command::Configuration2);
|
||||||
|
|
||||||
|
let hmac_key: HmacKey = HmacKey::from_slice(&secret_bytes);
|
||||||
|
let button_press = sub_arg_matches.is_present("button-press");
|
||||||
|
information!("Button press: {}", button_press);
|
||||||
|
|
||||||
|
let mut device_config = DeviceModeConfig::default();
|
||||||
|
device_config.challenge_response_hmac(&hmac_key, false, button_press);
|
||||||
|
|
||||||
|
if let Err(err) = yubi.write_config(config, &mut device_config) {
|
||||||
|
failure!("Config device failed: {:?}", err);
|
||||||
} else {
|
} else {
|
||||||
warning!("YubiKey not found");
|
success!("Device configured");
|
||||||
return Ok(Some(1));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Ok(None)
|
Ok(None)
|
||||||
|
|||||||
Reference in New Issue
Block a user