librasn / rasn

A Safe #[no_std] ASN.1 Codec Framework
Other
199 stars 50 forks source link

Invalid allowed characters for VisibleString type #146

Closed Nicceboy closed 11 months ago

Nicceboy commented 1 year ago

Hey,

it seems like VisibleString allows too many characters.

Currently it supports full range of 7-bit ASCII, while it should limit the support for characters specified in ISO International Register of Coded Character Sets, registration 6. + SPACE character. (ITU-T Rec. X.680 (02/2021), Section 41, Table 8.)

Registration number 6. limits the allowed characters into so called ASCII graphics set, which has 94 characters.

Unfortunately these standards are still behind paywalls, but one might find readable version by a little bit of searching.

I might make a PR to fix this. Also the from_iso646_bytes function requires relative fix so that type restriction can be applied.

Should we also create "new" function for these string types to enforce type restrictions further or is it unnecessary? I would like to trust for the input when defining encoder so that the coming type does not contain disallowed characters

XAMPPRocky commented 1 year ago

Should we also create "new" function for these string types to enforce type restrictions further or is it unnecessary? I would like to trust for the input when defining encoder so that the coming type does not contain disallowed characters

Yes, the type should require valid characters at creation time, the function shouldn't be called new however it should be try_from_* where * is the input source (e.g. try_from_bytes). new should be reserved for creating empty strings.