X509CertificateExCollection.cs 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203
  1. //
  2. // X509CertificateExCollection.cs - System.Security.Cryptography.X509Certificates.X509CertificateExCollection
  3. //
  4. // Author:
  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. //
  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;
  33. using System.Collections;
  34. namespace System.Security.Cryptography.X509Certificates {
  35. // Note: Match the definition of framework version 1.2.3400.0 on http://longhorn.msdn.microsoft.com
  36. public sealed class X509CertificateExCollection : X509CertificateCollection {
  37. // constructors
  38. public X509CertificateExCollection () {}
  39. public X509CertificateExCollection (X509CertificateExCollection certificates)
  40. {
  41. AddRange (certificates);
  42. }
  43. public X509CertificateExCollection (X509CertificateEx[] certificates)
  44. {
  45. AddRange (certificates);
  46. }
  47. // properties
  48. public new X509CertificateEx this [int index] {
  49. get {
  50. if (index < 0)
  51. throw new ArgumentOutOfRangeException ("negative index");
  52. if (index >= InnerList.Count)
  53. throw new ArgumentOutOfRangeException ("index >= Count");
  54. return (X509CertificateEx) InnerList [index];
  55. }
  56. set { InnerList [index] = value; }
  57. }
  58. // methods
  59. public int Add (X509CertificateEx certificate)
  60. {
  61. if (certificate == null)
  62. throw new ArgumentNullException ("certificate");
  63. return InnerList.Add (certificate);
  64. }
  65. // note: transactional
  66. public void AddRange (X509CertificateEx[] certificates)
  67. {
  68. if (certificates == null)
  69. throw new ArgumentNullException ("certificates");
  70. for (int i=0; i < certificates.Length; i++)
  71. InnerList.Add (certificates [i]);
  72. }
  73. // note: transactional
  74. public void AddRange (X509CertificateExCollection certificates)
  75. {
  76. if (certificates == null)
  77. throw new ArgumentNullException ("certificates");
  78. InnerList.AddRange (certificates);
  79. }
  80. public bool Contains (X509CertificateEx certificate)
  81. {
  82. if (certificate == null)
  83. throw new ArgumentNullException ("certificate");
  84. foreach (X509CertificateEx c in InnerList) {
  85. if (certificate.Equals (c))
  86. return true;
  87. }
  88. return false;
  89. }
  90. public byte[] Export (X509ContentType contentType)
  91. {
  92. return null;
  93. }
  94. public byte[] Export (X509ContentType contentType, string password)
  95. {
  96. return null;
  97. }
  98. public X509CertificateExCollection Find (X509FindType findType, object findValue, bool validOnly)
  99. {
  100. return null;
  101. }
  102. public new X509CertificateExEnumerator GetEnumerator ()
  103. {
  104. return null;
  105. }
  106. public void Import (byte[] rawData)
  107. {
  108. }
  109. public void Import (byte[] rawData, string password, X509KeyStorageFlags keyStorageFlags)
  110. {
  111. }
  112. public void Import (string fileName)
  113. {
  114. }
  115. public void Import (string fileName, string password, X509KeyStorageFlags keyStorageFlags)
  116. {
  117. }
  118. public void Insert (int index, X509CertificateEx certificate)
  119. {
  120. if (certificate == null)
  121. throw new ArgumentNullException ("certificate");
  122. if (index < 0)
  123. throw new ArgumentOutOfRangeException ("negative index");
  124. if (index >= InnerList.Count)
  125. throw new ArgumentOutOfRangeException ("index >= Count");
  126. InnerList.Insert (index, certificate);
  127. }
  128. public void Remove (X509CertificateEx certificate)
  129. {
  130. if (certificate == null)
  131. throw new ArgumentNullException ("certificate");
  132. for (int i=0; i < InnerList.Count; i++) {
  133. X509CertificateEx c = (X509CertificateEx) InnerList [i];
  134. if (certificate.Equals (c)) {
  135. InnerList.RemoveAt (i);
  136. // only first instance is removed
  137. return;
  138. }
  139. }
  140. }
  141. // note: transactional
  142. public void RemoveRange (X509CertificateEx[] certificates)
  143. {
  144. if (certificates == null)
  145. throw new ArgumentNullException ("certificate");
  146. }
  147. // note: transactional
  148. public void RemoveRange (X509CertificateExCollection certificates)
  149. {
  150. if (certificates == null)
  151. throw new ArgumentNullException ("certificate");
  152. }
  153. // note: UI
  154. public X509CertificateExCollection Select (string title, string message, X509SelectionFlag selectionFlag)
  155. {
  156. return null;
  157. }
  158. // note: UI
  159. public X509CertificateExCollection Select (string title, string message, X509SelectionFlag selectionFlag, IntPtr hwndParent)
  160. {
  161. return null;
  162. }
  163. }
  164. }
  165. #endif