pub enum LockPolicy {
BestEffort,
Strict,
}Expand description
What a Locked constructor does when the operating system refuses to
lock the memory or, on Linux, to exclude it from core dumps.
The policy is process-wide and set at most once, with LockPolicy::set.
Until it is set, BestEffort applies.
§Which to choose
A refused lock loses exactly one property: under memory pressure the pages holding the secret may be written to swap, which is not wiped when the process exits. On a host with no swap there is nothing to lose. Everything else, including the wipe on drop and the exclusion from core dumps on Linux, still holds. A refused dump exclusion, which is rare and takes a seccomp filter to provoke, is treated the same way.
BestEffort is the default because a strict default fails in development
and CI, where swap exposure is irrelevant, and teaches people to turn it
off. A service that needs the guarantee sets Strict once at startup, or
checks Locked::locked on the values it cares about.
Variants§
BestEffort
Create the value anyway and record the refusal, readable from
Locked::lock_error. When more than one protection is refused,
the lock refusal is the one recorded.
Strict
Fail the constructor with the refusal. Where locking is unavailable
altogether (non-Unix targets, Miri, Kani) that is every constructor:
LockError::Unavailable is a refusal too.
Implementations§
Source§impl LockPolicy
impl LockPolicy
Sourcepub fn set(self) -> Result<(), LockPolicyError>
pub fn set(self) -> Result<(), LockPolicyError>
Set the process-wide policy. Succeeds at most once, or again with the same value; a different value after the first is an error carrying the policy in force.
use vitaminc::protected::LockPolicy;
// A test binary runs many tests in one process; set once, tolerate repeats.
let _ = LockPolicy::BestEffort.set();
assert_eq!(LockPolicy::current(), LockPolicy::BestEffort);Trait Implementations§
Source§impl Clone for LockPolicy
impl Clone for LockPolicy
Source§fn clone(&self) -> LockPolicy
fn clone(&self) -> LockPolicy
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more