rusticata / der-parser

BER/DER parser written in pure Rust. Fast, zero-copy, safe.
Apache License 2.0
84 stars 29 forks source link

Concatenate a OIDs #45

Open zotho opened 3 years ago

zotho commented 3 years ago

Just draft to implement possibility of https://github.com/rusticata/der-parser/issues/44

const A: Oid = oid!(1.2.3);
const B: Oid = oid_append!(A, 4.5); // 1.2.3.4.5
const C: Oid = oid_append!(A, B);   // 1.2.3.1.2.3.4.5

But this functionality requires #![feature(const_precise_live_drops)]

lilyball commented 3 years ago

How much of a change would it be to change Oid so instead of exposing a single slice of bytes, it exposed an iterator of byte slices instead? This way an Oid could have an optional base_oid field. Serializing and equality comparisons would use the iterator. This would be a breaking change of course, as we'd be removing the byte slice view, but it allows for trivial compile-time and runtime appending. The biggest issue I can see (beyond it being a breaking change) is that ideally you'd want to only allow appending of relative Oids to a base, but this isn't expressed in the type system, so you'd have to define some reasonable behavior for what happens if you append an absolute Oid to another one (the obvious behavior is to treat the absolute one as a relative one instead, which just expands its encoding by one byte, and means oid!(1.2.3) + oid!(4.5.6) doesn't punish me for forgetting the rel keyword).