formats icon indicating copy to clipboard operation
formats copied to clipboard

der_derive: Generate ASN.1 schema from Rust types

Open dima-starosud opened this issue 3 years ago • 4 comments

This is the feature request.

Usually, when working with external formats there is either:

  • schema-first approach:
    • e.g. having my_type.proto one can generate source code for it;
  • or code-first approach:
    • e.g. async_graphql allows dumping GraphQL schema from Rust types which we derived GraphQL support for;
    • or, probably, the most popular, code-first approach used in many modern SQL ORMs;

Anyway, in both cases, we have a schema that we can share with clients or services.

It would be nice to have the same feature provided by der_derive crate, e.g. having a bunch of enum/struct with derived Sequence or Choice be able to derive corresponding ASN.1 schema for these types.

This will allow writing app deriving ASN.1 support for types and later sharing generated schema with clients. Otherwise, when we have just Rust types with derived ASN.1 support, we cannot immediately tell what data will be accepted by those types. One has to try and fail before he would find the correct ASN.1 format.

dima-starosud avatar Sep 15 '22 11:09 dima-starosud

Some way of generating code from ASN.1 schemas would be nice.

It sounds like you're requesting the other direction, though? I'm not aware of any implementation of schema-driven data formats which works that way, being able to produce a schema from source code.

DER is primarily used in cryptography-related specifications originally created/popularized in the '90s. I wouldn't recommend using it for greenfield applications.

tarcieri avatar Sep 15 '22 17:09 tarcieri

Not sure regarding the '90s 😁 I've decided to use ASN.1 and this crate is one of the most popular for Rust. Anyway, to me this point seems a bit of off topic 🤔

I named GraphQL and SQL, but there are other examples of code-first approaches. My point here is that when we have just a struct with derived ASN.1 support, we cannot immediately tell what data will be accepted by that struct. One has to try and fail before it would find the correct ASN.1 format (will add this to the ticket description).

dima-starosud avatar Sep 16 '22 11:09 dima-starosud

Schema derivation will have lots of issues, including optional fields, open types, enum values, named bits, etc., so this would not reduce try and fail by much.

From: dima-starosud @.> Reply-To: RustCrypto/formats @.> Date: Friday, September 16, 2022 at 4:28 AM To: RustCrypto/formats @.> Cc: Subscribed @.> Subject: Re: [RustCrypto/formats] der_derive: Generate ASN.1 schema from Rust types (Issue #722)

Not sure regarding the '90s 😁 I've decided to use ASN.1 and this crate is one of the most popular for Rust. Anyway, to me this point seems a bit of off topic 🤔

I named GraphQL and SQL, but there are other examples of code-first approaches. My point here is that when we have just a struct with derived ASN.1 support, we cannot immediately tell what data will be accepted by that struct. One has to try and fail before it would find the correct ASN.1 format (will add this to the ticket description).

— Reply to this email directly, view it on GitHub, or unsubscribe. You are receiving this because you are subscribed to this thread.Message ID: @.***>

carl-wallace avatar Sep 16 '22 13:09 carl-wallace

I've decided to use ASN.1 and this crate is one of the most popular for Rust.

Note that DER is a special encoding of ASN.1 known as the distinguished representation, which is primarily oriented towards cryptography applications (particularly those use cases involving signed data).

If you're looking for a more general-purpose encoding like Protobuf, you'll probably want BER, which isn't supported by this library.

tarcieri avatar Sep 16 '22 13:09 tarcieri

I don't think we're going to end up implementing anything like this, at least in the near future

tarcieri avatar Aug 18 '24 17:08 tarcieri