Skip to content

Commit

Permalink
Replace println! from library functions with configurable logging (#…
Browse files Browse the repository at this point in the history
…424)

* Replace `println!` from library functions with configurable logging

Developers building on this crate do not necessarily need logging to
occur over `println!` when authenticating 2FA, so this commit replaces
the print macros with logging macros
  • Loading branch information
mishazharov authored Apr 10, 2024
1 parent 1386f66 commit 869a0b9
Showing 1 changed file with 11 additions and 13 deletions.
24 changes: 11 additions & 13 deletions webauthn-authenticator-rs/src/mozilla.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,19 +58,19 @@ impl MozillaAuthenticator {
let _thread_handle = thread::spawn(move || loop {
match status_rx.recv() {
Ok(StatusUpdate::DeviceAvailable { dev_info }) => {
println!("STATUS: device available: {}", dev_info)
debug!("STATUS: device available: {}", dev_info)
}
Ok(StatusUpdate::DeviceUnavailable { dev_info }) => {
println!("STATUS: device unavailable: {}", dev_info)
debug!("STATUS: device unavailable: {}", dev_info)
}
Ok(StatusUpdate::Success { dev_info }) => {
println!("STATUS: success using device: {}", dev_info);
debug!("STATUS: success using device: {}", dev_info);
}
Ok(StatusUpdate::SelectDeviceNotice) => {
println!("STATUS: Please select a device by touching one of them.");
info!("STATUS: Please select a device by touching one of them.");
}
Ok(StatusUpdate::DeviceSelected(dev_info)) => {
println!("STATUS: Continuing with device: {}", dev_info);
debug!("STATUS: Continuing with device: {}", dev_info);
}
Ok(StatusUpdate::PinError(error, sender)) => match error {
PinError::PinRequired => {
Expand All @@ -80,7 +80,7 @@ impl MozillaAuthenticator {
continue;
}
PinError::InvalidPin(attempts) => {
println!(
error!(
"Wrong PIN! {}",
attempts.map_or("Try again.".to_string(), |a| format!(
"You have {} attempts left.",
Expand All @@ -93,19 +93,17 @@ impl MozillaAuthenticator {
continue;
}
PinError::PinAuthBlocked => {
eprintln!("Too many failed attempts in one row. Your device has been temporarily blocked. Please unplug it and plug in again.")
error!("Too many failed attempts in one row. Your device has been temporarily blocked. Please unplug it and plug in again.")
}
PinError::PinBlocked => {
eprintln!(
"Too many failed attempts. Your device has been blocked. Reset it."
)
error!("Too many failed attempts. Your device has been blocked. Reset it.")
}
e => {
eprintln!("Unexpected error: {:?}", e)
error!("Unexpected error: {:?}", e)
}
},
Err(RecvError) => {
println!("STATUS: end");
debug!("STATUS: end");
return;
}
}
Expand Down Expand Up @@ -196,7 +194,7 @@ impl AuthenticatorBackend for MozillaAuthenticator {
let (attestation_object, client_data) = match register_result {
Ok(RegisterResult::CTAP1(_, _)) => return Err(WebauthnCError::PlatformAuthenticator),
Ok(RegisterResult::CTAP2(a, c)) => {
println!("Ok!");
trace!("Ok!");
(a, c)
}
Err(_e) => return Err(WebauthnCError::PlatformAuthenticator),
Expand Down

0 comments on commit 869a0b9

Please sign in to comment.