public static void TryCopyIA5StringBytes_Success_CER_MinConstructedLength() { // CER says that the maximum encoding length for a IA5String primitive // is 1000, and that a constructed form must be used for values greater // than 1000 bytes, with segments dividing up for each thousand // [1000, 1000, ..., len%1000]. // // So our smallest constructed form is 1001 bytes, [1000, 1] // // 36 80 (indefinite constructed IA5 string) // 04 82 03 E9 (primitive octet string, 1000 bytes) // [1000 content bytes] // 04 01 (primitive octet string, 1 byte) // pp // 00 00 (end of contents, 0 bytes) // 1011 total. byte[] input = new byte[1011]; int offset = 0; // CONSTRUCTED IA5STRING (Indefinite) input[offset++] = 0x36; input[offset++] = 0x80; // OCTET STRING (1000) input[offset++] = 0x04; input[offset++] = 0x82; input[offset++] = 0x03; input[offset++] = 0xE8; // Primitive 1: (65 65 :: 61 61) (1000) input[offset++] = 0x65; input[offset] = 0x65; offset += 997; input[offset++] = 0x61; input[offset++] = 0x61; // OCTET STRING (1) input[offset++] = 0x04; input[offset++] = 0x01; // Primitive 2: One more byte input[offset] = 0x2E; byte[] expected = new byte[1001]; offset = 0; expected[offset++] = 0x65; expected[offset] = 0x65; offset += 997; expected[offset++] = 0x61; expected[offset++] = 0x61; expected[offset] = 0x2E; byte[] output = new byte[1001]; AsnReader reader = new AsnReader(input, AsnEncodingRules.CER); bool success = reader.TryCopyIA5StringBytes(output, out int bytesWritten); Assert.True(success, "reader.TryCopyIA5StringBytes"); Assert.Equal(1001, bytesWritten); Assert.Equal( expected.ByteArrayToHex(), output.ByteArrayToHex()); }