@@ -73,6 +73,16 @@ impl<'a> DecodeValue<'a> for &'a OctetStringRef {
7373 }
7474}
7575
76+ impl EncodeValue for OctetStringRef {
77+ fn value_len ( & self ) -> Result < Length , Error > {
78+ self . inner . value_len ( )
79+ }
80+
81+ fn encode_value ( & self , writer : & mut impl Writer ) -> Result < ( ) , Error > {
82+ self . inner . encode_value ( writer)
83+ }
84+ }
85+
7686impl EncodeValue for & OctetStringRef {
7787 fn value_len ( & self ) -> Result < Length , Error > {
7888 self . inner . value_len ( )
@@ -383,6 +393,9 @@ mod tests {
383393 } ;
384394 use hex_literal:: hex;
385395
396+ #[ cfg( feature = "alloc" ) ]
397+ use alloc:: borrow:: Cow ;
398+
386399 #[ test]
387400 fn octet_string_decode ( ) {
388401 // PrintableString "hi"
@@ -405,6 +418,23 @@ mod tests {
405418 assert_eq ! ( AsRef :: <str >:: as_ref( & res) , "hi" ) ;
406419 }
407420
421+ #[ cfg( feature = "alloc" ) ]
422+ #[ test]
423+ fn cow_octet_string_decode_and_encode ( ) {
424+ // PrintableString "hi"
425+ const EXAMPLE : & [ u8 ] = & hex ! (
426+ "040c" // primitive definite length OCTET STRING
427+ "48656c6c6f2c20776f726c64" // "Hello, world"
428+ ) ;
429+
430+ let decoded = Cow :: < OctetStringRef > :: from_der ( EXAMPLE ) . unwrap ( ) ;
431+ assert_eq ! ( decoded. as_bytes( ) , b"Hello, world" ) ;
432+
433+ use crate :: Encode ;
434+ let encoded = decoded. to_der ( ) . unwrap ( ) ;
435+ assert_eq ! ( EXAMPLE , encoded) ;
436+ }
437+
408438 #[ test]
409439 #[ cfg( all( feature = "alloc" , feature = "ber" ) ) ]
410440 fn decode_ber_primitive_definite ( ) {
0 commit comments