Skip to content
This repository was archived by the owner on Jan 23, 2023. It is now read-only.

Commit ca4ef03

Browse files
committed
Replace all remaining native-induced CryptographicExceptions with CreateOpenSslCryptographicException.
While "throw new CryptographicException();" does have several hits remaining after this change, they are all in the interpretation of data, rather than indicating a P/Invoke has gone wrong.
1 parent f5452f9 commit ca4ef03

File tree

4 files changed

+5
-7
lines changed

4 files changed

+5
-7
lines changed

src/Common/src/Interop/Unix/libcrypto/Interop.d2i.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ internal static unsafe byte[] OpenSslI2D<THandle>(I2DFunc<THandle> i2d, THandle
4040

4141
if (size < 1)
4242
{
43-
throw new CryptographicException();
43+
throw CreateOpenSslCryptographicException();
4444
}
4545

4646
byte[] data = new byte[size];

src/System.Security.Cryptography.Hashing.Algorithms/src/Internal/Cryptography/HashProviderDispenser.Unix.cs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -69,10 +69,8 @@ public EvpHashProvider(IntPtr algorithmEvp)
6969
}
7070

7171
_ctx = Interop.libcrypto.EVP_MD_CTX_create();
72-
if (_ctx.IsInvalid)
73-
{
74-
throw new CryptographicException();
75-
}
72+
73+
Interop.libcrypto.CheckValidOpenSslHandle(_ctx);
7674

7775
Check(Interop.libcrypto.EVP_DigestInit_ex(_ctx, algorithmEvp, IntPtr.Zero));
7876
}

src/System.Security.Cryptography.X509Certificates/src/Internal/Cryptography/Pal.Unix/OpenSslX509ChainProcessor.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ public static IChainPal BuildChain(
121121

122122
if (elementCertPtr == IntPtr.Zero)
123123
{
124-
throw new CryptographicException();
124+
throw Interop.libcrypto.CreateOpenSslCryptographicException();
125125
}
126126

127127
// Duplicate the certificate handle

src/System.Security.Cryptography.X509Certificates/src/Internal/Cryptography/Pal.Unix/OpenSslX509Encoder.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -198,7 +198,7 @@ public unsafe void DecodeX509EnhancedKeyUsageExtension(byte[] encoded, out OidCo
198198

199199
if (oidPtr == IntPtr.Zero)
200200
{
201-
throw new CryptographicException();
201+
throw Interop.libcrypto.CreateOpenSslCryptographicException();
202202
}
203203

204204
string oidValue = Interop.libcrypto.OBJ_obj2txt_helper(oidPtr);

0 commit comments

Comments
 (0)