I have some code in which I want to make absolutely sure that a moved-from std::vector
will not leave secret data around (think about crypto key management). In my class' move constructor, I do something like:
X(X&& rhs): secret_vector{std::move(rhs.secret_vector)}{
rhs.secret_vector.resize(N);
safe_zero(rhs.secret_vector); // zero out all elements
rhs.secret_vector.resize(0);
}
As you can see, I re-use the secret vector after moving from it. I looked at
but it was not absolutely clear that I can do this (I did not understand what "pre-conditions" really are).
My question is: can I resize a moved-from std::vector, perform some operation on it, then resize it back to zero?