bluetech / pcsc-rust

Rust bindings to PC/SC for smart card communication
https://docs.rs/pcsc
MIT License
104 stars 24 forks source link

How to mock a Card #50

Open Fethbita opened 3 months ago

Fethbita commented 3 months ago

Hi, I am writing an application that uses pcsc and I have a struct that holds a Card. Some functions of this struct use card.transmit to send and receive APDUs and process them. I would like to be able to mock Card so that I can test these processing functions. What do you use for mocking Card?

bluetech commented 2 months ago

It mostly depends, do you care about the actual APDUs/RAPDUs i.e. do you want to simulate the logic of an actual card, or do you just need some dummy for tests?

Fethbita commented 2 months ago

I only need a dummy for tests to begin with.

Edit: When I say dummy, for my use case it would be the best if I could choose what the transmit function returns, that way I could test the functions with test vectors.