1
1
// Copyright (c) Microsoft. All rights reserved.
2
2
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
3
3
4
- using System ;
5
- using System . IO ;
6
- using System . Text ;
7
- using System . Diagnostics ;
8
- using System . Globalization ;
9
- using System . Runtime . InteropServices ;
10
-
11
- using Internal . Cryptography ;
12
4
using Internal . Cryptography . Pal ;
13
5
14
6
namespace System . Security . Cryptography . X509Certificates
@@ -38,13 +30,11 @@ public X509Certificate2Collection(X509Certificate2Collection certificates)
38
30
{
39
31
get
40
32
{
41
- return ( X509Certificate2 ) ( List [ index ] ) ;
33
+ return ( X509Certificate2 ) ( base [ index ] ) ;
42
34
}
43
35
set
44
36
{
45
- if ( value == null )
46
- throw new ArgumentNullException ( "value" ) ;
47
- List [ index ] = value ;
37
+ base [ index ] = value ;
48
38
}
49
39
}
50
40
@@ -53,7 +43,7 @@ public int Add(X509Certificate2 certificate)
53
43
if ( certificate == null )
54
44
throw new ArgumentNullException ( "certificate" ) ;
55
45
56
- return List . Add ( certificate ) ;
46
+ return base . Add ( certificate ) ;
57
47
}
58
48
59
49
public void AddRange ( X509Certificate2 [ ] certificates )
@@ -87,10 +77,9 @@ public void AddRange(X509Certificate2Collection certificates)
87
77
int i = 0 ;
88
78
try
89
79
{
90
- foreach ( X509Certificate2 certificate in certificates )
80
+ for ( ; i < certificates . Count ; i ++ )
91
81
{
92
- Add ( certificate ) ;
93
- i ++ ;
82
+ Add ( certificates [ i ] ) ;
94
83
}
95
84
}
96
85
catch
@@ -105,26 +94,27 @@ public void AddRange(X509Certificate2Collection certificates)
105
94
106
95
public bool Contains ( X509Certificate2 certificate )
107
96
{
108
- if ( certificate == null )
109
- throw new ArgumentNullException ( "certificate" ) ;
97
+ // This method used to throw ArgumentNullException, but it has been deliberately changed
98
+ // to no longer throw to match the behavior of X509CertificateCollection.Contains and the
99
+ // IList.Contains implementation, which do not throw.
110
100
111
- return List . Contains ( certificate ) ;
101
+ return base . Contains ( certificate ) ;
112
102
}
113
103
114
104
public byte [ ] Export ( X509ContentType contentType )
115
105
{
116
106
return Export ( contentType , password : null ) ;
117
107
}
118
108
119
- public byte [ ] Export ( X509ContentType contentType , String password )
109
+ public byte [ ] Export ( X509ContentType contentType , string password )
120
110
{
121
111
using ( IStorePal storePal = StorePal . LinkFromCertificateCollection ( this ) )
122
112
{
123
113
return storePal . Export ( contentType , password ) ;
124
114
}
125
115
}
126
116
127
- public X509Certificate2Collection Find ( X509FindType findType , Object findValue , bool validOnly )
117
+ public X509Certificate2Collection Find ( X509FindType findType , object findValue , bool validOnly )
128
118
{
129
119
if ( findValue == null )
130
120
throw new ArgumentNullException ( "findValue" ) ;
@@ -139,16 +129,15 @@ public X509Certificate2Collection Find(X509FindType findType, Object findValue,
139
129
140
130
public new X509Certificate2Enumerator GetEnumerator ( )
141
131
{
142
- X509CertificateEnumerator baseEnumerator = base . GetEnumerator ( ) ;
143
- return new X509Certificate2Enumerator ( baseEnumerator ) ;
132
+ return new X509Certificate2Enumerator ( this ) ;
144
133
}
145
134
146
135
public void Import ( byte [ ] rawData )
147
136
{
148
137
Import ( rawData , password : null , keyStorageFlags : X509KeyStorageFlags . DefaultKeySet ) ;
149
138
}
150
139
151
- public void Import ( byte [ ] rawData , String password , X509KeyStorageFlags keyStorageFlags )
140
+ public void Import ( byte [ ] rawData , string password , X509KeyStorageFlags keyStorageFlags )
152
141
{
153
142
if ( rawData == null )
154
143
throw new ArgumentNullException ( "rawData" ) ;
@@ -159,12 +148,12 @@ public void Import(byte[] rawData, String password, X509KeyStorageFlags keyStora
159
148
}
160
149
}
161
150
162
- public void Import ( String fileName )
151
+ public void Import ( string fileName )
163
152
{
164
153
Import ( fileName , password : null , keyStorageFlags : X509KeyStorageFlags . DefaultKeySet ) ;
165
154
}
166
155
167
- public void Import ( String fileName , String password , X509KeyStorageFlags keyStorageFlags )
156
+ public void Import ( string fileName , string password , X509KeyStorageFlags keyStorageFlags )
168
157
{
169
158
if ( fileName == null )
170
159
throw new ArgumentNullException ( "fileName" ) ;
@@ -180,15 +169,15 @@ public void Insert(int index, X509Certificate2 certificate)
180
169
if ( certificate == null )
181
170
throw new ArgumentNullException ( "certificate" ) ;
182
171
183
- List . Insert ( index , certificate ) ;
172
+ base . Insert ( index , certificate ) ;
184
173
}
185
174
186
175
public void Remove ( X509Certificate2 certificate )
187
176
{
188
177
if ( certificate == null )
189
178
throw new ArgumentNullException ( "certificate" ) ;
190
179
191
- List . Remove ( certificate ) ;
180
+ base . Remove ( certificate ) ;
192
181
}
193
182
194
183
public void RemoveRange ( X509Certificate2 [ ] certificates )
@@ -222,10 +211,9 @@ public void RemoveRange(X509Certificate2Collection certificates)
222
211
int i = 0 ;
223
212
try
224
213
{
225
- foreach ( X509Certificate2 certificate in certificates )
214
+ for ( ; i < certificates . Count ; i ++ )
226
215
{
227
- Remove ( certificate ) ;
228
- i ++ ;
216
+ Remove ( certificates [ i ] ) ;
229
217
}
230
218
}
231
219
catch
@@ -239,4 +227,3 @@ public void RemoveRange(X509Certificate2Collection certificates)
239
227
}
240
228
}
241
229
}
242
-
0 commit comments