Protected

Struct Protected 

Source
pub struct Protected<T>(/* private fields */);
Expand description

The most basic controlled type. It ensures inner types are Zeroize and implements Debug and Display safely (i.e. inner sensitive values are redacted).

Implementations§

Source§

impl<T> Protected<T>

Source

pub const fn new(x: T) -> Self
where T: Zeroize,

Create a new Protected from an inner value.

Source§

impl<T> Protected<Protected<T>>

Source

pub fn flatten(self) -> Protected<T>

Flatten a Protected of Protected into a single Protected. Similar to Option::flatten.

use vitaminc_protected::{Controlled, Protected};
let x = Protected::new(Protected::new([0u8; 32]));
let y = x.flatten();
assert_eq!(y.risky_unwrap(), [0u8; 32]);

Like Option, flattening only removes one level of nesting at a time.

Source§

impl<T> Protected<Option<T>>

Source

pub fn transpose(self) -> Option<Protected<T>>

Transpose a Protected of Option into an Option of Protected. Similar to Option::transpose.

use vitaminc_protected::Protected;
let x = Protected::new(Some([0u8; 32]));
let y = x.transpose();
assert!(y.is_some())

Trait Implementations§

Source§

impl<T> BitXor for Protected<T>
where T: BitXor + Zeroize, <T as BitXor>::Output: Zeroize,

Source§

type Output = Protected<<T as BitXor>::Output>

The resulting type after applying the ^ operator.
Source§

fn bitxor(self, rhs: Self) -> Self::Output

Performs the ^ operation. Read more
Source§

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

Source§

fn clone(&self) -> Self

Returns a duplicate 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<T> Controlled for Protected<T>
where T: Zeroize,

Source§

type Inner = T

Source§

fn risky_unwrap(self) -> Self::Inner

Unwraps the inner value of the Controlled type. This is a risky operation because it consumes the Controlled type and returns the inner value negating the protections that the Controlled type provides. Read more
Source§

fn init_from_inner(x: Self::Inner) -> Self

Source§

fn risky_ref(&self) -> &T

Provides a reference to the inner value. This is a risky operation because it bypasses the protections that the Controlled type provides. Use with caution!
Source§

fn inner_mut(&mut self) -> &mut Self::Inner

Source§

fn new(inner: Self::Inner) -> Self
where Self: Sized,

Initialize a new instance of the Controlled type from the inner value.
Source§

fn generate<F>(f: F) -> Self
where Self: Sized, F: FnOnce() -> Self::Inner,

Generate a new instance of the Controlled type from a function that returns the inner value. Read more
Source§

fn generate_ok<F, E>(f: F) -> Result<Self, E>
where Self: Sized, F: FnOnce() -> Result<Self::Inner, E>,

Generate a new Controlled type from a function that returns a Result with the inner value. Read more
Source§

fn map<B, F>(self, f: F) -> <Self as ReplaceT<B>>::Output
where Self: Sized + ReplaceT<B>, F: FnOnce(<Self as Controlled>::Inner) -> B, <Self as ReplaceT<B>>::Output: Controlled<Inner = B>, B: Zeroize,

