Skip to content

Commit 7f203dd

Browse files
authored
Remove duplicated ForceColumnEncryption property check (#2166)
1 parent b3110be commit 7f203dd

File tree

2 files changed

+31
-24
lines changed
  • src/Microsoft.Data.SqlClient

2 files changed

+31
-24
lines changed

src/Microsoft.Data.SqlClient/netcore/src/Microsoft/Data/SqlClient/TdsParser.cs

+15-12
Original file line numberDiff line numberDiff line change
@@ -9174,20 +9174,23 @@ internal Task TdsExecuteRPC(SqlCommand cmd, _SqlRPC[] rpcArray, int timeout, boo
91749174

91759175
ParameterDirection parameterDirection = param.Direction;
91769176

9177-
// Throw an exception if ForceColumnEncryption is set on a parameter and the ColumnEncryption is not enabled on SqlConnection or SqlCommand
9178-
if (param.ForceColumnEncryption &&
9179-
!(cmd.ColumnEncryptionSetting == SqlCommandColumnEncryptionSetting.Enabled ||
9180-
(cmd.ColumnEncryptionSetting == SqlCommandColumnEncryptionSetting.UseConnectionSetting && cmd.Connection.IsColumnEncryptionSettingEnabled)))
9177+
if (param.ForceColumnEncryption)
91819178
{
9182-
throw SQL.ParamInvalidForceColumnEncryptionSetting(param.ParameterName, rpcext.GetCommandTextOrRpcName());
9183-
}
9179+
// Throw an exception if ForceColumnEncryption is set on a parameter and the ColumnEncryption is not enabled on SqlConnection or SqlCommand
9180+
if (
9181+
!(cmd.ColumnEncryptionSetting == SqlCommandColumnEncryptionSetting.Enabled
9182+
||
9183+
(cmd.ColumnEncryptionSetting == SqlCommandColumnEncryptionSetting.UseConnectionSetting && cmd.Connection.IsColumnEncryptionSettingEnabled)))
9184+
{
9185+
throw SQL.ParamInvalidForceColumnEncryptionSetting(param.ParameterName, rpcext.GetCommandTextOrRpcName());
9186+
}
91849187

9185-
// Check if the applications wants to force column encryption to avoid sending sensitive data to server
9186-
if (param.ForceColumnEncryption && param.CipherMetadata == null
9187-
&& (parameterDirection == ParameterDirection.Input || parameterDirection == ParameterDirection.InputOutput))
9188-
{
9189-
// Application wants a parameter to be encrypted before sending it to server, however server doesnt think this parameter needs encryption.
9190-
throw SQL.ParamUnExpectedEncryptionMetadata(param.ParameterName, rpcext.GetCommandTextOrRpcName());
9188+
// Check if the applications wants to force column encryption to avoid sending sensitive data to server
9189+
if (param.CipherMetadata == null && (parameterDirection == ParameterDirection.Input || parameterDirection == ParameterDirection.InputOutput))
9190+
{
9191+
// Application wants a parameter to be encrypted before sending it to server, however server doesnt think this parameter needs encryption.
9192+
throw SQL.ParamUnExpectedEncryptionMetadata(param.ParameterName, rpcext.GetCommandTextOrRpcName());
9193+
}
91919194
}
91929195

91939196
if (enableOptimizedParameterBinding && (parameterDirection == ParameterDirection.Output || parameterDirection == ParameterDirection.InputOutput))

src/Microsoft.Data.SqlClient/netfx/src/Microsoft/Data/SqlClient/TdsParser.cs

+16-12
Original file line numberDiff line numberDiff line change
@@ -10078,20 +10078,24 @@ internal Task TdsExecuteRPC(SqlCommand cmd, _SqlRPC[] rpcArray, int timeout, boo
1007810078

1007910079
ParameterDirection parameterDirection = param.Direction;
1008010080

10081-
// Throw an exception if ForceColumnEncryption is set on a parameter and the ColumnEncryption is not enabled on SqlConnection or SqlCommand
10082-
if (param.ForceColumnEncryption &&
10083-
!(cmd.ColumnEncryptionSetting == SqlCommandColumnEncryptionSetting.Enabled ||
10084-
(cmd.ColumnEncryptionSetting == SqlCommandColumnEncryptionSetting.UseConnectionSetting && cmd.Connection.IsColumnEncryptionSettingEnabled)))
10081+
if (param.ForceColumnEncryption)
1008510082
{
10086-
throw SQL.ParamInvalidForceColumnEncryptionSetting(param.ParameterName, rpcext.GetCommandTextOrRpcName());
10087-
}
10083+
// Throw an exception if ForceColumnEncryption is set on a parameter and the ColumnEncryption is not enabled on SqlConnection or SqlCommand
10084+
if (
10085+
!(cmd.ColumnEncryptionSetting == SqlCommandColumnEncryptionSetting.Enabled
10086+
||
10087+
(cmd.ColumnEncryptionSetting == SqlCommandColumnEncryptionSetting.UseConnectionSetting && cmd.Connection.IsColumnEncryptionSettingEnabled))
10088+
)
10089+
{
10090+
throw SQL.ParamInvalidForceColumnEncryptionSetting(param.ParameterName, rpcext.GetCommandTextOrRpcName());
10091+
}
1008810092

10089-
// Check if the applications wants to force column encryption to avoid sending sensitive data to server
10090-
if (param.ForceColumnEncryption && param.CipherMetadata == null
10091-
&& (parameterDirection == ParameterDirection.Input || parameterDirection == ParameterDirection.InputOutput))
10092-
{
10093-
// Application wants a parameter to be encrypted before sending it to server, however server doesnt think this parameter needs encryption.
10094-
throw SQL.ParamUnExpectedEncryptionMetadata(param.ParameterName, rpcext.GetCommandTextOrRpcName());
10093+
// Check if the applications wants to force column encryption to avoid sending sensitive data to server
10094+
if (param.CipherMetadata == null && (parameterDirection == ParameterDirection.Input || parameterDirection == ParameterDirection.InputOutput))
10095+
{
10096+
// Application wants a parameter to be encrypted before sending it to server, however server doesnt think this parameter needs encryption.
10097+
throw SQL.ParamUnExpectedEncryptionMetadata(param.ParameterName, rpcext.GetCommandTextOrRpcName());
10098+
}
1009510099
}
1009610100

1009710101
if (enableOptimizedParameterBinding && (parameterDirection == ParameterDirection.Output || parameterDirection == ParameterDirection.InputOutput))

0 commit comments

Comments
 (0)