-
Notifications
You must be signed in to change notification settings - Fork 4
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
Support for all status bytes #10
Comments
I'm not a fan of this approach - the point of using enums to me is to make the universe of possibilities smaller, not allow random bytes throughout the following code (https://lexi-lambda.github.io/blog/2019/11/05/parse-don-t-validate/). If there is an We already have the TryInto (https://github.com/ycrypto/iso7816/blob/main/src/response/status.rs#L83) though, which encodes this philosophy. What is wrong with adding variants as needed? Or doing a full pass to add most of them? Using the C approach (like reqwest) does not seem to me to make anything easier or more ergonomic. |
The constants (public or maybe private) could still be helpful to remove duplication of explicit codes in the two conversions between parsed and raw. Maybe a quick macro-rules macro to define the constants and the two conversions? |
That's not really possible because you can't make enum constructors private.
It's not really used anywhere though. Also, adding an
The only invalid SW bytes according to // Choice one: Use a default status if the Status bytes failed to parse (data loss, especially a pain currently when I'm doing debugging).
fn do_something() -> Result<Data, Status>;
// Choice 2: Return the SW bytes if they're incorrect: Overall a pretty bad API.
fn do_something() -> Result<Data, Result<Status, u16>>; Enums also prevent renaming (without a breaking change), and a lot of the current names don't properly reflect their ISO7816-4 meaning. For example |
I think I have found a better option: simply make the |
Done by #17 |
The
Status
enum contains a number of status bytes, but not all defined by the specifications. It also does not contain a fallback (Unknown(u16)
) variant that could be used to encode unknown bytes, like doesopenpgp-card
I think we should add such a variant. However this can become an issue when matching against bytes. For example if one wants to test that a given status bytes are Success, they would need to match against both
Success
andUnknown::(0x9000)
which can be tedious and lead to inconsistencies.I suggest we instead change
Status
to a newtypeStatus(u16)
with a bunch of associated constants for known values. You can still do pattern matching with the constants.For example, reqwest uses this pattern instead of an enum for HTTP status codes: https://docs.rs/reqwest/latest/reqwest/struct.StatusCode.html#associatedconstant.ACCEPTED
The text was updated successfully, but these errors were encountered: