Skip to content

Commit

Permalink
Rename netcore string resource file and helpers (#671)
Browse files Browse the repository at this point in the history
  • Loading branch information
Wraith2 authored Aug 7, 2020
1 parent 8c1f52c commit 4f04db7
Show file tree
Hide file tree
Showing 50 changed files with 635 additions and 639 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -119,44 +119,44 @@ internal static Exception GetExceptionForIoErrno(ErrorInfo errorInfo, string pat
if (isDirectory)
{
return !string.IsNullOrEmpty(path) ?
new DirectoryNotFoundException(SR.Format(SR.IO_PathNotFound_Path, path)) :
new DirectoryNotFoundException(SR.IO_PathNotFound_NoPathName);
new DirectoryNotFoundException(Strings.Format(Strings.IO_PathNotFound_Path, path)) :
new DirectoryNotFoundException(Strings.IO_PathNotFound_NoPathName);
}
else
{
return !string.IsNullOrEmpty(path) ?
new FileNotFoundException(SR.Format(SR.IO_FileNotFound_FileName, path), path) :
new FileNotFoundException(SR.IO_FileNotFound);
new FileNotFoundException(Strings.Format(Strings.IO_FileNotFound_FileName, path), path) :
new FileNotFoundException(Strings.IO_FileNotFound);
}

case Error.EACCES:
case Error.EBADF:
case Error.EPERM:
Exception inner = GetIOException(errorInfo);
return !string.IsNullOrEmpty(path) ?
new UnauthorizedAccessException(SR.Format(SR.UnauthorizedAccess_IODenied_Path, path), inner) :
new UnauthorizedAccessException(SR.UnauthorizedAccess_IODenied_NoPathName, inner);
new UnauthorizedAccessException(Strings.Format(Strings.UnauthorizedAccess_IODenied_Path, path), inner) :
new UnauthorizedAccessException(Strings.UnauthorizedAccess_IODenied_NoPathName, inner);

case Error.ENAMETOOLONG:
return !string.IsNullOrEmpty(path) ?
new PathTooLongException(SR.Format(SR.IO_PathTooLong_Path, path)) :
new PathTooLongException(SR.IO_PathTooLong);
new PathTooLongException(Strings.Format(Strings.IO_PathTooLong_Path, path)) :
new PathTooLongException(Strings.IO_PathTooLong);

case Error.EWOULDBLOCK:
return !string.IsNullOrEmpty(path) ?
new IOException(SR.Format(SR.IO_SharingViolation_File, path), errorInfo.RawErrno) :
new IOException(SR.IO_SharingViolation_NoFileName, errorInfo.RawErrno);
new IOException(Strings.Format(Strings.IO_SharingViolation_File, path), errorInfo.RawErrno) :
new IOException(Strings.IO_SharingViolation_NoFileName, errorInfo.RawErrno);

case Error.ECANCELED:
return new OperationCanceledException();

case Error.EFBIG:
return new ArgumentOutOfRangeException("value", SR.ArgumentOutOfRange_FileLengthTooBig);
return new ArgumentOutOfRangeException("value", Strings.ArgumentOutOfRange_FileLengthTooBig);

case Error.EEXIST:
if (!string.IsNullOrEmpty(path))
{
return new IOException(SR.Format(SR.IO_FileExists_Name, path), errorInfo.RawErrno);
return new IOException(Strings.Format(Strings.IO_FileExists_Name, path), errorInfo.RawErrno);
}
goto default;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,8 @@ private static string GetGssApiDisplayStatus(Status majorStatus, Status minorSta
string minorError = GetGssApiDisplayStatus(minorStatus, isMinor: true);

return (majorError != null && minorError != null) ?
SRHelper.Format(SR.net_gssapi_operation_failed_detailed, majorError, minorError) :
SRHelper.Format(SR.net_gssapi_operation_failed, majorStatus.ToString("x"), minorStatus.ToString("x"));
StringsHelper.Format(Strings.net_gssapi_operation_failed_detailed, majorError, minorError) :
StringsHelper.Format(Strings.net_gssapi_operation_failed, majorStatus.ToString("x"), minorStatus.ToString("x"));
}

private static string GetGssApiDisplayStatus(Status status, bool isMinor)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ internal int Copy(byte[] destination, int offset)
int destinationAvailable = destination.Length - offset; // amount of space in the given buffer
if (sourceLength > destinationAvailable)
{
throw new NetSecurityNative.GssApiException(SRHelper.Format(SR.net_context_buffer_too_small, sourceLength, destinationAvailable));
throw new NetSecurityNative.GssApiException(StringsHelper.Format(Strings.net_context_buffer_too_small, sourceLength, destinationAvailable));
}

Marshal.Copy(_data, destination, offset, sourceLength);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ internal static SafeEcKeyHandle EcKeyCreateByKeyParameters(
key?.Dispose();
Interop.Crypto.ErrClearError();

throw new PlatformNotSupportedException(SR.Format(SR.Cryptography_CurveNotSupported, oid));
throw new PlatformNotSupportedException(Strings.Format(Strings.Cryptography_CurveNotSupported, oid));
}
return key;
}
Expand Down Expand Up @@ -69,7 +69,7 @@ internal static SafeEcKeyHandle EcKeyCreateByExplicitCurve(ECCurve curve)
}
else
{
throw new PlatformNotSupportedException(SR.Format(SR.Cryptography_CurveNotSupported, curve.CurveType.ToString()));
throw new PlatformNotSupportedException(Strings.Format(Strings.Cryptography_CurveNotSupported, curve.CurveType.ToString()));
}

