der-parser icon indicating copy to clipboard operation
der-parser copied to clipboard

Concatenate a relative OID onto a base OID

Open lilyball opened this issue 4 years ago • 3 comments

I would really like to be able to concatenate relative OIDs onto base OIDs at compile-time. I'm not sure if this is actually possible, but I want to be able to write something like

const OID_BASE: Oid = oid!(1.2.840.1234);
const OID_SUB_1: Oid = oid!(OID_BASE 10);
const OID_SUB_2: Oid = oid!(OID_SUB_1 15);

Or some alternative syntax that achieves the same thing. I don't know if there's any way to achieve this without heap allocation. I really wish Rust had built-in syntax for "please flatten this array into the enclosing array literal".

The goal here is of course to be able to represent a tree of OIDs using a similar structure to how they're declared in ASN.1, instead of having to repeat the OID base everywhere.

lilyball avatar Jun 17 '21 07:06 lilyball

After looking into proc macros some more, I'm pretty sure this isn't possible.

What should be possible though is writing an oid_tree!() macro that lets you define a whole set of OIDs, where base OIDs can have children that are prefixed by the base. I'm currently working on such a macro for my own project, but I'd love to see this crate offer it directly.

lilyball avatar Jun 17 '21 19:06 lilyball

@lilyball We can probably achieve this with changes like https://github.com/rusticata/der-parser/pull/45

zotho avatar Jun 18 '21 14:06 zotho

I would love to see that at build time, but I don't think there is a way to resolve a symbol value in a proc-macro (or macro). Maybe #45 is a solution (see the PR for discussion).

chifflier avatar Jul 09 '21 13:07 chifflier