Updating exception filters to use when instead of if

This commit is contained in:
Pranav K 2014-12-16 10:21:48 -08:00
parent ae6698a924
commit 8136affef9
8 changed files with 13 additions and 12 deletions

View File

@ -61,7 +61,7 @@ namespace Microsoft.AspNet.Security.DataProtection.Azure
{
blobRef.DownloadToStream(memoryStream);
}
catch (StorageException ex) if (ex.RequestInformation.HttpStatusCode == (int)HttpStatusCode.NotFound)
catch (StorageException ex) when (ex.RequestInformation.HttpStatusCode == (int)HttpStatusCode.NotFound)
{
// 404s are not a fatal error - empty keyring
return null;

View File

@ -30,7 +30,7 @@ namespace Microsoft.AspNet.Security.DataProtection.Cng
pbAdditionalAuthenticatedData: (pbAdditionalAuthenticatedDataArray != null) ? &pbAdditionalAuthenticatedDataArray[additionalAuthenticatedData.Offset] : &dummy,
cbAdditionalAuthenticatedData: (uint)additionalAuthenticatedData.Count);
}
catch (Exception ex) if (!(ex is CryptographicException))
catch (Exception ex) when (!(ex is CryptographicException))
{
// Homogenize to CryptographicException.
throw Error.CryptCommon_GenericError(ex);
@ -71,7 +71,7 @@ namespace Microsoft.AspNet.Security.DataProtection.Cng
cbPreBuffer: preBufferSize,
cbPostBuffer: postBufferSize);
}
catch (Exception ex) if (!(ex is CryptographicException))
catch (Exception ex) when (!(ex is CryptographicException))
{
// Homogenize to CryptographicException.
throw Error.CryptCommon_GenericError(ex);

View File

@ -36,7 +36,7 @@ namespace Microsoft.AspNet.Security.DataProtection
byte[] protectedDataAsBytes = protector.Protect(unprotectedDataAsBytes);
return WebEncoders.Base64UrlEncode(protectedDataAsBytes);
}
catch (Exception ex) if (!(ex is CryptographicException))
catch (Exception ex) when (!(ex is CryptographicException))
{
// Homogenize exceptions to CryptographicException
throw Error.CryptCommon_GenericError(ex);
@ -60,7 +60,7 @@ namespace Microsoft.AspNet.Security.DataProtection
byte[] unprotectedDataAsBytes = protector.Unprotect(protectedDataAsBytes);
return CryptoUtil.SecureUtf8Encoding.GetString(unprotectedDataAsBytes);
}
catch (Exception ex) if (!(ex is CryptographicException))
catch (Exception ex) when (!(ex is CryptographicException))
{
// Homogenize exceptions to CryptographicException
throw Error.CryptCommon_GenericError(ex);

View File

@ -43,7 +43,7 @@ namespace Microsoft.AspNet.Security.DataProtection.Dpapi
return _shim.Protect(unprotectedData, _combinedPurposes, _scope)
?? CryptoUtil.Fail<byte[]>("Null return value.");
}
catch (Exception ex) if (!(ex is CryptographicException))
catch (Exception ex) when (!(ex is CryptographicException))
{
// Homogenize to CryptographicException
throw Error.CryptCommon_GenericError(ex);
@ -57,7 +57,7 @@ namespace Microsoft.AspNet.Security.DataProtection.Dpapi
return _shim.Unprotect(protectedData, _combinedPurposes, _scope)
?? CryptoUtil.Fail<byte[]>("Null return value.");
}
catch (Exception ex) if (!(ex is CryptographicException))
catch (Exception ex) when (!(ex is CryptographicException))
{
// Homogenize to CryptographicException
throw Error.CryptCommon_GenericError(ex);

View File

@ -131,7 +131,7 @@ namespace Microsoft.AspNet.Security.DataProtection.KeyManagement
postBufferSize: 0);
CryptoUtil.Assert(retVal != null && retVal.Length >= sizeof(uint) + sizeof(Guid), "retVal != null && retVal.Length >= sizeof(uint) + sizeof(Guid)");
}
catch (Exception ex) if (!(ex is CryptographicException))
catch (Exception ex) when (!(ex is CryptographicException))
{
// homogenize all errors to CryptographicException
throw Error.Common_EncryptionFailed(ex);
@ -247,7 +247,7 @@ namespace Microsoft.AspNet.Security.DataProtection.KeyManagement
CryptoUtil.Assert(retVal != null, "retVal != null");
return retVal;
}
catch (Exception ex) if (!(ex is CryptographicException))
catch (Exception ex) when (!(ex is CryptographicException))
{
// homogenize all failures to CryptographicException
throw Error.DecryptionFailed(ex);

View File

@ -278,7 +278,7 @@ namespace Microsoft.AspNet.Security.DataProtection.Managed
}
}
}
catch (Exception ex) if (!(ex is CryptographicException))
catch (Exception ex) when (!(ex is CryptographicException))
{
// Homogenize all exceptions to CryptographicException.
throw Error.CryptCommon_GenericError(ex);
@ -382,7 +382,7 @@ namespace Microsoft.AspNet.Security.DataProtection.Managed
}
}
}
catch (Exception ex) if (!(ex is CryptographicException))
catch (Exception ex) when (!(ex is CryptographicException))
{
// Homogenize all exceptions to CryptographicException.
throw Error.CryptCommon_GenericError(ex);

View File

@ -86,7 +86,7 @@ namespace Microsoft.AspNet.Security.DataProtection
expiration = new DateTimeOffset((long)utcTicksExpiration, TimeSpan.Zero);
return retVal;
}
catch (Exception ex) if (!(ex is CryptographicException))
catch (Exception ex) when (!(ex is CryptographicException))
{
// Homogenize all failures to CryptographicException
throw Error.CryptCommon_GenericError(ex);

View File

@ -23,6 +23,7 @@
"aspnetcore50": {
"dependencies": {
"Microsoft.Win32.Registry": "4.0.0-beta-*",
"System.IO": "4.0.10-beta-*",
"System.Security.Cryptography.X509Certificates": "4.0.0-beta-*",
"System.Security.Cryptography.Encryption.Aes": "4.0.0-beta-*",
"System.Security.Cryptography.Hashing.Algorithms": "4.0.0-beta-*",