| 1343 | |
| 1344 | #ifndef MMKV_DISABLE_CRYPT |
| 1345 | bool MMKV::doFullWriteBack(pair<MMBuffer, size_t> prepared, AESCrypt *newCrypter, bool needSync) { |
| 1346 | auto ptr = (uint8_t *) m_file->getMemory(); |
| 1347 | auto totalSize = prepared.second; |
| 1348 | |
| 1349 | uint8_t newIV[AES_IV_LEN]; |
| 1350 | auto encrypter = (newCrypter == InvalidCryptPtr) ? nullptr : (newCrypter ? newCrypter : m_crypter); |
| 1351 | if (encrypter) { |
| 1352 | AESCrypt::fillRandomIV(newIV); |
| 1353 | encrypter->resetIV(newIV, sizeof(newIV)); |
| 1354 | } |
| 1355 | |
| 1356 | delete m_output; |
| 1357 | m_output = new CodedOutputData(ptr + Fixed32Size, m_file->getFileSize() - Fixed32Size); |
| 1358 | if (m_crypter) { |
| 1359 | auto decrypter = m_crypter; |
| 1360 | memmoveDictionary(*m_dicCrypt, m_output, ptr, decrypter, encrypter, prepared); |
| 1361 | } else if (prepared.first.length() != 0) { |
| 1362 | auto &preparedData = prepared.first; |
| 1363 | fullWriteBackWholeData(std::move(preparedData), totalSize, m_output); |
| 1364 | if (encrypter) { |
| 1365 | encrypter->encrypt(ptr + Fixed32Size, ptr + Fixed32Size, totalSize); |
| 1366 | } |
| 1367 | } else { |
| 1368 | memmoveDictionary(*m_dic, m_output, ptr, encrypter, totalSize); |
| 1369 | } |
| 1370 | |
| 1371 | m_actualSize = totalSize; |
| 1372 | if (encrypter) { |
| 1373 | recalculateCRCDigestWithIV(newIV); |
| 1374 | } else { |
| 1375 | recalculateCRCDigestWithIV(nullptr); |
| 1376 | } |
| 1377 | m_hasFullWriteback = true; |
| 1378 | // make sure lastConfirmedMetaInfo is saved if needed |
| 1379 | if (needSync) { |
| 1380 | sync(MMKV_SYNC); |
| 1381 | } |
| 1382 | return true; |
| 1383 | } |
| 1384 | |
| 1385 | #else // MMKV_DISABLE_CRYPT |
| 1386 |
nothing calls this directly
no test coverage detected