Struct t_rust_less_lib::memguard::SecretBytes
source · pub struct SecretBytes { /* private fields */ }
Expand description
Strictly memory protected bytes contain sensitive data.
This implementation borrows a lot of code and ideas from:
- https://crates.io/crates/memsec
- https://crates.io/crates/secrets
- https://download.libsodium.org/doc/memory_management
secrets
is not good enough because it relies on libsodium which breaks the desired
portability of this library (at least at the time of this writing).
memsec
is not
good enough because it focuses on protecting a generic type T
which size is known at
compile-time. In this library we are dealing with dynamic amounts of sensitive data and
there is no point in securing a Vec<u8>
via memsec
… all we would achieve is protecting
the pointer to sensitive data in unsecured space.
Implementations§
source§impl SecretBytes
impl SecretBytes
sourcepub fn from_secured(bytes: &[u8]) -> Self
pub fn from_secured(bytes: &[u8]) -> Self
Copy from slice of bytes.
This is not a regular From implementation because the caller has to ensure that the original bytes are zeroed out (or are already in some secured memspace. This different signature should be a reminder of that.
pub fn with_capacity(capacity: usize) -> SecretBytes
pub fn with_capacity_for_chars(capacity_for_chars: usize) -> SecretBytes
pub fn zeroed(size: usize) -> SecretBytes
pub fn random<T>(rng: &mut T, size: usize) -> SecretBytes
pub fn is_empty(&self) -> bool
pub fn len(&self) -> usize
pub fn capacity(&self) -> usize
pub fn borrow(&self) -> Ref<'_>
pub fn borrow_mut(&mut self) -> RefMut<'_>
pub fn locks(&self) -> isize
Trait Implementations§
source§impl Clone for SecretBytes
impl Clone for SecretBytes
source§impl Debug for SecretBytes
impl Debug for SecretBytes
source§impl<'de> Deserialize<'de> for SecretBytes
impl<'de> Deserialize<'de> for SecretBytes
source§fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>where
D: Deserializer<'de>,
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>where
D: Deserializer<'de>,
source§impl Drop for SecretBytes
impl Drop for SecretBytes
source§impl From<&mut [u8]> for SecretBytes
impl From<&mut [u8]> for SecretBytes
source§impl From<String> for SecretBytes
impl From<String> for SecretBytes
source§impl PartialEq for SecretBytes
impl PartialEq for SecretBytes
source§impl Serialize for SecretBytes
impl Serialize for SecretBytes
source§impl Zeroize for SecretBytes
impl Zeroize for SecretBytes
impl Eq for SecretBytes
impl Send for SecretBytes
impl Sync for SecretBytes
Auto Trait Implementations§
impl !Freeze for SecretBytes
impl RefUnwindSafe for SecretBytes
impl Unpin for SecretBytes
impl UnwindSafe for SecretBytes
Blanket Implementations§
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
source§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
source§fn into_any(self: Box<T>) -> Box<dyn Any>
fn into_any(self: Box<T>) -> Box<dyn Any>
Box<dyn Trait>
(where Trait: Downcast
) to Box<dyn Any>
. Box<dyn Any>
can
then be further downcast
into Box<ConcreteType>
where ConcreteType
implements Trait
.source§fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
Rc<Trait>
(where Trait: Downcast
) to Rc<Any>
. Rc<Any>
can then be
further downcast
into Rc<ConcreteType>
where ConcreteType
implements Trait
.source§fn as_any(&self) -> &(dyn Any + 'static)
fn as_any(&self) -> &(dyn Any + 'static)
&Trait
(where Trait: Downcast
) to &Any
. This is needed since Rust cannot
generate &Any
’s vtable from &Trait
’s.source§fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
&mut Trait
(where Trait: Downcast
) to &Any
. This is needed since Rust cannot
generate &mut Any
’s vtable from &mut Trait
’s.source§impl<T> DowncastSync for T
impl<T> DowncastSync for T
source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key
and return true
if they are equal.source§impl<T> IntoEither for T
impl<T> IntoEither for T
source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
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 moresource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
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