Map the inner value of this Controlled type. Conceptually similar to Option::map`. Read more
Source§

fn map_ok<B, F, E>(self, f: F) -> Result<<Self as ReplaceT<B>>::Output, E>
where Self: Sized + ReplaceT<B>, F: FnOnce(<Self as Controlled>::Inner) -> Result<B, E>, <Self as ReplaceT<B>>::Output: Controlled<Inner = B>, B: Zeroize,

Similar to map but the closure returns a Result with the new inner value. The result is a Result with the new Controlled type. Read more
Source§

fn zip<Other, Out, F>(self, b: Other, f: F) -> Protected<Out>
where Self: Sized, Other: Controlled, Out: Zeroize, F: FnOnce(Self::Inner, Other::Inner) -> Out,

Zip two Controlled values of the same type together with a function that combines them. Read more
Source§

fn zip_ref<'a, A, Other, Out, F>( self, other: &'a Other, f: F, ) -> <Self as ReplaceT<Out>>::Output
where A: ?Sized + 'a, Self: Sized + ReplaceT<Out>, <Self as ReplaceT<Out>>::Output: Controlled<Inner = Out>, Other: AsProtectedRef<'a, A>, Out: Zeroize, F: FnOnce(Self::Inner, &A) -> Out,

Like zip but the second argument is a reference. Read more
Source§

fn update<F>(&mut self, f: F)
where F: FnMut(&mut Self::Inner),

Similar to map but using references to that the inner value is updated in place. Read more
Source§

fn update_with<Other, F>(&mut self, other: Other, f: F)
where F: FnMut(&mut Self::Inner, Other::Inner), Other: Controlled,

Update the inner value with another Controlled value. The inner value of the second argument is passed to the closure. Read more
Source§

fn update_with_ref<'a, A, F>(&mut self, other: ProtectedRef<'a, A>, f: F)
where A: ?Sized + 'a, F: FnMut(&mut Self::Inner, &A),

Like update_with but the second argument is a reference. Read more
Source§

fn iter<'a, I>(&'a self) -> impl Iterator<Item = Protected<I>>
where <Self as Controlled>::Inner: AsRef<[I]>, I: Copy + 'a,

Iterate over the inner value and wrap each element in a Protected. I must be Copy because Protected always takes ownership of the inner value.
Source§

fn replace(&mut self, new: Self) -> Self
where Self: Sized,

Replace the inner value with a new one. The new value must be Self. Read more
Source§

fn risky_inner_mut(&mut self) -> &mut Self::Inner

Provides a mutable reference to the inner value. This is a risky operation because it bypasses the protections that the Controlled type provides. Use with caution!
Source§

impl<T> Debug for Protected<T>

Source§

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

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

impl<T, A> Extend<A> for Protected<T>
where T: Extend<A>,

Source§

fn extend<I>(&mut self, iter: I)
where I: IntoIterator<Item = A>,

Extends a collection with the contents of an iterator. Read more
Source§

fn extend_one(&mut self, item: A)

🔬This is a nightly-only experimental API. (extend_one)
Extends a collection with exactly one element.
Source§

fn extend_reserve(&mut self, additional: usize)

🔬This is a nightly-only experimental API. (extend_one)
Reserves capacity in a collection for the given number of additional elements. Read more
Source§

impl<const N: usize> From<[char; N]> for Protected<String>

Source§

fn from(x: [char; N]) -> Self

Converts to this type from the input type.
Source§

impl<const N: usize, U> From<GenericArray<u8, U>> for Protected<[u8; N]>
where U: ArrayLength<u8>, [u8; N]: From<GenericArray<u8, U>>,

Source§

fn from(x: GenericArray<u8, U>) -> Self

Converts to this type from the input type.
Source§

impl<T: Zeroize> From<T> for Protected<T>

Source§

fn from(x: T) -> Self

Converts to this type from the input type.
Source§

impl<const N: usize, T> Index<Protected<usize>> for [T; N]

Allows the use a of a Paranoid usize to index an array.

Source§

type Output = T

The returned type after indexing.
Source§

fn index(&self, index: Protected<usize>) -> &Self::Output

Performs the indexing (container[index]) operation. Read more
Source§

impl<const N: usize, T> IndexMut<Protected<usize>> for [T; N]

Source§

fn index_mut(&mut self, index: Protected<usize>) -> &mut Self::Output

Performs the mutable indexing (container[index]) operation. Read more
Source§

impl<T, K> ReplaceT<K> for Protected<T>

Source§

impl<T> Zeroed for Protected<T>
where T: Zeroed,

Source§

fn zeroed() -> Self

Source§

impl<T> Zeroize for Protected<T>
where T: Zeroize,

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<T> Acceptable<DefaultScope> for Protected<T>

Source§

impl<T> Copy for Protected<T>
where T: Copy,

Source§

impl<T: Zeroize> ZeroizeOnDrop for Protected<T>

Auto Trait Implementations§

§

impl<T> Freeze for Protected<T>
where T: Freeze,

§

impl<T> RefUnwindSafe for Protected<T>
where T: RefUnwindSafe,

§

impl<T> Send for Protected<T>
where T: Send,

§

impl<T> Sync for Protected<T>
where T: Sync,

§

impl<T> Unpin for Protected<T>
where T: Unpin,

§

impl<T> UnwindSafe for Protected<T>
where T: 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<'a, T> AsProtectedRef<'a, <T as Controlled>::Inner> for T
where T: Controlled,

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<'de, T> SafeDeserialize<'de> for T
where <T as Controlled>::Inner: SafeDeserialize<'de>, T: Controlled,

Source§

fn safe_deserialize<S>( deserializer: S, ) -> Result<T, <S as Deserializer<'de>>::Error>
where S: Deserializer<'de>,

Source§

impl<T> SafeSerialize for T

Source§

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

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

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.