X509CertificateExCollection.cs 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206
  1. //
  2. // System.Security.Cryptography.X509Certificates.X509Certificate2Collection class
  3. //
  4. // Authors:
  5. // Sebastien Pouliot <[email protected]>
  6. // Tim Coleman ([email protected])
  7. //
  8. // (C) 2003 Motus Technologies Inc. (http://www.motus.com)
  9. // Copyright (C) Tim Coleman, 2004
  10. // Copyright (C) 2005 Novell Inc. (http://www.novell.com)
  11. //
  12. // Permission is hereby granted, free of charge, to any person obtaining
  13. // a copy of this software and associated documentation files (the
  14. // "Software"), to deal in the Software without restriction, including
  15. // without limitation the rights to use, copy, modify, merge, publish,
  16. // distribute, sublicense, and/or sell copies of the Software, and to
  17. // permit persons to whom the Software is furnished to do so, subject to
  18. // the following conditions:
  19. //
  20. // The above copyright notice and this permission notice shall be
  21. // included in all copies or substantial portions of the Software.
  22. //
  23. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  24. // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  25. // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  26. // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
  27. // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
  28. // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
  29. // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  30. //
  31. #if NET_2_0
  32. using System.Collections;
  33. namespace System.Security.Cryptography.X509Certificates {
  34. public sealed class X509Certificate2Collection : X509CertificateCollection {
  35. // constructors
  36. public X509Certificate2Collection ()
  37. {
  38. }
  39. public X509Certificate2Collection (X509Certificate2Collection certificates)
  40. {
  41. AddRange (certificates);
  42. }
  43. public X509Certificate2Collection (X509Certificate2 certificate)
  44. {
  45. Add (certificate);
  46. }
  47. public X509Certificate2Collection (X509Certificate2[] certificates)
  48. {
  49. AddRange (certificates);
  50. }
  51. // properties
  52. public new X509Certificate2 this [int index] {
  53. get {
  54. if (index < 0)
  55. throw new ArgumentOutOfRangeException ("negative index");
  56. if (index >= InnerList.Count)
  57. throw new ArgumentOutOfRangeException ("index >= Count");
  58. return (X509Certificate2) InnerList [index];
  59. }
  60. set { InnerList [index] = value; }
  61. }
  62. // methods
  63. public int Add (X509Certificate2 certificate)
  64. {
  65. if (certificate == null)
  66. throw new ArgumentNullException ("certificate");
  67. return InnerList.Add (certificate);
  68. }
  69. // note: transactional
  70. public void AddRange (X509Certificate2[] certificates)
  71. {
  72. if (certificates == null)
  73. throw new ArgumentNullException ("certificates");
  74. for (int i=0; i < certificates.Length; i++)
  75. InnerList.Add (certificates [i]);
  76. }
  77. // note: transactional
  78. public void AddRange (X509Certificate2Collection certificates)
  79. {
  80. if (certificates == null)
  81. throw new ArgumentNullException ("certificates");
  82. InnerList.AddRange (certificates);
  83. }
  84. public bool Contains (X509Certificate2 certificate)
  85. {
  86. if (certificate == null)
  87. throw new ArgumentNullException ("certificate");
  88. foreach (X509Certificate2 c in InnerList) {
  89. if (certificate.Equals (c))
  90. return true;
  91. }
  92. return false;
  93. }
  94. public byte[] Export (X509ContentType contentType)
  95. {
  96. return null;
  97. }
  98. public byte[] Export (X509ContentType contentType, string password)
  99. {
  100. return null;
  101. }
  102. public X509Certificate2Collection Find (X509FindType findType, object findValue, bool validOnly)
  103. {
  104. return null;
  105. }
  106. public new X509Certificate2Enumerator GetEnumerator ()
  107. {
  108. return null;
  109. }
  110. public void Import (byte[] rawData)
  111. {
  112. }
  113. public void Import (byte[] rawData, string password, X509KeyStorageFlags keyStorageFlags)
  114. {
  115. }
  116. public void Import (string fileName)
  117. {
  118. }
  119. public void Import (string fileName, string password, X509KeyStorageFlags keyStorageFlags)
  120. {
  121. }
  122. public void Insert (int index, X509Certificate2 certificate)
  123. {
  124. if (certificate == null)
  125. throw new ArgumentNullException ("certificate");
  126. if (index < 0)
  127. throw new ArgumentOutOfRangeException ("negative index");
  128. if (index >= InnerList.Count)
  129. throw new ArgumentOutOfRangeException ("index >= Count");
  130. InnerList.Insert (index, certificate);
  131. }
  132. public void Remove (X509Certificate2 certificate)
  133. {
  134. if (certificate == null)
  135. throw new ArgumentNullException ("certificate");
  136. for (int i=0; i < InnerList.Count; i++) {
  137. X509Certificate2 c = (X509Certificate2) InnerList [i];
  138. if (certificate.Equals (c)) {
  139. InnerList.RemoveAt (i);
  140. // only first instance is removed
  141. return;
  142. }
  143. }
  144. }
  145. // note: transactional
  146. public void RemoveRange (X509Certificate2[] certificates)
  147. {
  148. if (certificates == null)
  149. throw new ArgumentNullException ("certificate");
  150. }
  151. // note: transactional
  152. public void RemoveRange (X509Certificate2Collection certificates)
  153. {
  154. if (certificates == null)
  155. throw new ArgumentNullException ("certificate");
  156. }
  157. // note: UI
  158. public X509Certificate2Collection Select (string title, string message, X509SelectionFlag selectionFlag)
  159. {
  160. return null;
  161. }
  162. // note: UI
  163. public X509Certificate2Collection Select (string title, string message, X509SelectionFlag selectionFlag, IntPtr hwndParent)
  164. {
  165. return null;
  166. }
  167. }
  168. }
  169. #endif