@@ -94,6 +94,46 @@ public void Read_WithExtensions_ReturnsInstance()
9494 Verify ( testTstInfo ) ;
9595 }
9696
97+ [ Fact ]
98+ public void Encode_WithDefaultOrderingFalse_OmitsBooleanAndIsAcceptedByConsumers ( )
99+ {
100+ // DER X.690 §11.5: a value equal to the DEFAULT must not be encoded.
101+ // 'ordering BOOLEAN DEFAULT FALSE' must be omitted when false.
102+ TestTstInfo testTstInfo = CreateTestTstInfo ( ) ;
103+
104+ AsnWriter writer = new ( AsnEncodingRules . DER ) ;
105+ testTstInfo . Encode ( writer ) ;
106+ byte [ ] bytes = writer . Encode ( ) ;
107+
108+ // Verify the ordering boolean is not present in the encoded bytes
109+ AsnReader reader = new ( bytes , AsnEncodingRules . DER ) ;
110+ AsnReader sequence = reader . ReadSequence ( ) ;
111+
112+ sequence . ReadInteger ( ) ; // version
113+ sequence . ReadObjectIdentifier ( ) ; // policy
114+ sequence . ReadSequence ( ) ; // messageImprint
115+ sequence . ReadInteger ( ) ; // serialNumber
116+ sequence . ReadGeneralizedTime ( ) ; // genTime
117+ // accuracy is not present in this test data
118+
119+ bool hasBooleanTag = sequence . HasData && sequence . PeekTag ( ) == Asn1Tag . Boolean ;
120+ Assert . False ( hasBooleanTag ,
121+ "Ordering=false must not be explicitly encoded per DER rules (X.690 §11.5)." ) ;
122+
123+ // Verify NuGet's own parser accepts the encoding and reads ordering as false
124+ TstInfo parsed = TstInfo . Read ( bytes ) ;
125+ Assert . False ( parsed . Ordering ) ;
126+
127+ #if IS_CORECLR
128+ // Verify the BCL parser also accepts the encoding and reads ordering as false
129+ Assert . True (
130+ System . Security . Cryptography . Pkcs . Rfc3161TimestampTokenInfo . TryDecode (
131+ new ReadOnlyMemory < byte > ( bytes ) , out System . Security . Cryptography . Pkcs . Rfc3161TimestampTokenInfo ? bclTstInfo , out _ ) ,
132+ "BCL Rfc3161TimestampTokenInfo.TryDecode rejected the encoded TSTInfo." ) ;
133+ Assert . False ( bclTstInfo ! . IsOrdering ) ;
134+ #endif
135+ }
136+
97137 private static void Verify ( TestTstInfo expectedTstInfo )
98138 {
99139 AsnWriter writer = new ( AsnEncodingRules . DER ) ;
0 commit comments