c++ - Secure, password specific std::string that zeroes itself upon de-allocation -
i found relevant question @ [ 1 ] boost specific due age of post , c++11 having not been matured point otherwise, i'm looking secure std::string typedef of sort below zeroes upon de-allocation.
typedef std::basic_string<char, std::char_traits<char>, securestr<char>> string;
[ 1 ] - how 1 securely clear std::string?
would know of examples? code must not optimized away on compilation , such, compromise security of application. know can quite problem without use of apis o/s and/or compiler.
the accepted answer in question linked doesn't appear boost-specific; doesn't mention boost. it's custom allocator use std::basic_string
.
however, mentions depending on implementation of basic_string
, allocator may not invoked; basic_string
may have space store small strings internally without having separate allocation. instantiating basic_string
custom allocator not enough: need 0 memory of string object itself, in addition buffers may have allocated.
one way use unique_ptr
constructed custom deleter function. unique_ptr
doesn't deal allocators directly, allocate storage basic_string
using custom allocator, construct unique_ptr
deleter delegates custom allocator.
btw, you're looking @ zeroing memory when you're done it, thing concerned possibility sensitive data gets paged out disk. operating systems provide (non-portable) apis locking small amounts of data in ram won't paged out; might want take advantage of features in custom allocator.