librasn / compiler

An ASN1 compiler producing Rust bindings for the rasn framework
Other
13 stars 7 forks source link

Add a fallible new_with_constraints or similar? #30

Closed shahn closed 3 months ago

shahn commented 3 months ago

Would there be interest in deriving a function which checks the constraints when constructing an AsnType, such as new_with_constraints() -> Result <_, ConstraintError>? That would allow users to ensure they are not operating with invalid values in their application logic before calling encode.

6d7a commented 3 months ago

Thank you for your issue. As I understand it, the feature would rather be part of rasn itself than the compiler. Please feel free to open an issue here. That said, I guess the constraint checker would run pretty much the same logic under the hood as the encode function, so you could just call encode and check the Err of the returned Result. Let us know though, if there is something missing in the error reporting of the encoder.

shahn commented 2 months ago

I think the error reporting is fine, the idea was just to use the types generated by rasn-compiler as "definitely valid, encoding won't fail" types. Your reasoning is totally understandable though, thanks for providing your rationale. 👍