chore: only print json when success
This commit is contained in:
@@ -44,8 +44,6 @@ impl Command for CommandImpl {
|
||||
|
||||
let mut yubi = Yubico::new();
|
||||
|
||||
let mut json = BTreeMap::<&'_ str, String>::new();
|
||||
|
||||
if let Ok(device) = yubi.find_yubikey() {
|
||||
success!("Found key, Vendor ID: {:?} Product ID {:?}", device.vendor_id, device.product_id);
|
||||
|
||||
@@ -67,11 +65,14 @@ impl Command for CommandImpl {
|
||||
let hex_sha512 = iff!(sha512_output, Some(crate::digest::sha512_bytes(v)), None);
|
||||
|
||||
if json_output {
|
||||
let mut json = BTreeMap::<&'_ str, String>::new();
|
||||
json.insert("challenge_hex", hex::encode(challenge_bytes));
|
||||
json.insert("response_hex", hex_string);
|
||||
hex_sha256.map(|hex_sha256| json.insert("response_sha256_hex", hex::encode(hex_sha256)));
|
||||
hex_sha384.map(|hex_sha384| json.insert("response_sha384_hex", hex::encode(hex_sha384)));
|
||||
hex_sha512.map(|hex_sha512| json.insert("response_sha512_hex", hex::encode(hex_sha512)));
|
||||
|
||||
println!("{}", serde_json::to_string_pretty(&json).unwrap());
|
||||
} else {
|
||||
success!("Challenge HEX: {}", hex::encode(challenge_bytes));
|
||||
success!("Response HEX: {}", hex_string);
|
||||
@@ -83,10 +84,6 @@ impl Command for CommandImpl {
|
||||
warning!("Yubikey not found");
|
||||
}
|
||||
|
||||
if json_output {
|
||||
println!("{}", serde_json::to_string_pretty(&json).unwrap());
|
||||
}
|
||||
|
||||
Ok(None)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user