RustCrypto / RustCrypto/formats

der: unified generic `*String`/`*StringRef` types

Open
#1,061 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Rust
Stars
338
Forks
188
Avg merge
4d 6h
Merged PRs (30d)
15

Description

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>

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the impl_string_type! macro in der/src/asn1/internal_macros.rs and inspect the existing owned and borrowed ASN.1 string types it generates. Work out the const-generic tag representation and validation trait, then check that the existing string types can become aliases while retaining their validation behavior and public API.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
cryptography
Issue type
Refactor
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.