Callers of this function always pad up to `CB_PIN_MAX` with `0xFF`.
The logic being changed here was previously identical to the `_verify`
function in `ykpiv.c`:
https://github.com/Yubico/yubico-piv-tool/blob/8ba243f/lib/ykpiv.c#L1299
...but @str4d noticed this potentially allows a caller to send an
unpadded PIN, which may (or may not) be an issue.
It seems like given we're inside a while loop which also has this
conditional, the original code should've been fine, but this change
makes it closer to the original C code.
This commit contains a "big bang" refactor/rewrite which does the
following:
- Replaces all `SCard*` FFI calls with the `pcsc` crate, which provides
a safe, portable PC/SC API across Windows, macOS, and Linux
- Refactors the `util` module into modules representing the various
device functions and concepts, e.g. `certificate`, `key`, `mgm`
- Replaces all usage of `libc` with `std` functionality, and in many
places rewriting functionality to use safe code.
- Removes `ykpiv_` from all function names, and `Piv*` from type names.
In 20/20 hindsight I wish I had done this commit more incrementally so
as to make it easier to review. Que sera sera.
However, realistically we need to test all functionality on the device
to ensure that it actually works. Going forward I would like to put
pretty much all of the current code behind an `untested` cargo feature,
and then remove it for each bit of functionality we test.
Changes the `APDU` struct into a builder for serialized APDU messages.
This makes APDU construction safer and more idiomatic, and also caught a
few bugs in the process (missing templ from the C translation).
There was originally another `Error` type from the translation. Now that
it's gone, and we don't presently have a type just named `Error`, this
renames the current `ErrorKind` type now that the original was deleted.
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!