Skip to content
This repository was archived by the owner on Jan 23, 2023. It is now read-only.

Commit 4aa6b8e

Browse files
committed
Define DerSequenceReader.ContextSpecificTagFlag, and use it instead of magic 0x80/0x81.
Also added comments for the sourcing of the context specific tag relevance for the Policy Constraints extension.
1 parent b64a9f8 commit 4aa6b8e

File tree

2 files changed

+7
-3
lines changed

2 files changed

+7
-3
lines changed

src/System.Security.Cryptography.X509Certificates/src/Internal/Cryptography/Pal.Unix/CertificatePolicy.cs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -299,12 +299,14 @@ private static void ReadCertPolicyConstraintsExtension(X509Extension extension,
299299

300300
while (reader.HasData)
301301
{
302+
// Policy Constraints context specific tag values are defined in RFC 3280 4.2.1.12,
303+
// and restated (unchanged) in RFC 5280 4.2.1.11.
302304
switch (reader.PeekTag())
303305
{
304-
case 0x80:
306+
case DerSequenceReader.ContextSpecificTagFlag | 0:
305307
policy.RequireExplicitPolicyDepth = reader.ReadInteger();
306308
break;
307-
case 0x81:
309+
case DerSequenceReader.ContextSpecificTagFlag | 1:
308310
policy.InhibitMappingDepth = reader.ReadInteger();
309311
break;
310312
default:

src/System.Security.Cryptography.X509Certificates/src/Internal/Cryptography/Pal.Unix/DerSequenceReader.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ namespace Internal.Cryptography.Pal
1212
/// </summary>
1313
internal class DerSequenceReader
1414
{
15+
internal const byte ContextSpecificTagFlag = 0x80;
16+
1517
private readonly byte[] _data;
1618
private readonly int _end;
1719
private int _position;
@@ -206,7 +208,7 @@ private static void CheckTag(DerTag expected, byte[] data, int position)
206208
byte actual = data[position];
207209

208210
// Context-specific datatypes cannot be tag-verified
209-
if (actual >= 0x80)
211+
if ((actual & ContextSpecificTagFlag) != 0)
210212
{
211213
return;
212214
}

0 commit comments

Comments
 (0)