Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Write tests for functions that call send #2

Closed
Fethbita opened this issue Apr 17, 2024 · 2 comments · Fixed by #4
Closed

Write tests for functions that call send #2

Fethbita opened this issue Apr 17, 2024 · 2 comments · Fixed by #4

Comments

@Fethbita
Copy link
Owner

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: bluetech/pcsc-rust#50.

The functions that can get unit tests after this are:

@dishmaker
Copy link

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> {
    // ...

}

@Fethbita
Copy link
Owner Author

Fethbita commented Oct 6, 2024

Thank you for the tip @dishmaker. Implemented this solution in #4, also implementing a trait based solution for the Rng.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants