@@ -655,6 +655,38 @@ static const uint8_t kWrappedIndefBER[] = {0x30, 0x08, 0x30, 0x04, 0x30,
655655static const uint8_t kWrappedIndefDER [] = {0x30 , 0x06 , 0x30 , 0x02 ,
656656 0x30 , 0x00 , 0x30 , 0x00 };
657657
658+ // kConstructedStringBER contains a deeply-nested constructed OCTET STRING.
659+ // The BER conversion collapses this to one level deep, but not completely.
660+ static const uint8_t kConstructedStringBER [] = {
661+ 0xa0 , 0x10 , 0x24 , 0x06 , 0x04 , 0x01 , 0x00 , 0x04 , 0x01 ,
662+ 0x01 , 0x24 , 0x06 , 0x04 , 0x01 , 0x02 , 0x04 , 0x01 , 0x03 ,
663+ };
664+ static const uint8_t kConstructedStringDER [] = {
665+ 0xa0 , 0x08 , 0x04 , 0x02 , 0x00 , 0x01 , 0x04 , 0x02 , 0x02 , 0x03 ,
666+ };
667+
668+ // kWrappedConstructedStringBER contains a constructed OCTET STRING, wrapped
669+ // and followed by valid DER. This tests that we correctly identify BER nested
670+ // inside DER.
671+ //
672+ // SEQUENCE {
673+ // SEQUENCE {
674+ // [OCTET_STRING CONSTRUCTED] {
675+ // OCTET_STRING {}
676+ // }
677+ // }
678+ // SEQUENCE {}
679+ // }
680+ static const uint8_t kWrappedConstructedStringBER [] = {
681+ 0x30 , 0x08 , 0x30 , 0x04 , 0x24 , 0x02 , 0x04 , 0x00 , 0x30 , 0x00 };
682+ static const uint8_t kWrappedConstructedStringDER [] = {
683+ 0x30 , 0x06 , 0x30 , 0x02 , 0x04 , 0x00 , 0x30 , 0x00 };
684+
685+ // kConstructedBitString contains a BER constructed BIT STRING. These are not
686+ // supported and thus are left unchanged.
687+ static const uint8_t kConstructedBitStringBER [] = {
688+ 0x23 , 0x0a , 0x03 , 0x03 , 0x00 , 0x12 , 0x34 , 0x03 , 0x03 , 0x00 , 0x56 , 0x78 };
689+
658690TEST (CBSTest, BerConvert) {
659691 static const uint8_t kSimpleBER [] = {0x01 , 0x01 , 0x00 };
660692
@@ -686,38 +718,6 @@ TEST(CBSTest, BerConvert) {
686718 0x6e , 0x10 , 0x9b , 0xb8 , 0x02 , 0x02 , 0x07 , 0xd0 ,
687719 };
688720
689- // kConstructedStringBER contains a deeply-nested constructed OCTET STRING.
690- // The BER conversion collapses this to one level deep, but not completely.
691- static const uint8_t kConstructedStringBER [] = {
692- 0xa0 , 0x10 , 0x24 , 0x06 , 0x04 , 0x01 , 0x00 , 0x04 , 0x01 ,
693- 0x01 , 0x24 , 0x06 , 0x04 , 0x01 , 0x02 , 0x04 , 0x01 , 0x03 ,
694- };
695- static const uint8_t kConstructedStringDER [] = {
696- 0xa0 , 0x08 , 0x04 , 0x02 , 0x00 , 0x01 , 0x04 , 0x02 , 0x02 , 0x03 ,
697- };
698-
699- // kWrappedConstructedStringBER contains a constructed OCTET STRING, wrapped
700- // and followed by valid DER. This tests that we correctly identify BER nested
701- // inside DER.
702- //
703- // SEQUENCE {
704- // SEQUENCE {
705- // [OCTET_STRING CONSTRUCTED] {
706- // OCTET_STRING {}
707- // }
708- // }
709- // SEQUENCE {}
710- // }
711- static const uint8_t kWrappedConstructedStringBER [] = {
712- 0x30 , 0x08 , 0x30 , 0x04 , 0x24 , 0x02 , 0x04 , 0x00 , 0x30 , 0x00 };
713- static const uint8_t kWrappedConstructedStringDER [] = {
714- 0x30 , 0x06 , 0x30 , 0x02 , 0x04 , 0x00 , 0x30 , 0x00 };
715-
716- // kConstructedBitString contains a BER constructed BIT STRING. These are not
717- // supported and thus are left unchanged.
718- static const uint8_t kConstructedBitStringBER [] = {
719- 0x23 , 0x0a , 0x03 , 0x03 , 0x00 , 0x12 , 0x34 , 0x03 , 0x03 , 0x00 , 0x56 , 0x78 };
720-
721721 ExpectBerConvert (" kSimpleBER" , kSimpleBER , kSimpleBER );
722722 ExpectBerConvert (" kNonMinimalLengthBER" , kNonMinimalLengthDER ,
723723 kNonMinimalLengthBER );
@@ -762,12 +762,23 @@ TEST(CBSTest, IndefiniteBerASN1Macros) {
762762 kWrappedIndefBER + sizeof (kWrappedIndefBER )),
763763 true );
764764
765- // TODO: Change expectation of below to true. Below use BER constructed
766- // strings and will still fail until we revert a70edd4.
765+ // Below use BER constructed strings.
767766 ExpectParse (d2i_ASN1_OCTET_STRING,
768767 std::vector<uint8_t >(kOctetStringBER ,
769768 kOctetStringBER + sizeof (kOctetStringBER )),
770- false );
769+ true );
770+ ExpectParse (d2i_ASN1_TYPE,
771+ std::vector<uint8_t >(kConstructedStringBER ,
772+ kConstructedStringBER + sizeof (kConstructedStringBER )),
773+ true );
774+ ExpectParse (d2i_ASN1_SEQUENCE_ANY,
775+ std::vector<uint8_t >(kWrappedConstructedStringBER ,
776+ kWrappedConstructedStringBER + sizeof (kWrappedConstructedStringBER )),
777+ true );
778+ ExpectParse (d2i_ASN1_BIT_STRING,
779+ std::vector<uint8_t >(kConstructedBitStringBER ,
780+ kConstructedBitStringBER + sizeof (kConstructedBitStringBER )),
781+ true );
771782}
772783
773784struct BERTest {
0 commit comments