Skip to content

Conversation

@tarcieri
Copy link
Member

@tarcieri tarcieri commented Nov 7, 2025

Also includes a POC that the traits work with OctetStringRef

cc @dishmaker

@tarcieri tarcieri force-pushed the der/cow-trait-impls branch from eddff1f to c4a09a3 Compare November 7, 2025 23:06
Also includes a POC that the traits work with `OctetStringRef`
@tarcieri tarcieri force-pushed the der/cow-trait-impls branch from c4a09a3 to aae1db2 Compare November 7, 2025 23:08
@tarcieri tarcieri merged commit c8ff2bd into master Nov 7, 2025
107 checks passed
@tarcieri tarcieri deleted the der/cow-trait-impls branch November 7, 2025 23:23
#[cfg(feature = "alloc")]
#[test]
fn cow_octet_string_decode_and_encode() {
// PrintableString "hi"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's not a PrintableString "hi"

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

D'oh!

let decoded = Cow::<OctetStringRef>::from_der(EXAMPLE).unwrap();
assert_eq!(decoded.as_bytes(), b"Hello, world");

let encoded = decoded.to_der().unwrap();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice! So it "just works" 😄

But the sad part is Cow<BitStringRef> and "alloc"-gated Cow.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not much that can be done about an alloc-gated Cow. You can make the type generic so you can swap out Cow<'a, OctetStringRef> for &'a OctetStringRef>.

I can potentially make BitStringRef work, though it will be somewhat annoying.

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.

3 participants