oxidize: Fix second pass of compile errors and commented-out code

This commit gets the Rust code to compile! 🎉

Additionally, it fixes all of the commented out code that was failing
translation from C due to the use of unions, namely around the APDU
messages.

It does a fair amount of reformatting around branches, with the net
result hopefully being something actually a bit closer to the C code,
and a straightforward list of `if` statements.

It also removes all of the remaining externs that aren't supposed to be
externs, replacing them with a more straightforward usage of the module
system.

Finally it fixes all errors and warnings (relating to e.g. usage of
uninitialized memory), in addition to most clippy lints! (some have
been explicitly disabled)

All that said, it still doesn't do anything: it needs to be wired up to
a PCSC library first before that will be possible. But hey, it compiles!
This commit is contained in:
Tony Arcieri
2019-11-17 09:02:18 -08:00
parent 1d86885ab1
commit 7d40a9917e
10 changed files with 5366 additions and 6323 deletions
+66
View File
@@ -0,0 +1,66 @@
//! Application Protocol Data Unit (APDU)
use zeroize::Zeroize;
/// Application Protocol Data Unit (APDU).
///
/// These messages are packets used to communicate with the YubiKey using the
/// Chip Card Interface Device (CCID) protocol.
#[derive(Clone)]
pub struct APDU {
/// Instruction class - indicates the type of command, e.g. interindustry or proprietary
pub cla: u8,
/// Instruction code - indicates the specific command, e.g. "write data"
pub ins: u8,
/// Instruction parameter 1 for the command, e.g. offset into file at which to write the data
pub p1: u8,
/// Instruction parameter 2 for the command
pub p2: u8,
/// Length of command - encodes the number of bytes of command data to follow
pub lc: u8,
/// Command data
pub data: [u8; 255],
}
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 {
self
}
}
impl Default for APDU {
fn default() -> Self {
Self {
cla: 0,
ins: 0,
p1: 0,
p2: 0,
lc: 0,
data: [0u8; 255],
}
}
}
impl Zeroize for APDU {
fn zeroize(&mut self) {
self.cla.zeroize();
self.ins.zeroize();
self.p1.zeroize();
self.p2.zeroize();
self.lc.zeroize();
self.data.zeroize();
}
}