MCPcopy Create free account
hub / github.com/apple/foundationdb / insertBaseCipherKey

Method insertBaseCipherKey

flow/BlobCipher.cpp:152–185  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

150}
151
152Reference<BlobCipherKey> BlobCipherKeyIdCache::insertBaseCipherKey(const EncryptCipherBaseKeyId& baseCipherId,
153 const uint8_t* baseCipher,
154 int baseCipherLen) {
155 ASSERT_GT(baseCipherId, ENCRYPT_INVALID_CIPHER_KEY_ID);
156
157 // BaseCipherKeys are immutable, given the routine invocation updates 'latestCipher',
158 // ensure no key-tampering is done
159 Reference<BlobCipherKey> latestCipherKey = getLatestCipherKey();
160 if (latestCipherKey.isValid() && latestCipherKey->getBaseCipherId() == baseCipherId) {
161 if (memcmp(latestCipherKey->rawBaseCipher(), baseCipher, baseCipherLen) == 0) {
162 TraceEvent("InsertBaseCipherKey_AlreadyPresent")
163 .detail("BaseCipherKeyId", baseCipherId)
164 .detail("DomainId", domainId);
165 // Key is already present; nothing more to do.
166 return latestCipherKey;
167 } else {
168 TraceEvent("InsertBaseCipherKey_UpdateCipher")
169 .detail("BaseCipherKeyId", baseCipherId)
170 .detail("DomainId", domainId);
171 throw encrypt_update_cipher();
172 }
173 }
174
175 Reference<BlobCipherKey> cipherKey =
176 makeReference<BlobCipherKey>(domainId, baseCipherId, baseCipher, baseCipherLen);
177 BlobCipherKeyIdCacheKey cacheKey = getCacheKey(cipherKey->getBaseCipherId(), cipherKey->getSalt());
178 keyIdCache.emplace(cacheKey, cipherKey);
179
180 // Update the latest BaseCipherKeyId for the given encryption domain
181 latestBaseCipherKeyId = baseCipherId;
182 latestRandomSalt = cipherKey->getSalt();
183
184 return cipherKey;
185}
186
187Reference<BlobCipherKey> BlobCipherKeyIdCache::insertBaseCipherKey(const EncryptCipherBaseKeyId& baseCipherId,
188 const uint8_t* baseCipher,

Callers 1

insertCipherKeyMethod · 0.80

Calls 8

TraceEventClass · 0.85
getBaseCipherIdMethod · 0.80
rawBaseCipherMethod · 0.80
detailMethod · 0.80
getSaltMethod · 0.80
isValidMethod · 0.45
findMethod · 0.45
endMethod · 0.45

Tested by

no test coverage detected