@@ -159,7 +159,7 @@ pub use self::allocating::OctetString;
159159#[ cfg( feature = "alloc" ) ]
160160mod allocating {
161161 use super :: * ;
162- use crate :: { BytesOwned , referenced:: * } ;
162+ use crate :: { referenced:: * , BytesOwned } ;
163163 use alloc:: { borrow:: Cow , boxed:: Box , vec:: Vec } ;
164164
165165 /// ASN.1 `OCTET STRING` type: owned form.
@@ -375,7 +375,25 @@ mod tests {
375375
376376 #[ test]
377377 #[ cfg( feature = "alloc" ) ]
378- fn decode_ber ( ) {
378+ fn decode_ber_primitive_definite ( ) {
379+ use crate :: { Decode , asn1:: OctetString } ;
380+ use hex_literal:: hex;
381+
382+ const EXAMPLE : & [ u8 ] = & hex ! (
383+ "040c" // primitive definite length OCTET STRING
384+ "48656c6c6f2c20776f726c64" // "Hello, world"
385+ ) ;
386+
387+ let decoded = OctetString :: from_ber ( EXAMPLE ) . unwrap ( ) ;
388+ assert_eq ! ( decoded. as_bytes( ) , b"Hello, world" ) ;
389+
390+ let decoded = OctetString :: from_der ( EXAMPLE ) . unwrap ( ) ;
391+ assert_eq ! ( decoded. as_bytes( ) , b"Hello, world" ) ;
392+ }
393+
394+ #[ test]
395+ #[ cfg( feature = "alloc" ) ]
396+ fn decode_ber_constructed_indefinite ( ) {
379397 use crate :: { Decode , asn1:: OctetString } ;
380398 use hex_literal:: hex;
381399
@@ -390,6 +408,28 @@ mod tests {
390408 assert_eq ! ( decoded. as_bytes( ) , b"Hello, world" ) ;
391409 }
392410
411+ #[ test]
412+ #[ cfg( feature = "alloc" ) ]
413+ fn decode_ber_constructed_definite ( ) {
414+ use crate :: { Decode , Error , ErrorKind , Length , Tag , asn1:: OctetString } ;
415+ use hex_literal:: hex;
416+
417+ const EXAMPLE_BER : & [ u8 ] = & hex ! (
418+ "2410" // Constructed definite length OCTET STRING
419+ "040648656c6c6f2c" // Segment containing "Hello,"
420+ "040620776f726c64" // Segment containing " world"
421+ ) ;
422+
423+ let err = OctetString :: from_ber ( EXAMPLE_BER ) . err ( ) . unwrap ( ) ;
424+ let expected = Error :: new (
425+ ErrorKind :: Noncanonical {
426+ tag : Tag :: OctetString ,
427+ } ,
428+ Length :: new ( 1 ) ,
429+ ) ;
430+ assert_eq ! ( expected, err) ;
431+ }
432+
393433 #[ test]
394434 #[ cfg( feature = "alloc" ) ]
395435 fn decode_context_specific_ber_explicit ( ) {
0 commit comments