Use log crate for logging

Switches all of the previous `state->verbose`-gated `eprintln!` calls to
use macros from the `log` crate, trying to map them onto the previous
verbosity levels, more or less following this mapping:

0. off
1. error/info/warn (depending on context)
2. trace

This additionally includes a bunch of logic/branch reformatting (and
occasional missed constants), since getting rid of all the gating on
verbose provided ample opportunities to clean up the code. Hopefully I
didn't break too much in the process!
This commit is contained in:
Tony Arcieri
2019-11-20 11:28:43 -08:00
parent f25eed1a86
commit c3d5df1643
5 changed files with 633 additions and 878 deletions
+16 -6
View File
@@ -1,5 +1,6 @@
//! Application Protocol Data Unit (APDU)
use std::fmt::{self, Debug};
use zeroize::Zeroize;
/// Application Protocol Data Unit (APDU).
@@ -28,12 +29,6 @@ pub struct APDU {
}
impl APDU {
/// Get a const pointer to this APDU
// TODO(tarcieri): eliminate pointers and use all safe references
pub(crate) fn as_ptr(&self) -> *const APDU {
self
}
/// Get a mut pointer to this APDU
// TODO(tarcieri): eliminate pointers and use all safe references
pub(crate) fn as_mut_ptr(&mut self) -> *mut APDU {
@@ -41,6 +36,21 @@ impl APDU {
}
}
impl Debug for APDU {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(
f,
"APDU {{ cla: {}, ins: {}, p1: {}, p2: {}, lc: {}, data: {:?} }}",
self.cla,
self.ins,
self.p1,
self.p2,
self.lc,
&self.data[..]
)
}
}
impl Default for APDU {
fn default() -> Self {
Self {