mscorlib(4.0.0.0) API with additions
X509ExtensionCollection.cs
1 using System.Collections;
3 
5 {
8  {
9  private ArrayList m_list = new ArrayList();
10 
18  public X509Extension this[int index]
19  {
20  get
21  {
22  if (index < 0)
23  {
24  throw new InvalidOperationException(SR.GetString("InvalidOperation_EnumNotStarted"));
25  }
26  if (index >= m_list.Count)
27  {
28  throw new ArgumentOutOfRangeException("index", SR.GetString("ArgumentOutOfRange_Index"));
29  }
30  return (X509Extension)m_list[index];
31  }
32  }
33 
37  public X509Extension this[string oid]
38  {
39  get
40  {
41  string text = System.Security.Cryptography.X509Certificates.X509Utils.FindOidInfoWithFallback(2u, oid, System.Security.Cryptography.OidGroup.ExtensionOrAttribute);
42  if (text == null)
43  {
44  text = oid;
45  }
46  foreach (X509Extension item in m_list)
47  {
48  if (string.Compare(item.Oid.Value, text, StringComparison.OrdinalIgnoreCase) == 0)
49  {
50  return item;
51  }
52  }
53  return null;
54  }
55  }
56 
59  public int Count => m_list.Count;
60 
64  public bool IsSynchronized => false;
65 
68  public object SyncRoot => this;
69 
72  {
73  }
74 
75  internal unsafe X509ExtensionCollection(System.Security.Cryptography.SafeCertContextHandle safeCertContextHandle)
76  {
77  using (System.Security.Cryptography.SafeCertContextHandle safeCertContextHandle2 = CAPI.CertDuplicateCertificateContext(safeCertContextHandle))
78  {
79  CAPIBase.CERT_CONTEXT cERT_CONTEXT = *(CAPIBase.CERT_CONTEXT*)(void*)safeCertContextHandle2.DangerousGetHandle();
80  CAPIBase.CERT_INFO cERT_INFO = (CAPIBase.CERT_INFO)Marshal.PtrToStructure(cERT_CONTEXT.pCertInfo, typeof(CAPIBase.CERT_INFO));
81  uint cExtension = cERT_INFO.cExtension;
82  IntPtr rgExtension = cERT_INFO.rgExtension;
83  for (uint num = 0u; num < cExtension; num++)
84  {
85  X509Extension x509Extension = new X509Extension(new IntPtr((long)rgExtension + num * Marshal.SizeOf(typeof(CAPIBase.CERT_EXTENSION))));
86  X509Extension x509Extension2 = CryptoConfig.CreateFromName(x509Extension.Oid.Value) as X509Extension;
87  if (x509Extension2 != null)
88  {
89  x509Extension2.CopyFrom(x509Extension);
90  x509Extension = x509Extension2;
91  }
92  Add(x509Extension);
93  }
94  }
95  }
96 
101  public int Add(X509Extension extension)
102  {
103  if (extension == null)
104  {
105  throw new ArgumentNullException("extension");
106  }
107  return m_list.Add(extension);
108  }
109 
113  {
114  return new X509ExtensionEnumerator(this);
115  }
116 
120  {
121  return new X509ExtensionEnumerator(this);
122  }
123 
133  void ICollection.CopyTo(Array array, int index)
134  {
135  if (array == null)
136  {
137  throw new ArgumentNullException("array");
138  }
139  if (array.Rank != 1)
140  {
141  throw new ArgumentException(SR.GetString("Arg_RankMultiDimNotSupported"));
142  }
143  if (index < 0 || index >= array.Length)
144  {
145  throw new ArgumentOutOfRangeException("index", SR.GetString("ArgumentOutOfRange_Index"));
146  }
147  if (index + Count > array.Length)
148  {
149  throw new ArgumentException(SR.GetString("Argument_InvalidOffLen"));
150  }
151  for (int i = 0; i < Count; i++)
152  {
153  array.SetValue(this[i], index);
154  index++;
155  }
156  }
157 
167  public void CopyTo(X509Extension[] array, int index)
168  {
169  ((ICollection)this).CopyTo((Array)array, index);
170  }
171  }
172 }
The exception that is thrown when a null reference (Nothing in Visual Basic) is passed to a method th...
Oid Oid
Gets or sets the T:System.Security.Cryptography.Oid value for an T:System.Security....
Supports a simple iteration over a T:System.Security.Cryptography.X509Certificates....
StringComparison
Specifies the culture, case, and sort rules to be used by certain overloads of the M:System....
static object CreateFromName(string name, params object[] args)
Creates a new instance of the specified cryptographic object with the specified arguments.
Definition: __Canon.cs:3
The exception that is thrown when the value of an argument is outside the allowable range of values a...
static int SizeOf(object structure)
Returns the unmanaged size of an object in bytes.
Definition: Marshal.cs:159
string Value
Gets or sets the dotted number of the identifier.
Definition: Oid.cs:17
Exposes an enumerator, which supports a simple iteration over a non-generic collection....
Definition: IEnumerable.cs:9
Accesses the cryptography configuration information.
Definition: CryptoConfig.cs:17
bool IsSynchronized
Gets a value indicating whether the collection is guaranteed to be thread safe.
Represents a collection of T:System.Security.Cryptography.X509Certificates.X509Extension objects....
A platform-specific type that is used to represent a pointer or a handle.
Definition: IntPtr.cs:14
Provides methods for creating, manipulating, searching, and sorting arrays, thereby serving as the ba...
Definition: Array.cs:17
Provides a collection of methods for allocating unmanaged memory, copying unmanaged memory blocks,...
Definition: Marshal.cs:15
IEnumerator GetEnumerator()
Returns an enumerator that iterates through a collection.
X509ExtensionCollection()
Initializes a new instance of the T:System.Security.Cryptography.X509Certificates....
The exception that is thrown when one of the arguments provided to a method is not valid.
void CopyTo(X509Extension[] array, int index)
Copies a collection into an array starting at the specified index.
static void PtrToStructure(IntPtr ptr, object structure)
Marshals data from an unmanaged block of memory to a managed object.
Definition: Marshal.cs:1198
X509ExtensionEnumerator GetEnumerator()
Returns an enumerator that can iterate through an T:System.Security.Cryptography.X509Certificates....
int Count
Gets the number of T:System.Security.Cryptography.X509Certificates.X509Extension objects in a T:Syste...
object SyncRoot
Gets an object that you can use to synchronize access to the T:System.Security.Cryptography....
The exception that is thrown when a method call is invalid for the object's current state.
Defines size, enumerators, and synchronization methods for all nongeneric collections.
Definition: ICollection.cs:8
override void CopyFrom(AsnEncodedData asnEncodedData)
Copies the extension properties of the specified T:System.Security.Cryptography.AsnEncodedData object...
void CopyTo(Array array, int index)
Copies the elements of the T:System.Collections.ICollection to an T:System.Array, starting at a parti...
int Add(X509Extension extension)
Adds an T:System.Security.Cryptography.X509Certificates.X509Extension object to an T:System....
Supports a simple iteration over a non-generic collection.
Definition: IEnumerator.cs:9
Implements the T:System.Collections.IList interface using an array whose size is dynamically increase...
Definition: ArrayList.cs:14