Skip to content

Commit

Permalink
make enclave key map lazy initialized (#372)
Browse files Browse the repository at this point in the history
  • Loading branch information
Wraith2 authored and karinazhou committed Jan 8, 2020
1 parent 8ff5125 commit 166a79e
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ private enum EXECTYPE
// cached metadata
private _SqlMetaDataSet _cachedMetaData;

private Dictionary<int, SqlTceCipherInfoEntry> keysToBeSentToEnclave = new Dictionary<int, SqlTceCipherInfoEntry>();
private Dictionary<int, SqlTceCipherInfoEntry> keysToBeSentToEnclave;
private bool requiresEnclaveComputations = false;
internal EnclavePackage enclavePackage = null;
private SqlEnclaveAttestationParameters enclaveAttestationParameters = null;
Expand Down Expand Up @@ -2994,8 +2994,10 @@ private void ResetEncryptionState()
_parameters[i].HasReceivedMetadata = false;
}
}

keysToBeSentToEnclave.Clear();
if (keysToBeSentToEnclave != null)
{
keysToBeSentToEnclave.Clear();
}
enclavePackage = null;
requiresEnclaveComputations = false;
enclaveAttestationParameters = null;
Expand Down Expand Up @@ -3728,10 +3730,14 @@ private void ReadDescribeEncryptionParameterResults(SqlDataReader ds, ReadOnlyDi
{
throw SQL.InvalidEncryptionKeyOrdinalEnclaveMetadata(requestedKey, columnEncryptionKeyTable.Count);
}

if (!keysToBeSentToEnclave.ContainsKey(currentOrdinal))
if (keysToBeSentToEnclave == null)
{
keysToBeSentToEnclave = new Dictionary<int, SqlTceCipherInfoEntry>();
keysToBeSentToEnclave.Add(currentOrdinal, cipherInfo);
}
else if (!keysToBeSentToEnclave.ContainsKey(currentOrdinal))
{
this.keysToBeSentToEnclave.Add(currentOrdinal, cipherInfo);
keysToBeSentToEnclave.Add(currentOrdinal, cipherInfo);
}

requiresEnclaveComputations = true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ private enum EXECTYPE
// cached metadata
private _SqlMetaDataSet _cachedMetaData;

private Dictionary<int, SqlTceCipherInfoEntry> keysToBeSentToEnclave = new Dictionary<int, SqlTceCipherInfoEntry>();
private Dictionary<int, SqlTceCipherInfoEntry> keysToBeSentToEnclave;
private bool requiresEnclaveComputations = false;
internal EnclaveDelegate.EnclavePackage enclavePackage = null;
private SqlEnclaveAttestationParameters enclaveAttestationParameters = null;
Expand Down Expand Up @@ -3872,7 +3872,10 @@ private void ResetEncryptionState()
}
}

keysToBeSentToEnclave.Clear();
if (keysToBeSentToEnclave != null)
{
keysToBeSentToEnclave.Clear();
}
enclavePackage = null;
requiresEnclaveComputations = false;
enclaveAttestationParameters = null;
Expand Down Expand Up @@ -4666,9 +4669,14 @@ private void ReadDescribeEncryptionParameterResults(SqlDataReader ds, ReadOnlyDi
throw SQL.InvalidEncryptionKeyOrdinalEnclaveMetadata(requestedKey, columnEncryptionKeyTable.Count);
}

if (!keysToBeSentToEnclave.ContainsKey(currentOrdinal))
if (keysToBeSentToEnclave == null)
{
keysToBeSentToEnclave = new Dictionary<int, SqlTceCipherInfoEntry>();
keysToBeSentToEnclave.Add(currentOrdinal, cipherInfo);
}
else if (!keysToBeSentToEnclave.ContainsKey(currentOrdinal))
{
this.keysToBeSentToEnclave.Add(currentOrdinal, cipherInfo);
keysToBeSentToEnclave.Add(currentOrdinal, cipherInfo);
}

requiresEnclaveComputations = true;
Expand Down

0 comments on commit 166a79e

Please sign in to comment.