enh(Foundation): add Poco::secureClear() for securely clearing a string by first overwriting it with zeroes.

This commit is contained in:
Günter Obiltschnig 2024-06-11 10:42:49 +02:00
parent bc29f30e5c
commit 3092ba5455

View File

@ -763,6 +763,18 @@ struct CILess
};
template <typename T>
void secureClear(T& str)
/// Securely clears a string's contents by first overwriting
/// the entire buffer (up to capacity) with zeroes, then
/// clearing the string.
{
str.resize(str.capacity());
std::fill(str.begin(), str.end(), typename T::value_type());
str.clear();
}
} // namespace Poco
#if defined(__clang__) && ((__clang_major__ > 3) || (__clang_major__ == 3 && __clang_minor__ >= 6))