|
@@ -194,8 +194,11 @@ void EncryptionManager::encryptSensitiveFields(Document& doc) {
|
|
|
|
|
|
|
|
std::lock_guard lock(mutex_);
|
|
std::lock_guard lock(mutex_);
|
|
|
|
|
|
|
|
- // Traverse JSON and encrypt sensitive fields
|
|
|
|
|
- encryptJsonField(doc.data, "");
|
|
|
|
|
|
|
+ // Materialise once, mutate via the existing recursive helper, then
|
|
|
|
|
+ // re-encode. encryptJsonField mutates the tree in place.
|
|
|
|
|
+ nlohmann::json tree = doc.data();
|
|
|
|
|
+ encryptJsonField(tree, "");
|
|
|
|
|
+ doc.set_data(tree);
|
|
|
|
|
|
|
|
doc.encrypted = true;
|
|
doc.encrypted = true;
|
|
|
}
|
|
}
|
|
@@ -208,7 +211,9 @@ void EncryptionManager::decryptSensitiveFields(Document& doc) {
|
|
|
std::lock_guard lock(mutex_);
|
|
std::lock_guard lock(mutex_);
|
|
|
|
|
|
|
|
// Traverse JSON and decrypt sensitive fields
|
|
// Traverse JSON and decrypt sensitive fields
|
|
|
- decryptJsonField(doc.data, "", doc.collection, doc.id);
|
|
|
|
|
|
|
+ nlohmann::json tree = doc.data();
|
|
|
|
|
+ decryptJsonField(tree, "", doc.collection, doc.id);
|
|
|
|
|
+ doc.set_data(tree);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
void EncryptionManager::preserveUnchangedEncryption(Document& newDoc, const Document& existingDoc) {
|
|
void EncryptionManager::preserveUnchangedEncryption(Document& newDoc, const Document& existingDoc) {
|
|
@@ -217,7 +222,12 @@ void EncryptionManager::preserveUnchangedEncryption(Document& newDoc, const Docu
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
std::lock_guard lock(mutex_);
|
|
std::lock_guard lock(mutex_);
|
|
|
- preserveUnchangedJsonField(newDoc.data, existingDoc.data, "");
|
|
|
|
|
|
|
+ // existingDoc is const — we need both trees in scope long enough to
|
|
|
|
|
+ // walk them. Decode both, mutate newTree, write back.
|
|
|
|
|
+ nlohmann::json newTree = newDoc.data();
|
|
|
|
|
+ const nlohmann::json& existingTree = existingDoc.data();
|
|
|
|
|
+ preserveUnchangedJsonField(newTree, existingTree, "");
|
|
|
|
|
+ newDoc.set_data(newTree);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
void EncryptionManager::preserveUnchangedJsonField(nlohmann::json& newObj,
|
|
void EncryptionManager::preserveUnchangedJsonField(nlohmann::json& newObj,
|