This repository was archived by the owner on Jan 23, 2023. It is now read-only.
File tree Expand file tree Collapse file tree 2 files changed +8
-10
lines changed
src/System.Security.Cryptography.X509Certificates
src/Internal/Cryptography/Pal.Unix Expand file tree Collapse file tree 2 files changed +8
-10
lines changed Original file line number Diff line number Diff line change @@ -190,6 +190,12 @@ private List<X509Certificate2> ReadDirectory()
190
190
191
191
public void Add ( ICertificatePal certPal )
192
192
{
193
+ if ( _readOnly )
194
+ {
195
+ // Windows compatibility: Remove only throws when it needs to do work, add throws always.
196
+ throw new CryptographicException ( SR . Cryptography_X509_StoreReadOnly ) ;
197
+ }
198
+
193
199
// Save the collection to a local so it's consistent for the whole method
194
200
List < X509Certificate2 > certificates = _certificates ;
195
201
OpenSslX509CertificateReader cert = ( OpenSslX509CertificateReader ) certPal ;
@@ -267,13 +273,6 @@ public void Add(ICertificatePal certPal)
267
273
}
268
274
}
269
275
270
- if ( _readOnly )
271
- {
272
- // Windows compatibility: Don't throw until it has been established that
273
- // the certificate is not present, and we need to modify the filesystem.
274
- throw new CryptographicException ( SR . Cryptography_X509_StoreReadOnly ) ;
275
- }
276
-
277
276
string destinationFilename ;
278
277
FileMode mode = FileMode . CreateNew ;
279
278
Original file line number Diff line number Diff line change @@ -60,7 +60,7 @@ public static void AddReadOnlyThrows()
60
60
61
61
[ Fact ]
62
62
[ ActiveIssue ( 2820 , PlatformID . AnyUnix ) ]
63
- public static void AddReadOnlyDoesntThrowWhenCertificateExists ( )
63
+ public static void AddReadOnlyThrowsWhenCertificateExists ( )
64
64
{
65
65
using ( X509Store store = new X509Store ( StoreName . My , StoreLocation . CurrentUser ) )
66
66
{
@@ -82,8 +82,7 @@ public static void AddReadOnlyDoesntThrowWhenCertificateExists()
82
82
83
83
if ( toAdd != null )
84
84
{
85
- // This shouldn't throw, the cert is already present.
86
- store . Add ( toAdd ) ;
85
+ Assert . Throws < CryptographicException > ( ( ) => store . Add ( toAdd ) ) ;
87
86
}
88
87
}
89
88
}
You can’t perform that action at this time.
0 commit comments