SafeEcKeyHandle key = Interop.Crypto.EcKeyCreateByExplicitParameters(
Expand Down Expand Up @@ -131,7 +131,7 @@ internal static ECParameters GetECKeyParameters(

if (rc == -1)
{
throw new CryptographicException(SR.Cryptography_CSP_NoPrivateKey);
throw new CryptographicException(Strings.Cryptography_CSP_NoPrivateKey);
}
else if (rc != 1)
{
Expand Down Expand Up @@ -218,7 +218,7 @@ internal static ECParameters GetECCurveParameters(

if (rc == -1)
{
throw new CryptographicException(SR.Cryptography_CSP_NoPrivateKey);
throw new CryptographicException(Strings.Cryptography_CSP_NoPrivateKey);
}
else if (rc != 1)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ internal static SafeSslHandle AllocateSslContext(SslProtocols protocols, SafeX50
{
if (innerContext.IsInvalid)
{
throw CreateSslException(SR.net_allocate_ssl_context_failed);
throw CreateSslException(Strings.net_allocate_ssl_context_failed);
}

// Configure allowed protocols. It's ok to use DangerousGetHandle here without AddRef/Release as we just
Expand All @@ -80,7 +80,7 @@ internal static SafeSslHandle AllocateSslContext(SslProtocols protocols, SafeX50
if (!Ssl.SetEncryptionPolicy(innerContext, policy))
{
Crypto.ErrClearError();
throw new PlatformNotSupportedException(SR.Format(SR.net_ssl_encryptionpolicy_notsupported, policy));
throw new PlatformNotSupportedException(Strings.Format(Strings.net_ssl_encryptionpolicy_notsupported, policy));
}

bool hasCertificateAndKey =
Expand Down Expand Up @@ -111,7 +111,7 @@ internal static SafeSslHandle AllocateSslContext(SslProtocols protocols, SafeX50
{
if (Interop.Ssl.SslCtxSetAlpnProtos(innerContext, sslAuthenticationOptions.ApplicationProtocols) != 0)
{
throw CreateSslException(SR.net_alpn_config_failed);
throw CreateSslException(Strings.net_alpn_config_failed);
}
}
}
Expand All @@ -121,7 +121,7 @@ internal static SafeSslHandle AllocateSslContext(SslProtocols protocols, SafeX50
if (context.IsInvalid)
{
context.Dispose();
throw CreateSslException(SR.net_allocate_ssl_context_failed);
throw CreateSslException(Strings.net_allocate_ssl_context_failed);
}

if (!sslAuthenticationOptions.IsServer)
Expand All @@ -147,7 +147,7 @@ internal static SafeSslHandle AllocateSslContext(SslProtocols protocols, SafeX50
using (X509Chain chain = TLSCertificateExtensions.BuildNewChain(cert, includeClientApplicationPolicy: false))
{
if (chain != null && !Ssl.AddExtraChainCertificates(context, chain))
throw CreateSslException(SR.net_ssl_use_cert_failed);
throw CreateSslException(Strings.net_ssl_use_cert_failed);
}
}
}
Expand Down Expand Up @@ -196,7 +196,7 @@ internal static bool DoSslHandshake(SafeSslHandle context, byte[] recvBuf, int r

if ((retVal != -1) || (error != Ssl.SslErrorCode.SSL_ERROR_WANT_READ))
{
throw new SslException(SR.Format(SR.net_ssl_handshake_failed_error, error), innerError);
throw new SslException(Strings.Format(Strings.net_ssl_handshake_failed_error, error), innerError);
}
}

Expand Down Expand Up @@ -259,7 +259,7 @@ internal static int Encrypt(SafeSslHandle context, ReadOnlyMemory<byte> input, r
break;

default:
throw new SslException(SR.Format(SR.net_ssl_encrypt_failed, errorCode), innerError);
throw new SslException(Strings.Format(Strings.net_ssl_encrypt_failed, errorCode), innerError);
}
}
else
Expand Down Expand Up @@ -328,7 +328,7 @@ internal static int Decrypt(SafeSslHandle context, byte[] outBuffer, int offset,
break;

default:
throw new SslException(SR.Format(SR.net_ssl_decrypt_failed, errorCode), innerError);
throw new SslException(Strings.Format(Strings.net_ssl_decrypt_failed, errorCode), innerError);
}
}

Expand Down Expand Up @@ -358,7 +358,7 @@ private static void QueryUniqueChannelBinding(SafeSslHandle context, SafeChannel

if (0 == certHashLength)
{
throw CreateSslException(SR.net_ssl_get_channel_binding_token_failed);
throw CreateSslException(Strings.net_ssl_get_channel_binding_token_failed);
}

bindingHandle.SetCertHashLength(certHashLength);
Expand Down Expand Up @@ -430,7 +430,7 @@ private static int BioRead(SafeBioHandle bio, byte[] buffer, int count)
int bytes = Crypto.BioRead(bio, buffer, count);
if (bytes != count)
{
throw CreateSslException(SR.net_ssl_read_bio_failed_error);
throw CreateSslException(Strings.net_ssl_read_bio_failed_error);
}
return bytes;
}
Expand All @@ -453,7 +453,7 @@ private static int BioWrite(SafeBioHandle bio, byte[] buffer, int offset, int co

if (bytes != count)
{
throw CreateSslException(SR.net_ssl_write_bio_failed_error);
throw CreateSslException(Strings.net_ssl_write_bio_failed_error);
}
return bytes;
}
Expand Down Expand Up @@ -496,22 +496,22 @@ private static void SetSslCertificate(SafeSslContextHandle contextPtr, SafeX509H

if (1 != retVal)
{
throw CreateSslException(SR.net_ssl_use_cert_failed);
throw CreateSslException(Strings.net_ssl_use_cert_failed);
}

retVal = Ssl.SslCtxUsePrivateKey(contextPtr, keyPtr);

if (1 != retVal)
{
throw CreateSslException(SR.net_ssl_use_private_key_failed);
throw CreateSslException(Strings.net_ssl_use_private_key_failed);
}

//check private key
retVal = Ssl.SslCtxCheckPrivateKey(contextPtr);

if (1 != retVal)
{
throw CreateSslException(SR.net_ssl_check_private_key_failed);
throw CreateSslException(Strings.net_ssl_check_private_key_failed);
}
}

Expand All @@ -520,7 +520,7 @@ internal static SslException CreateSslException(string message)
// Capture last error to be consistent with CreateOpenSslCryptographicException
ulong errorVal = Crypto.ErrPeekLastError();
Crypto.ErrClearError();
string msg = SR.Format(message, Marshal.PtrToStringAnsi(Crypto.ErrReasonErrorString(errorVal)));
string msg = Strings.Format(message, Marshal.PtrToStringAnsi(Crypto.ErrReasonErrorString(errorVal)));
return new SslException(msg, (int)errorVal);
}

Expand All @@ -547,7 +547,7 @@ public SslException(string inputMessage, int error)
}

public SslException(int error)
: this(SR.Format(SR.net_generic_operation_failed, error))
: this(Strings.Format(Strings.net_generic_operation_failed, error))
{
HResult = error;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ internal static byte[] ConvertAlpnProtocolListToByteArray(List<SslApplicationPro
{
if (protocol.Protocol.Length == 0 || protocol.Protocol.Length > byte.MaxValue)
{
throw new ArgumentException(SR.net_ssl_app_protocols_invalid, nameof(applicationProtocols));
throw new ArgumentException(Strings.net_ssl_app_protocols_invalid, nameof(applicationProtocols));
}

protocolSize += protocol.Protocol.Length + 1;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ public unsafe int DecryptMessage(SafeDeleteContext context, ref Interop.SspiCli.
if (status == 0 && qop == Interop.SspiCli.SECQOP_WRAP_NO_ENCRYPT)
{
NetEventSource.Fail(this, $"Expected qop = 0, returned value = {qop}");
throw new InvalidOperationException(SR.net_auth_message_not_encrypted);
throw new InvalidOperationException(Strings.net_auth_message_not_encrypted);
}

return status;
Expand Down Expand Up @@ -156,7 +156,7 @@ public unsafe int QueryContextAttributes(SafeDeleteContext context, Interop.Sspi
}
else
{
throw new ArgumentException(SRHelper.Format(SR.SSPIInvalidHandleType, handleType.FullName), nameof(handleType));
throw new ArgumentException(StringsHelper.Format(Strings.SSPIInvalidHandleType, handleType.FullName), nameof(handleType));
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,12 +97,12 @@ public unsafe int DecryptMessage(SafeDeleteContext context, ref Interop.SspiCli.

public int MakeSignature(SafeDeleteContext context, ref Interop.SspiCli.SecBufferDesc inputOutput, uint sequenceNumber)
{
throw NotImplemented.ByDesignWithMessage(SR.net_MethodNotImplementedException);
throw NotImplemented.ByDesignWithMessage(Strings.net_MethodNotImplementedException);
}

public int VerifySignature(SafeDeleteContext context, ref Interop.SspiCli.SecBufferDesc inputOutput, uint sequenceNumber)
{
throw NotImplemented.ByDesignWithMessage(SR.net_MethodNotImplementedException);
throw NotImplemented.ByDesignWithMessage(Strings.net_MethodNotImplementedException);
}

public unsafe int QueryContextChannelBinding(SafeDeleteContext phContext, Interop.SspiCli.ContextAttribute attribute, out SafeFreeContextBufferChannelBinding refHandle)
Expand All @@ -129,7 +129,7 @@ public unsafe int QueryContextAttributes(SafeDeleteContext phContext, Interop.Ss
}
else
{
throw new ArgumentException(System.SRHelper.Format(SR.SSPIInvalidHandleType, handleType.FullName), nameof(handleType));
throw new ArgumentException(System.StringsHelper.Format(Strings.SSPIInvalidHandleType, handleType.FullName), nameof(handleType));
}
}
fixed (byte* bufferPtr = buffer)
Expand Down
Loading

0 comments on commit 4f04db7

Please sign in to comment.