@@ -218,7 +218,7 @@ mod allocating {
218218 type Error = Error ;
219219
220220 fn decode_value < R : Reader < ' a > > ( reader : & mut R , header : Header ) -> Result < Self , Error > {
221- let inner = BytesOwned :: decode_value ( reader, header) ?;
221+ let inner = BytesOwned :: decode_value_parts ( reader, header, Self :: TAG ) ?;
222222 Ok ( Self { inner } )
223223 }
224224 }
@@ -363,6 +363,16 @@ mod bytes {
363363mod tests {
364364 use crate :: asn1:: { OctetStringRef , PrintableStringRef } ;
365365
366+ #[ test]
367+ fn octet_string_decode_into ( ) {
368+ // PrintableString "hi"
369+ let der = b"\x13 \x02 \x68 \x69 " ;
370+ let oct = OctetStringRef :: new ( der) . unwrap ( ) ;
371+
372+ let res = oct. decode_into :: < PrintableStringRef < ' _ > > ( ) . unwrap ( ) ;
373+ assert_eq ! ( AsRef :: <str >:: as_ref( & res) , "hi" ) ;
374+ }
375+
366376 #[ test]
367377 #[ cfg( feature = "alloc" ) ]
368378 fn decode_ber ( ) {
@@ -372,7 +382,7 @@ mod tests {
372382 const EXAMPLE_BER : & [ u8 ] = & hex ! (
373383 "2480" // Constructed indefinite length OCTET STRING
374384 "040648656c6c6f2c" // Segment containing "Hello,"
375- "040620776f726c64" // Segment containing world
385+ "040620776f726c64" // Segment containing " world"
376386 "0000" // End-of-contents marker
377387 ) ;
378388
@@ -381,12 +391,62 @@ mod tests {
381391 }
382392
383393 #[ test]
384- fn octet_string_decode_into ( ) {
385- // PrintableString "hi"
386- let der = b"\x13 \x02 \x68 \x69 " ;
387- let oct = OctetStringRef :: new ( der) . unwrap ( ) ;
394+ #[ cfg( feature = "alloc" ) ]
395+ fn decode_context_specific_ber_explicit ( ) {
396+ use crate :: {
397+ EncodingRules , SliceReader , TagNumber ,
398+ asn1:: { ContextSpecific , OctetString } ,
399+ } ;
400+ use hex_literal:: hex;
388401
389- let res = oct. decode_into :: < PrintableStringRef < ' _ > > ( ) . unwrap ( ) ;
390- assert_eq ! ( AsRef :: <str >:: as_ref( & res) , "hi" ) ;
402+ let tag_number = TagNumber ( 0 ) ;
403+
404+ const EXAMPLE_BER : & [ u8 ] = & hex ! (
405+ "A080" // indefinite length explicit tag
406+ "2480" // Constructed indefinite length OCTET STRING
407+ "040648656c6c6f2c" // Segment containing "Hello,"
408+ "040620776f726c64" // Segment containing "world"
409+ "0000" // End-of-contents marker
410+ "0000" // End-of-contents marker
411+ ) ;
412+
413+ let mut reader =
414+ SliceReader :: new_with_encoding_rules ( EXAMPLE_BER , EncodingRules :: Ber ) . unwrap ( ) ;
415+
416+ let decoded = ContextSpecific :: < OctetString > :: decode_explicit ( & mut reader, tag_number)
417+ . unwrap ( )
418+ . unwrap ( )
419+ . value ;
420+
421+ assert_eq ! ( decoded. as_bytes( ) , b"Hello, world" ) ;
422+ }
423+
424+ #[ test]
425+ #[ cfg( feature = "alloc" ) ]
426+ fn decode_context_specific_ber_implicit ( ) {
427+ use crate :: {
428+ EncodingRules , SliceReader , TagNumber ,
429+ asn1:: { ContextSpecific , OctetString } ,
430+ } ;
431+ use hex_literal:: hex;
432+
433+ let tag_number = TagNumber ( 0 ) ;
434+
435+ const EXAMPLE_BER : & [ u8 ] = & hex ! (
436+ "A080" // implicit tag, constructed indefinite length OCTET STRING
437+ "040648656c6c6f2c" // Segment containing "Hello,"
438+ "040620776f726c64" // Segment containing "world"
439+ "0000" // End-of-contents marker
440+ ) ;
441+
442+ let mut reader =
443+ SliceReader :: new_with_encoding_rules ( EXAMPLE_BER , EncodingRules :: Ber ) . unwrap ( ) ;
444+
445+ let decoded = ContextSpecific :: < OctetString > :: decode_implicit ( & mut reader, tag_number)
446+ . unwrap ( )
447+ . unwrap ( )
448+ . value ;
449+
450+ assert_eq ! ( decoded. as_bytes( ) , b"Hello, world" ) ;
391451 }
392452}
0 commit comments