INTEGER as C-like enums ( or enums with discriminators) #40
-
I have the following ASN.1 Result ::= INTEGER {
acceptance (0),
user-rejection (1),
provider-rejection (2)
} One way to represent this in rust would be #[derive(Debug, AsnType, Encode, Decode)]
#[rasn(automatic_tags)]
struct StructContainingResult {
result: rasn::types::Integer
} However I would then have to write code to check if #[derive(Debug, AsnType, Encode, Decode)]
#[repr(u8)]
enum Result {
Acceptance=0,
UserRejection=1,
ProviderRejection=2
} (I know the ideal answer is "try and test" but I actually don't know how to calculate the encoding by hand) |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
Thank you for your question. Yeah this falls under #6 as providing constraints for integers, which isn't supported directly at the moment. For this specific instance though, you should be able to model pretty well in |
Beta Was this translation helpful? Give feedback.
Thank you for your question. Yeah this falls under #6 as providing constraints for integers, which isn't supported directly at the moment.
For this specific instance though, you should be able to model pretty well in
rasn
by usingenumerated
and setting#[rasn(tag(universal, 2)]
, which would encode it as an integer but also check if it matches any of the variants. It's a bit hacky, but if you don't want to write the validation it should work.