| 252 | |
| 253 | |
| 254 | std::string wipeSensitiveDataAndCutToLength(std::string str, size_t max_length, bool wipe_sensitive) |
| 255 | { |
| 256 | std::string res = std::move(str); |
| 257 | |
| 258 | if (wipe_sensitive) |
| 259 | if (auto masker = SensitiveDataMasker::getInstance()) |
| 260 | masker->wipeSensitiveData(res); |
| 261 | |
| 262 | size_t length = res.length(); |
| 263 | if (max_length && (length > max_length)) |
| 264 | { |
| 265 | constexpr size_t max_extra_msg_len = sizeof("... (truncated 18446744073709551615 characters)"); |
| 266 | if (max_length < max_extra_msg_len) |
| 267 | return "(removed " + std::to_string(length) + " characters)"; |
| 268 | max_length -= max_extra_msg_len; |
| 269 | res.resize(max_length); |
| 270 | res.append("... (truncated " + std::to_string(length - max_length) + " characters)"); |
| 271 | } |
| 272 | |
| 273 | return res; |
| 274 | } |
| 275 | |
| 276 | } |
no test coverage detected