Skip to main content

Fixed

Struct Fixed 

Source
pub struct Fixed<T> { /* private fields */ }
Expand description

Re-export of the Fixed type.

Implementations§

Source§

impl<T> Fixed<T>

Source

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

Wrap a value in a Fixed secret.

This is zero-cost and const-friendly.

§Example
use secure_gate::Fixed;
const SECRET: Fixed<u32> = Fixed::new(42);
Source§

impl<const N: usize> Fixed<[u8; N]>

This impl block contains no items.

§Byte-array specific helpers

Source§

impl<const N: usize> Fixed<[u8; N]>

Source

pub fn from_random() -> Self

Generate a secure random instance (panics on failure).

Fill with fresh random bytes using the System RNG. Panics on RNG failure for fail-fast crypto code. Guarantees secure entropy from system sources.

§Example
use secure_gate::{Fixed, ExposeSecret};
let random: Fixed<[u8; 32]> = Fixed::from_random();
assert_eq!(random.len(), 32);
Source§

impl<const N: usize> Fixed<[u8; N]>

Source

pub fn try_from_hex(s: &str) -> Result<Self, HexError>

Decode a hex string into a Fixed secret.

The decoded bytes must exactly match the array length N.

§Example
use secure_gate::{Fixed, ExposeSecret};
let hex_string = "424344"; // 3 bytes
let secret: Fixed<[u8; 3]> = Fixed::try_from_hex(hex_string).unwrap();
assert_eq!(secret.expose_secret()[0], 0x42);
Source§

impl<const N: usize> Fixed<[u8; N]>

Source

pub fn try_from_base64url(s: &str) -> Result<Self, Base64Error>

Decode a base64url string into a Fixed secret.

The decoded bytes must exactly match the array length N.

§Example
use secure_gate::{Fixed, ExposeSecret};
let b64_string = "QkNE"; // 3 bytes
let secret: Fixed<[u8; 3]> = Fixed::try_from_base64url(b64_string).unwrap();
assert_eq!(secret.expose_secret()[0], 0x42);
Source§

impl<const N: usize> Fixed<[u8; N]>

Source

pub fn try_from_bech32(s: &str) -> Result<Self, Bech32Error>

Decode a bech32 string into a Fixed secret, discarding the HRP.

The decoded bytes must exactly match the array length N.

§Example
use secure_gate::{Fixed, ExposeSecret, ToBech32};
let original = Fixed::new([1, 2, 3, 4]);
let bech32_string = original.with_secret(|s| s.to_bech32("test"));
let decoded = Fixed::<[u8; 4]>::try_from_bech32(&bech32_string).unwrap();
// HRP "test" is discarded
Source§

impl<const N: usize> Fixed<[u8; N]>

Source

pub fn try_from_bech32m(s: &str) -> Result<Self, Bech32Error>

Decode a bech32m string into a Fixed secret, discarding the HRP.

The decoded bytes must exactly match the array length N.

§Example
use secure_gate::Fixed;
// Note: Bech32m strings must be valid Bech32m format
let bech32m_string = "abc1qpzry9x8gf2tvdw0s3jn54khce6mua7lmqqqxw"; // 32 bytes
let secret: Result<Fixed<[u8; 32]>, _> = Fixed::try_from_bech32m(bech32m_string);
// Returns Result<Fixed<[u8; 32]>, Bech32Error>
Source§

impl<const N: usize> Fixed<[u8; N]>

Source

pub fn ct_eq(&self, other: &Self) -> bool

Constant-time equality comparison.

This is the only safe way to compare two fixed-size secrets. Available only when the ct-eq feature is enabled.

§Example
use secure_gate::Fixed;
let a = Fixed::new([1u8; 32]);
let b = Fixed::new([1u8; 32]);
assert!(a.ct_eq(&b));

Trait Implementations§

Source§

impl<T: CloneableSecret> Clone for Fixed<T>

Available on crate feature cloneable only.
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> ConstantTimeEq for Fixed<T>
where T: ConstantTimeEq,

Available on crate feature ct-eq only.
Source§

fn ct_eq(&self, other: &Self) -> bool

Compare two values in constant time. Read more
Source§

impl<T> ConstantTimeEqExt for Fixed<T>
where T: AsRef<[u8]> + ConstantTimeEq,

Available on crate feature ct-eq-hash only.
Source§

fn len(&self) -> usize

Get the length of the secret data in bytes. Read more
Source§

fn ct_eq_hash(&self, other: &Self) -> bool

Force BLAKE3 digest comparison (constant-time on 32-byte output). Read more
Source§

fn ct_eq_auto(&self, other: &Self, threshold_bytes: Option<usize>) -> bool

Recommended hybrid constant-time equality check. Read more
Source§

impl<T> Debug for Fixed<T>

Source§

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

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

impl<'de, const N: usize> Deserialize<'de> for Fixed<[u8; N]>

Available on crate feature serde-deserialize only.

Custom serde deserialization for byte arrays (direct to sequence).

Source§

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

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

impl<const N: usize, T> ExposeSecret for Fixed<[T; N]>

Source§

type Inner = [T; N]

The inner secret type being exposed. Read more
Source§

fn with_secret<F, R>(&self, f: F) -> R
where F: FnOnce(&[T; N]) -> R,

Provide scoped read-only access to the secret. Read more
Source§

fn expose_secret(&self) -> &[T; N]

Expose the secret for read-only access. Read more
Source§

fn len(&self) -> usize

Returns the length of the secret.
Source§

fn is_empty(&self) -> bool

Returns true if the secret is empty.
Source§

impl<const N: usize, T> ExposeSecretMut for Fixed<[T; N]>

Source§

fn with_secret_mut<F, R>(&mut self, f: F) -> R
where F: FnOnce(&mut [T; N]) -> R,

Provide scoped mutable access to the secret. Read more
Source§

fn expose_secret_mut(&mut self) -> &mut [T; N]

Expose the secret for mutable access. Read more
Source§

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

Source§

fn from(arr: [u8; N]) -> Self

Wrap a raw byte array in a Fixed secret.

Zero-cost conversion.

§Example
use secure_gate::Fixed;
let key: Fixed<[u8; 4]> = [1, 2, 3, 4].into();
Source§

impl<T> Serialize for Fixed<T>

Available on crate feature serde-serialize only.
Source§

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

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

impl<const N: usize> TryFrom<&[u8]> for Fixed<[u8; N]>

Source§

fn try_from(slice: &[u8]) -> Result<Self, Self::Error>

Attempt to create a Fixed from a byte slice. In debug builds, panics with detailed information on length mismatch to aid development. In release builds, returns an error on length mismatch to prevent information leaks.

§Example
use secure_gate::Fixed;
let slice: &[u8] = &[1u8, 2, 3, 4];
let key: Result<Fixed<[u8; 4]>, _> = slice.try_into();
assert!(key.is_ok());
Source§

type Error = FromSliceError

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

impl<T: Zeroize> Zeroize for Fixed<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 Fixed<T>

Available on crate feature zeroize only.

Zeroize on drop integration

Auto Trait Implementations§

§

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

§

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

§

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

§

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

§

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

§

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