| 193 | } |
| 194 | |
| 195 | std::string wipeSensitiveDataAndCutToLength(const std::string & str, size_t max_length) |
| 196 | { |
| 197 | std::string res = str; |
| 198 | |
| 199 | if (auto * masker = SensitiveDataMasker::getInstance()) |
| 200 | masker->wipeSensitiveData(res); |
| 201 | |
| 202 | size_t length = res.length(); |
| 203 | if (max_length && (length > max_length)) |
| 204 | { |
| 205 | constexpr size_t max_extra_msg_len = sizeof("... (truncated 18446744073709551615 characters)"); |
| 206 | if (max_length < max_extra_msg_len) |
| 207 | return "(removed " + std::to_string(length) + " characters)"; |
| 208 | max_length -= max_extra_msg_len; |
| 209 | res.resize(max_length); |
| 210 | res.append("... (truncated " + std::to_string(length - max_length) + " characters)"); |
| 211 | } |
| 212 | |
| 213 | return res; |
| 214 | } |
| 215 | |
| 216 | } |
no test coverage detected