Skip to content

Make ObjectIdentifier::as_der public#598

Merged
alex merged 2 commits intoalex:mainfrom
sivizius:expose-as_der-for-oids
Mar 11, 2026
Merged

Make ObjectIdentifier::as_der public#598
alex merged 2 commits intoalex:mainfrom
sivizius:expose-as_der-for-oids

Conversation

@sivizius
Copy link
Contributor

I use this crate primarily for its OID type. It’s unlikely that the current internal implementation will significantly change, so exposing the inner slice for reading is more useful than using with fallible (yet never failing) SimpleAsn1Writable methods.

@alex
Copy link
Owner

alex commented Feb 16, 2026

I'd be ok making as_der() public, I don't think it makes sense to do AsRef<> though.

@sivizius
Copy link
Contributor Author

I don't think it makes sense to do AsRef<> though.

There are quite a lot of functions/methods expecting T where T: AsRef<[u8]> or similar, e.g. https://docs.rs/sha1/latest/sha1/trait.Digest.html, https://doc.rust-lang.org/std/fs/fn.write.html. I was considering making as_der public, which is indeed more explicit, but the use of .as_der() everywhere feels a bit unnecessary because AsRef<[u8]> already narrows it done to some binary representation and there isn’t really another one which isn’t rather obscure. IIRC, a DER encoded OID is valid BER and CER encoding.

@alex
Copy link
Owner

alex commented Mar 11, 2026

I don't think Digest is a good analogy here. Code should be clear and readable, and explicitly indicating that what you want is DER contributes to that.

Signed-off-by: Sebastian Walz <sebastian.walz@secunet.com>
Signed-off-by: Sebastian Walz <sebastian.walz@secunet.com>
@sivizius sivizius force-pushed the expose-as_der-for-oids branch from 7695513 to 4f384f0 Compare March 11, 2026 12:54
@sivizius
Copy link
Contributor Author

I changed it as suggested (public as_der), impl AsRef<[u8]> might be subject of another PR, but it’s fine for my use case.

@sivizius sivizius changed the title impl AsRef<[u8]> for ObjectIdentifier Make ObjectIdentifier::as_der public Mar 11, 2026
@alex alex merged commit d9feaa2 into alex:main Mar 11, 2026
13 checks passed
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

Successfully merging this pull request may close these issues.

2 participants