FixedNoClone

Struct FixedNoClone 

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

Non-cloneable stack-allocated secret wrapper.

This is a zero-cost newtype over Fixed<T> that deliberately omits Clone and Copy. Use this when you want to enforce single-ownership and prevent accidental duplication of secrets.

Converts from Fixed<T> via .no_clone().

§Examples

use secure_gate::{Fixed, FixedNoClone};
let secret = Fixed::new([1u8; 32]);
let no_clone: FixedNoClone<[u8; 32]> = secret.no_clone();
// no_clone cannot be cloned
assert_eq!(no_clone.expose_secret()[0], 1);

With zeroize:

use secure_gate::FixedNoClone;
let mut secret = FixedNoClone::new([1u8, 2, 3]);
drop(secret); // wiped on drop

Implementations§

Source§

impl<T> FixedNoClone<T>

Source

pub const fn new(value: T) -> Self

Wrap a value in a non-cloneable fixed secret.

§Example
use secure_gate::FixedNoClone;
let secret = FixedNoClone::new(42u32);
Source

pub const fn expose_secret(&self) -> &T

Expose the inner value for read-only access.

This is the only way to read the secret — loud and auditable.

§Example
use secure_gate::FixedNoClone;
let secret = FixedNoClone::new([42u8; 32]);
assert_eq!(secret.expose_secret()[0], 42);
Source

pub fn expose_secret_mut(&mut self) -> &mut T

Expose the inner value for mutable access.

This is the only way to mutate the secret — loud and auditable.

§Example
use secure_gate::FixedNoClone;
let mut secret = FixedNoClone::new([1u8, 2, 3]);
secret.expose_secret_mut()[0] = 99;
assert_eq!(secret.expose_secret()[0], 99);
Source§

impl<T: Zeroize> FixedNoClone<T>

Source

pub fn zeroize_now(&mut self)

Explicitly zeroize the secret immediately.

This is useful when you want to wipe memory before the value goes out of scope, or when you want to make the zeroization intent explicit in the code.

§Example
use secure_gate::FixedNoClone;
let mut key = FixedNoClone::new([42u8; 32]);
// ... use key ...
key.zeroize_now();  // Explicit wipe - makes intent clear

Trait Implementations§

Source§

impl<T> Debug for FixedNoClone<T>

Source§

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

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

impl<T: Zeroize> Zeroize for FixedNoClone<T>

Available on crate feature zeroize only.
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: Zeroize> ZeroizeOnDrop for FixedNoClone<T>

Available on crate feature zeroize only.

Auto Trait Implementations§

§

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

§

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

§

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

§

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

§

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

§

impl<T> UnwindSafe for FixedNoClone<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<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> 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, 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.