feat: challconfig

This commit is contained in:
2022-03-29 23:41:15 +08:00
parent 370754b436
commit 79c8ad7e5a

View File

@@ -22,14 +22,13 @@ impl Command for CommandImpl {
if !sub_arg_matches.is_present("yes-config-chall") { if !sub_arg_matches.is_present("yes-config-chall") {
return simple_error!("--yes-config-chall is not configed"); return simple_error!("--yes-config-chall is not configed");
} }
let secret_bytes: Vec<u8>; let secret_bytes: Vec<u8> = if let Some(secret) = sub_arg_matches.value_of("secret") {
if let Some(secret) = sub_arg_matches.value_of("secret") { secret.as_bytes().to_vec()
secret_bytes = secret.as_bytes().to_vec();
} else if let Some(secret_hex) = sub_arg_matches.value_of("secret-hex") { } else if let Some(secret_hex) = sub_arg_matches.value_of("secret-hex") {
secret_bytes = hex::decode(secret_hex)?; opt_result!(hex::decode(secret_hex), "Decode secret-hex failed: {}")
} else { } else {
return simple_error!("Secret must assigned"); return simple_error!("Secret must assigned");
} };
// Secret must have 20 bytes // Secret must have 20 bytes
if secret_bytes.len() != 20 { if secret_bytes.len() != 20 {
@@ -47,6 +46,7 @@ impl Command for CommandImpl {
let hmac_key: HmacKey = HmacKey::from_slice(&secret_bytes); let hmac_key: HmacKey = HmacKey::from_slice(&secret_bytes);
let button_press = sub_arg_matches.is_present("button-press"); let button_press = sub_arg_matches.is_present("button-press");
information!("Button press: {}", button_press);
let mut device_config = DeviceModeConfig::default(); let mut device_config = DeviceModeConfig::default();
device_config.challenge_response_hmac(&hmac_key, false, button_press); device_config.challenge_response_hmac(&hmac_key, false, button_press);