Struct bitwarden_crypto::Sensitive

source ·
pub struct Sensitive<V: Zeroize> { /* private fields */ }
Expand description

Wrapper for sensitive values which makes a best effort to enforce zeroization of the inner value on drop. The inner value exposes a Sensitive::expose method which returns a reference to the inner value. Care must be taken to avoid accidentally exposing the inner value through copying or cloning.

Internally Sensitive contains a Box which ensures the value is placed on the heap. It implements the Drop trait which calls zeroize on the inner value.

Implementations§

source§

impl<V: Zeroize> Sensitive<V>

source

pub fn new(value: Box<V>) -> Self

Create a new Sensitive value. In an attempt to avoid accidentally placing this on the stack it only accepts a Box value. The rust compiler should be able to optimize away the initial stack allocation presuming the value is not used before being boxed.

source

pub fn expose(&self) -> &V

Expose the inner value. By exposing the inner value, you take responsibility for ensuring that any copy of the value is zeroized.

source

pub fn expose_mut(&mut self) -> &mut V

Expose the inner value mutable. By exposing the inner value, you take responsibility for ensuring that any copy of the value is zeroized.

source§

impl Sensitive<String>

source

pub fn decode_base64<T: Engine>( self, engine: T ) -> Result<SensitiveVec, CryptoError>

source§

impl Sensitive<Vec<u8>>

source

pub fn encode_base64<T: Engine>(self, engine: T) -> SensitiveString

source§

impl<V: Zeroize> Sensitive<V>

source

pub fn test<T: ?Sized>(value: &'static T) -> Self
where &'static T: Into<V>,

Trait Implementations§

source§

impl<V: Clone + Zeroize> Clone for Sensitive<V>

source§

fn clone(&self) -> Sensitive<V>

Returns a copy of the value. Read more
1.0.0 · source§

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

Performs copy-assignment from source. Read more
source§

impl<V: Zeroize + Serialize> Debug for Sensitive<V>

source§

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

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

impl<V: Zeroize + Default> Default for Sensitive<V>

source§

fn default() -> Self

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

impl<'de, V: Zeroize + Deserialize<'de>> Deserialize<'de> for Sensitive<V>

source§

fn deserialize<D: Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error>

Deserialize this value from the given Serde deserializer. Read more
source§

impl<V: Zeroize> Drop for Sensitive<V>

source§

fn drop(&mut self)

Executes the destructor for this type. Read more
source§

impl<const N: usize> From<Sensitive<[u8; N]>> for SensitiveVec

Helper to convert a Sensitive<[u8, N]> to a SensitiveVec.

source§

fn from(sensitive: Sensitive<[u8; N]>) -> Self

Converts to this type from the input type.
source§

impl From<Sensitive<String>> for SensitiveVec

source§

fn from(s: SensitiveString) -> Self

Converts to this type from the input type.
source§

impl<V: Zeroize + JsonSchema> JsonSchema for Sensitive<V>

Transparently expose the inner value for serialization

source§

fn schema_name() -> String

The name of the generated JSON Schema. Read more
source§

fn schema_id() -> Cow<'static, str>

Returns a string that uniquely identifies the schema produced by this type. Read more
source§

fn json_schema(gen: &mut SchemaGenerator) -> Schema

Generates a JSON Schema for this type. Read more
source§

fn is_referenceable() -> bool

Whether JSON Schemas generated for this type should be re-used where possible using the $ref keyword. Read more
source§

impl<V: PartialEq + Zeroize> PartialEq for Sensitive<V>

source§

fn eq(&self, other: &Sensitive<V>) -> bool

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

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

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl<V: Zeroize + Serialize> Serialize for Sensitive<V>

Unfortunately once we serialize a SensitiveString we can’t control the future memory.

source§

fn serialize<S: Serializer>(&self, serializer: S) -> Result<S::Ok, S::Error>

Serialize this value into the given Serde serializer. Read more
source§

impl TryFrom<Sensitive<String>> for DeviceKey

§

type Error = CryptoError

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

fn try_from(value: SensitiveString) -> Result<Self, Self::Error>

Performs the conversion.
source§

impl TryFrom<Sensitive<String>> for SymmetricCryptoKey

§

type Error = CryptoError

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

fn try_from(value: SensitiveString) -> Result<Self, Self::Error>

Performs the conversion.
source§

impl TryFrom<Sensitive<Vec<u8>>> for SensitiveString

Helper to convert a Sensitive<Vec<u8>> to a Sensitive<String>, care is taken to ensure any intermediate copies are zeroed to avoid leaking sensitive data.

§

type Error = CryptoError

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

fn try_from(v: SensitiveVec) -> Result<Self, CryptoError>

Performs the conversion.
source§

impl TryFrom<Sensitive<Vec<u8>>> for SymmetricCryptoKey

§

type Error = CryptoError

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

fn try_from(value: SensitiveVec) -> Result<Self, Self::Error>

Performs the conversion.
source§

impl<V: Zeroize> Zeroize for Sensitive<V>

source§

fn zeroize(&mut self)

Zero out this object from memory using Rust intrinsics which ensure the zeroization operation is not “optimized away” by the compiler.
source§

impl<V: Zeroize> StructuralPartialEq for Sensitive<V>

Auto Trait Implementations§

§

impl<V> Freeze for Sensitive<V>

§

impl<V> RefUnwindSafe for Sensitive<V>
where V: RefUnwindSafe,

§

impl<V> Send for Sensitive<V>
where V: Send,

§

impl<V> Sync for Sensitive<V>
where V: Sync,

§

impl<V> Unpin for Sensitive<V>

§

impl<V> UnwindSafe for Sensitive<V>
where V: UnwindSafe,

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> DynClone for T
where T: Clone,

source§

fn __clone_box(&self, _: Private) -> *mut ()

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> IntoEither for T

source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
source§

impl<T> Pointable for T

source§

const ALIGN: usize = _

The alignment of pointer.
§

type Init = T

The type for initializers.
source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
source§

impl<T> Same for T

§

type Output = T

Should always be Self
source§

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

§

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>,

§

type Error = Infallible

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

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

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

§

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.
source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

source§

fn vzip(self) -> V

source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,