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<Protected<T>>
impl<T> Protected<Protected<T>>
Sourcepub fn flatten(self) -> Protected<T>
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.
Trait Implementations§
Source§impl<T> Controlled for Protected<T>where
T: Zeroize,
impl<T> Controlled for Protected<T>where
T: Zeroize,
type Inner = T
Source§fn risky_unwrap(self) -> Self::Inner
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
fn init_from_inner(x: Self::Inner) -> Self
Source§fn risky_ref(&self) -> &T
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!
fn inner_mut(&mut self) -> &mut Self::Inner
Source§fn new(inner: Self::Inner) -> Selfwhere
Self: Sized,
fn new(inner: Self::Inner) -> Selfwhere
Self: Sized,
Initialize a new instance of the Controlled type from the inner value.
Source§fn generate<F>(f: F) -> Self
fn generate<F>(f: F) -> Self
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>
fn generate_ok<F, E>(f: F) -> Result<Self, E>
Generate a new Controlled type from a function that returns a
Result with the inner value. Read moreSource§fn map<B, F>(self, f: F) -> <Self as ReplaceT<B>>::Outputwhere
Self: Sized + ReplaceT<B>,
F: FnOnce(<Self as Controlled>::Inner) -> B,
<Self as ReplaceT<B>>::Output: Controlled<Inner = B>,
B: Zeroize,
fn map<B, F>(self, f: F) -> <Self as ReplaceT<B>>::Outputwhere
Self: Sized + ReplaceT<B>,
F: FnOnce(<Self as Controlled>::Inner) -> B,
<Self as ReplaceT<B>>::Output: Controlled<Inner = B>,
B: Zeroize,
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,
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 moreSource§fn zip<Other, Out, F>(self, b: Other, f: F) -> Protected<Out>
fn zip<Other, Out, F>(self, b: Other, f: F) -> Protected<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
fn zip_ref<'a, A, Other, Out, F>( self, other: &'a Other, f: F, ) -> <Self as ReplaceT<Out>>::Output
Like
zip but the second argument is a reference. Read moreSource§fn update<F>(&mut self, f: F)
fn update<F>(&mut self, f: F)
Similar to
map but using references to that the inner value is updated in place. Read moreSource§fn update_with<Other, F>(&mut self, other: Other, f: F)
fn update_with<Other, F>(&mut self, other: Other, f: F)
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)
fn update_with_ref<'a, A, F>(&mut self, other: ProtectedRef<'a, A>, f: F)
Like
update_with but the second argument is a reference. Read moreSource§fn iter<'a, I>(&'a self) -> impl Iterator<Item = Protected<I>>
fn iter<'a, I>(&'a self) -> impl Iterator<Item = Protected<I>>
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) -> Selfwhere
Self: Sized,
fn replace(&mut self, new: Self) -> Selfwhere
Self: Sized,
Replace the inner value with a new one.
The new value must be
Self. Read moreSource§fn risky_inner_mut(&mut self) -> &mut Self::Inner
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, A> Extend<A> for Protected<T>where
T: Extend<A>,
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>,
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)
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)
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, U> From<GenericArray<u8, U>> for Protected<[u8; N]>
impl<const N: usize, U> From<GenericArray<u8, U>> for Protected<[u8; N]>
Source§fn from(x: GenericArray<u8, U>) -> Self
fn from(x: GenericArray<u8, U>) -> 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.
impl<const N: usize, T> Index<Protected<usize>> for [T; N]
Allows the use a of a Paranoid usize to index an array.
impl<T> Acceptable<DefaultScope> for Protected<T>
impl<T> Copy for Protected<T>where
T: Copy,
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<'a, T> AsProtectedRef<'a, <T as Controlled>::Inner> for Twhere
T: Controlled,
impl<'a, T> AsProtectedRef<'a, <T as Controlled>::Inner> for Twhere
T: Controlled,
fn as_protected_ref(&'a self) -> ProtectedRef<'a, <T as Controlled>::Inner>
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more