Skip to content
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

der: unified generic *String/*StringRef types #1061

Open
tarcieri opened this issue May 13, 2023 · 0 comments
Open

der: unified generic *String/*StringRef types #1061

tarcieri opened this issue May 13, 2023 · 0 comments

Comments

@tarcieri
Copy link
Member

tarcieri commented May 13, 2023

We currently use the impl_string_type! macro to write the bodies of various ASN.1 string types.

For each ASN.1 type, we support an owned (*String) and borrowed (*StringRef) type.

Instead I think we could potentially have two generic types, e.g. StringType and StringRefType.

We need to make them generic around a value (the tag) though, so this seems like a use case for const generics. Unfortunately we model Tag as an enum, which we can't use as a const generic parameter until the adt_const_params feature is stabilized. However, this enum is repr(u8), so it's possible to use e.g. const TAG: u8 as the const generic parameter, casting/converting the Tag into a u8 (temporarily until adt_const_params are stabilized).

Really the various string types differ in two respects:

  1. The tag, which is captured as a const generic parameter per above
  2. Validation rules, i.e. what characters are allowed in the constructor

To capture these concerns I propose making a trait which can be impl'd for a const generic StringType/StringTypeRef containing these validation rules.

Then the existing types can become type aliases, e.g. pub type Ia5String = StringType<Tag::Ia5String as u8>

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant