Skip to content

Commit 166a79e

Browse files
Wraith2karinazhou
authored andcommitted
make enclave key map lazy initialized (#372)
1 parent 8ff5125 commit 166a79e

File tree

2 files changed

+24
-10
lines changed

2 files changed

+24
-10
lines changed

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

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ private enum EXECTYPE
111111
// cached metadata
112112
private _SqlMetaDataSet _cachedMetaData;
113113

114-
private Dictionary<int, SqlTceCipherInfoEntry> keysToBeSentToEnclave = new Dictionary<int, SqlTceCipherInfoEntry>();
114+
private Dictionary<int, SqlTceCipherInfoEntry> keysToBeSentToEnclave;
115115
private bool requiresEnclaveComputations = false;
116116
internal EnclavePackage enclavePackage = null;
117117
private SqlEnclaveAttestationParameters enclaveAttestationParameters = null;
@@ -2994,8 +2994,10 @@ private void ResetEncryptionState()
29942994
_parameters[i].HasReceivedMetadata = false;
29952995
}
29962996
}
2997-
2998-
keysToBeSentToEnclave.Clear();
2997+
if (keysToBeSentToEnclave != null)
2998+
{
2999+
keysToBeSentToEnclave.Clear();
3000+
}
29993001
enclavePackage = null;
30003002
requiresEnclaveComputations = false;
30013003
enclaveAttestationParameters = null;
@@ -3728,10 +3730,14 @@ private void ReadDescribeEncryptionParameterResults(SqlDataReader ds, ReadOnlyDi
37283730
{
37293731
throw SQL.InvalidEncryptionKeyOrdinalEnclaveMetadata(requestedKey, columnEncryptionKeyTable.Count);
37303732
}
3731-
3732-
if (!keysToBeSentToEnclave.ContainsKey(currentOrdinal))
3733+
if (keysToBeSentToEnclave == null)
3734+
{
3735+
keysToBeSentToEnclave = new Dictionary<int, SqlTceCipherInfoEntry>();
3736+
keysToBeSentToEnclave.Add(currentOrdinal, cipherInfo);
3737+
}
3738+
else if (!keysToBeSentToEnclave.ContainsKey(currentOrdinal))
37333739
{
3734-
this.keysToBeSentToEnclave.Add(currentOrdinal, cipherInfo);
3740+
keysToBeSentToEnclave.Add(currentOrdinal, cipherInfo);
37353741
}
37363742

37373743
requiresEnclaveComputations = true;

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

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ private enum EXECTYPE
121121
// cached metadata
122122
private _SqlMetaDataSet _cachedMetaData;
123123

124-
private Dictionary<int, SqlTceCipherInfoEntry> keysToBeSentToEnclave = new Dictionary<int, SqlTceCipherInfoEntry>();
124+
private Dictionary<int, SqlTceCipherInfoEntry> keysToBeSentToEnclave;
125125
private bool requiresEnclaveComputations = false;
126126
internal EnclaveDelegate.EnclavePackage enclavePackage = null;
127127
private SqlEnclaveAttestationParameters enclaveAttestationParameters = null;
@@ -3872,7 +3872,10 @@ private void ResetEncryptionState()
38723872
}
38733873
}
38743874

3875-
keysToBeSentToEnclave.Clear();
3875+
if (keysToBeSentToEnclave != null)
3876+
{
3877+
keysToBeSentToEnclave.Clear();
3878+
}
38763879
enclavePackage = null;
38773880
requiresEnclaveComputations = false;
38783881
enclaveAttestationParameters = null;
@@ -4666,9 +4669,14 @@ private void ReadDescribeEncryptionParameterResults(SqlDataReader ds, ReadOnlyDi
46664669
throw SQL.InvalidEncryptionKeyOrdinalEnclaveMetadata(requestedKey, columnEncryptionKeyTable.Count);
46674670
}
46684671

4669-
if (!keysToBeSentToEnclave.ContainsKey(currentOrdinal))
4672+
if (keysToBeSentToEnclave == null)
4673+
{
4674+
keysToBeSentToEnclave = new Dictionary<int, SqlTceCipherInfoEntry>();
4675+
keysToBeSentToEnclave.Add(currentOrdinal, cipherInfo);
4676+
}
4677+
else if (!keysToBeSentToEnclave.ContainsKey(currentOrdinal))
46704678
{
4671-
this.keysToBeSentToEnclave.Add(currentOrdinal, cipherInfo);
4679+
keysToBeSentToEnclave.Add(currentOrdinal, cipherInfo);
46724680
}
46734681

46744682
requiresEnclaveComputations = true;

0 commit comments

Comments
 (0)