From d8f4066a1d53da84bd616d5be12ea173c8570243 Mon Sep 17 00:00:00 2001 From: Wraith2 Date: Fri, 22 Sep 2023 01:21:38 +0100 Subject: [PATCH] remove duplicated ForceColumnEncryption property check --- .../src/Microsoft/Data/SqlClient/TdsParser.cs | 27 ++++++++++-------- .../src/Microsoft/Data/SqlClient/TdsParser.cs | 28 +++++++++++-------- 2 files changed, 31 insertions(+), 24 deletions(-) diff --git a/src/Microsoft.Data.SqlClient/netcore/src/Microsoft/Data/SqlClient/TdsParser.cs b/src/Microsoft.Data.SqlClient/netcore/src/Microsoft/Data/SqlClient/TdsParser.cs index bde99cda5e..be2c6e5838 100644 --- a/src/Microsoft.Data.SqlClient/netcore/src/Microsoft/Data/SqlClient/TdsParser.cs +++ b/src/Microsoft.Data.SqlClient/netcore/src/Microsoft/Data/SqlClient/TdsParser.cs @@ -9170,20 +9170,23 @@ internal Task TdsExecuteRPC(SqlCommand cmd, _SqlRPC[] rpcArray, int timeout, boo ParameterDirection parameterDirection = param.Direction; - // Throw an exception if ForceColumnEncryption is set on a parameter and the ColumnEncryption is not enabled on SqlConnection or SqlCommand - if (param.ForceColumnEncryption && - !(cmd.ColumnEncryptionSetting == SqlCommandColumnEncryptionSetting.Enabled || - (cmd.ColumnEncryptionSetting == SqlCommandColumnEncryptionSetting.UseConnectionSetting && cmd.Connection.IsColumnEncryptionSettingEnabled))) + if (param.ForceColumnEncryption) { - throw SQL.ParamInvalidForceColumnEncryptionSetting(param.ParameterName, rpcext.GetCommandTextOrRpcName()); - } + // Throw an exception if ForceColumnEncryption is set on a parameter and the ColumnEncryption is not enabled on SqlConnection or SqlCommand + if ( + !(cmd.ColumnEncryptionSetting == SqlCommandColumnEncryptionSetting.Enabled + || + (cmd.ColumnEncryptionSetting == SqlCommandColumnEncryptionSetting.UseConnectionSetting && cmd.Connection.IsColumnEncryptionSettingEnabled))) + { + throw SQL.ParamInvalidForceColumnEncryptionSetting(param.ParameterName, rpcext.GetCommandTextOrRpcName()); + } - // Check if the applications wants to force column encryption to avoid sending sensitive data to server - if (param.ForceColumnEncryption && param.CipherMetadata == null - && (parameterDirection == ParameterDirection.Input || parameterDirection == ParameterDirection.InputOutput)) - { - // Application wants a parameter to be encrypted before sending it to server, however server doesnt think this parameter needs encryption. - throw SQL.ParamUnExpectedEncryptionMetadata(param.ParameterName, rpcext.GetCommandTextOrRpcName()); + // Check if the applications wants to force column encryption to avoid sending sensitive data to server + if (param.CipherMetadata == null && (parameterDirection == ParameterDirection.Input || parameterDirection == ParameterDirection.InputOutput)) + { + // Application wants a parameter to be encrypted before sending it to server, however server doesnt think this parameter needs encryption. + throw SQL.ParamUnExpectedEncryptionMetadata(param.ParameterName, rpcext.GetCommandTextOrRpcName()); + } } if (enableOptimizedParameterBinding && (parameterDirection == ParameterDirection.Output || parameterDirection == ParameterDirection.InputOutput)) diff --git a/src/Microsoft.Data.SqlClient/netfx/src/Microsoft/Data/SqlClient/TdsParser.cs b/src/Microsoft.Data.SqlClient/netfx/src/Microsoft/Data/SqlClient/TdsParser.cs index 4aa369203e..d35bfd022f 100644 --- a/src/Microsoft.Data.SqlClient/netfx/src/Microsoft/Data/SqlClient/TdsParser.cs +++ b/src/Microsoft.Data.SqlClient/netfx/src/Microsoft/Data/SqlClient/TdsParser.cs @@ -10075,20 +10075,24 @@ internal Task TdsExecuteRPC(SqlCommand cmd, _SqlRPC[] rpcArray, int timeout, boo ParameterDirection parameterDirection = param.Direction; - // Throw an exception if ForceColumnEncryption is set on a parameter and the ColumnEncryption is not enabled on SqlConnection or SqlCommand - if (param.ForceColumnEncryption && - !(cmd.ColumnEncryptionSetting == SqlCommandColumnEncryptionSetting.Enabled || - (cmd.ColumnEncryptionSetting == SqlCommandColumnEncryptionSetting.UseConnectionSetting && cmd.Connection.IsColumnEncryptionSettingEnabled))) + if (param.ForceColumnEncryption) { - throw SQL.ParamInvalidForceColumnEncryptionSetting(param.ParameterName, rpcext.GetCommandTextOrRpcName()); - } + // Throw an exception if ForceColumnEncryption is set on a parameter and the ColumnEncryption is not enabled on SqlConnection or SqlCommand + if ( + !(cmd.ColumnEncryptionSetting == SqlCommandColumnEncryptionSetting.Enabled + || + (cmd.ColumnEncryptionSetting == SqlCommandColumnEncryptionSetting.UseConnectionSetting && cmd.Connection.IsColumnEncryptionSettingEnabled)) + ) + { + throw SQL.ParamInvalidForceColumnEncryptionSetting(param.ParameterName, rpcext.GetCommandTextOrRpcName()); + } - // Check if the applications wants to force column encryption to avoid sending sensitive data to server - if (param.ForceColumnEncryption && param.CipherMetadata == null - && (parameterDirection == ParameterDirection.Input || parameterDirection == ParameterDirection.InputOutput)) - { - // Application wants a parameter to be encrypted before sending it to server, however server doesnt think this parameter needs encryption. - throw SQL.ParamUnExpectedEncryptionMetadata(param.ParameterName, rpcext.GetCommandTextOrRpcName()); + // Check if the applications wants to force column encryption to avoid sending sensitive data to server + if (param.CipherMetadata == null && (parameterDirection == ParameterDirection.Input || parameterDirection == ParameterDirection.InputOutput)) + { + // Application wants a parameter to be encrypted before sending it to server, however server doesnt think this parameter needs encryption. + throw SQL.ParamUnExpectedEncryptionMetadata(param.ParameterName, rpcext.GetCommandTextOrRpcName()); + } } if (enableOptimizedParameterBinding && (parameterDirection == ParameterDirection.Output || parameterDirection == ParameterDirection.InputOutput))