-
Notifications
You must be signed in to change notification settings - Fork 171
der: impl DecodeValue/EncodeValue/Tagged for Cow
#2093
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -383,6 +383,9 @@ mod tests { | |
| }; | ||
| use hex_literal::hex; | ||
|
|
||
| #[cfg(feature = "alloc")] | ||
| use {crate::Encode, alloc::borrow::Cow}; | ||
|
|
||
| #[test] | ||
| fn octet_string_decode() { | ||
| // PrintableString "hi" | ||
|
|
@@ -405,6 +408,22 @@ mod tests { | |
| assert_eq!(AsRef::<str>::as_ref(&res), "hi"); | ||
| } | ||
|
|
||
| #[cfg(feature = "alloc")] | ||
| #[test] | ||
| fn cow_octet_string_decode_and_encode() { | ||
| // PrintableString "hi" | ||
| const EXAMPLE: &[u8] = &hex!( | ||
| "040c" // primitive definite length OCTET STRING | ||
| "48656c6c6f2c20776f726c64" // "Hello, world" | ||
| ); | ||
|
|
||
| let decoded = Cow::<OctetStringRef>::from_der(EXAMPLE).unwrap(); | ||
| assert_eq!(decoded.as_bytes(), b"Hello, world"); | ||
|
|
||
| let encoded = decoded.to_der().unwrap(); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nice! So it "just works" 😄 But the sad part is
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Not much that can be done about an I can potentially make |
||
| assert_eq!(EXAMPLE, encoded); | ||
| } | ||
|
|
||
| #[test] | ||
| #[cfg(all(feature = "alloc", feature = "ber"))] | ||
| fn decode_ber_primitive_definite() { | ||
|
|
||
There was a problem hiding this comment.
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"There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
D'oh!