Skip to main content

LockPolicy

Enum LockPolicy 

Source
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

Source

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);
Source

pub fn current() -> Self

The policy in force: the one set with set, or BestEffort.

Trait Implementations§

Source§

impl Clone for LockPolicy

Source§

fn clone(&self) -> LockPolicy

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Copy for LockPolicy

Source§

impl Debug for LockPolicy

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for LockPolicy

Source§

fn default() -> LockPolicy

Returns the “default value” for a type. Read more
Source§

impl Eq for LockPolicy

Source§

impl PartialEq for LockPolicy

Source§

fn eq(&self, other: &LockPolicy) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl StructuralPartialEq for LockPolicy

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.