/
X509Extension.cs
106 lines (91 loc) · 3.63 KB
/
X509Extension.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
using Internal.Cryptography;
namespace System.Security.Cryptography.X509Certificates
{
public class X509Extension : AsnEncodedData
{
protected X509Extension()
: base()
{
}
public X509Extension(AsnEncodedData encodedExtension, bool critical)
: this(encodedExtension.Oid!, encodedExtension.RawData, critical)
{
}
public X509Extension(Oid oid, byte[] rawData, bool critical)
: this(oid, (ReadOnlySpan<byte>)(rawData ?? throw new ArgumentNullException(nameof(rawData))), critical)
{
}
/// <summary>
/// Initializes a new instance of the <see cref="X509Extension"/> class.
/// </summary>
/// <param name="oid">
/// The object identifier used to identify the extension.
/// </param>
/// <param name="rawData">
/// The encoded data used to create the extension.
/// </param>
/// <param name="critical">
/// <see langword="true" /> if the extension is critical;
/// otherwise, <see langword="false" />.
/// </param>
public X509Extension(Oid oid, ReadOnlySpan<byte> rawData, bool critical)
: base(oid, rawData)
{
if (base.Oid?.Value == null)
throw new ArgumentNullException(nameof(oid));
if (base.Oid.Value.Length == 0)
throw new ArgumentException(SR.Format(SR.Arg_EmptyOrNullString_Named, "oid.Value"), nameof(oid));
Critical = critical;
}
public X509Extension(string oid, byte[] rawData, bool critical)
: this(new Oid(oid), rawData, critical)
{
}
/// <summary>
/// Initializes a new instance of the <see cref="X509Extension"/> class.
/// </summary>
/// <param name="oid">
/// The object identifier used to identify the extension.
/// </param>
/// <param name="rawData">
/// The encoded data used to create the extension.
/// </param>
/// <param name="critical">
/// <see langword="true" /> if the extension is critical;
/// otherwise, <see langword="false" />.
/// </param>
public X509Extension(string oid, ReadOnlySpan<byte> rawData, bool critical)
: this(new Oid(oid), rawData, critical)
{
}
internal X509Extension(Oid oid, byte[] rawData, bool critical, bool skipCopy)
: base(oid, rawData, skipCopy)
{
if (base.Oid?.Value == null)
throw new ArgumentNullException(nameof(oid));
if (base.Oid.Value.Length == 0)
throw new ArgumentException(SR.Format(SR.Arg_EmptyOrNullString_Named, "oid.Value"), nameof(oid));
Critical = critical;
}
public bool Critical { get; set; }
public override void CopyFrom(AsnEncodedData asnEncodedData)
{
ArgumentNullException.ThrowIfNull(asnEncodedData);
X509Extension? extension = asnEncodedData as X509Extension;
if (extension == null)
throw new ArgumentException(SR.Cryptography_X509_ExtensionMismatch);
base.CopyFrom(asnEncodedData);
Critical = extension.Critical;
}
internal X509Extension(string oidValue)
{
base.Oid = Oid.FromOidValue(oidValue, OidGroup.ExtensionOrAttribute);
}
internal X509Extension(Oid oid)
{
base.Oid = oid;
}
}
}