mscorlib(4.0.0.0) API with additions
X509ChainElementCollection.cs
1 using System.Collections;
3 
5 {
8  {
9  private X509ChainElement[] m_elements;
10 
18  public X509ChainElement 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_elements.Length)
27  {
28  throw new ArgumentOutOfRangeException("index", SR.GetString("ArgumentOutOfRange_Index"));
29  }
30  return m_elements[index];
31  }
32  }
33 
36  public int Count => m_elements.Length;
37 
40  public bool IsSynchronized => false;
41 
44  public object SyncRoot => this;
45 
47  {
48  m_elements = new X509ChainElement[0];
49  }
50 
51  internal unsafe X509ChainElementCollection(IntPtr pSimpleChain)
52  {
53  CAPIBase.CERT_SIMPLE_CHAIN cERT_SIMPLE_CHAIN = new CAPIBase.CERT_SIMPLE_CHAIN(Marshal.SizeOf(typeof(CAPIBase.CERT_SIMPLE_CHAIN)));
54  uint num = (uint)Marshal.ReadInt32(pSimpleChain);
55  if (num > Marshal.SizeOf((object)cERT_SIMPLE_CHAIN))
56  {
57  num = (uint)Marshal.SizeOf((object)cERT_SIMPLE_CHAIN);
58  }
59  System.Security.Cryptography.X509Certificates.X509Utils.memcpy(pSimpleChain, new IntPtr(&cERT_SIMPLE_CHAIN), num);
60  m_elements = new X509ChainElement[cERT_SIMPLE_CHAIN.cElement];
61  for (int i = 0; i < m_elements.Length; i++)
62  {
63  m_elements[i] = new X509ChainElement(Marshal.ReadIntPtr(new IntPtr((long)cERT_SIMPLE_CHAIN.rgpElement + i * Marshal.SizeOf(typeof(IntPtr)))));
64  }
65  }
66 
70  {
71  return new X509ChainElementEnumerator(this);
72  }
73 
77  {
78  return new X509ChainElementEnumerator(this);
79  }
80 
89  void ICollection.CopyTo(Array array, int index)
90  {
91  if (array == null)
92  {
93  throw new ArgumentNullException("array");
94  }
95  if (array.Rank != 1)
96  {
97  throw new ArgumentException(SR.GetString("Arg_RankMultiDimNotSupported"));
98  }
99  if (index < 0 || index >= array.Length)
100  {
101  throw new ArgumentOutOfRangeException("index", SR.GetString("ArgumentOutOfRange_Index"));
102  }
103  if (index + Count > array.Length)
104  {
105  throw new ArgumentException(SR.GetString("Argument_InvalidOffLen"));
106  }
107  for (int i = 0; i < Count; i++)
108  {
109  array.SetValue(this[i], index);
110  index++;
111  }
112  }
113 
122  public void CopyTo(X509ChainElement[] array, int index)
123  {
124  ((ICollection)this).CopyTo((Array)array, index);
125  }
126  }
127 }
static int ReadInt32([In] [MarshalAs(UnmanagedType.AsAny)] object ptr, int ofs)
Reads a 32-bit signed integer at a given offset from unmanaged memory.
The exception that is thrown when a null reference (Nothing in Visual Basic) is passed to a method th...
X509ChainElementEnumerator GetEnumerator()
Gets an T:System.Security.Cryptography.X509Certificates.X509ChainElementEnumerator object that can be...
object SyncRoot
Gets an object that can be used to synchronize access to an T:System.Security.Cryptography....
Supports a simple iteration over an T:System.Security.Cryptography.X509Certificates....
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
Represents a collection of T:System.Security.Cryptography.X509Certificates.X509ChainElement objects....
Exposes an enumerator, which supports a simple iteration over a non-generic collection....
Definition: IEnumerable.cs:9
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.
void CopyTo(X509ChainElement[] array, int index)
Copies an T:System.Security.Cryptography.X509Certificates.X509ChainElementCollection object into an a...
The exception that is thrown when one of the arguments provided to a method is not valid.
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
void CopyTo(Array array, int index)
Copies the elements of the T:System.Collections.ICollection to an T:System.Array, starting at a parti...
Supports a simple iteration over a non-generic collection.
Definition: IEnumerator.cs:9
static IntPtr ReadIntPtr([In] [MarshalAs(UnmanagedType.AsAny)] object ptr, int ofs)
Reads a processor native sized integer from unmanaged memory.
Definition: Marshal.cs:681
bool IsSynchronized
Gets a value indicating whether the collection of chain elements is synchronized.