Fethbita / emrtd

Rust eMRTD
Apache License 2.0
2 stars 0 forks source link

Write tests for functions that call `send` #2

Open Fethbita opened 5 months ago

Fethbita commented 5 months ago

Using test vectors and by mocking the send or card.transmit functions, unit tests for functions that call the send function can be written. However mocking a pcsc::Card proved to be difficult, an issue is created in pcsc GitHub: https://github.com/bluetech/pcsc-rust/issues/50.

The functions that can get unit tests after this are:

dishmaker commented 1 month ago

I think you can create a trait like:

pub trait MrtdCard {

    /// Returns answer to reset
    fn atr(&self) -> Result<Vec<u8>>

    /// Returns R-APDU including 2 bytes SW
    fn transmit(&self, c_apdu: &[u8]) -> Result<Vec<u8>>

}

so that your wrapper takes a generic param:


pub struct EmrtdComms<C: MrtdCard> {
    // ...
}

impl<C: MrtdCard> EmrtdComms<C> {
    // ...

}