pub struct Fixed<T> { /* private fields */ }Expand description
Re-export of the Fixed type.
Implementations§
impl<const N: usize> Fixed<[u8; N]>
§Byte-array specific helpers
Source§impl<const N: usize> Fixed<[u8; N]>
impl<const N: usize> Fixed<[u8; N]>
Sourcepub fn from_random() -> Self
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]>
impl<const N: usize> Fixed<[u8; N]>
Sourcepub fn try_from_hex(s: &str) -> Result<Self, HexError>
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]>
impl<const N: usize> Fixed<[u8; N]>
Sourcepub fn try_from_base64url(s: &str) -> Result<Self, Base64Error>
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]>
impl<const N: usize> Fixed<[u8; N]>
Sourcepub fn try_from_bech32(s: &str) -> Result<Self, Bech32Error>
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 discardedSource§impl<const N: usize> Fixed<[u8; N]>
impl<const N: usize> Fixed<[u8; N]>
Sourcepub fn try_from_bech32m(s: &str) -> Result<Self, Bech32Error>
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]>
impl<const N: usize> Fixed<[u8; N]>
Sourcepub fn ct_eq(&self, other: &Self) -> bool
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.
impl<T: CloneableSecret> Clone for Fixed<T>
cloneable only.Source§impl<T> ConstantTimeEq for Fixed<T>where
T: ConstantTimeEq,
Available on crate feature ct-eq only.
impl<T> ConstantTimeEq for Fixed<T>where
T: ConstantTimeEq,
ct-eq only.Source§impl<T> ConstantTimeEqExt for Fixed<T>
Available on crate feature ct-eq-hash only.
impl<T> ConstantTimeEqExt for Fixed<T>
ct-eq-hash only.Source§fn ct_eq_hash(&self, other: &Self) -> bool
fn ct_eq_hash(&self, other: &Self) -> bool
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).
impl<'de, const N: usize> Deserialize<'de> for Fixed<[u8; N]>
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>,
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>where
D: Deserializer<'de>,
Source§impl<const N: usize, T> ExposeSecret for Fixed<[T; N]>
impl<const N: usize, T> ExposeSecret for Fixed<[T; N]>
Source§fn with_secret<F, R>(&self, f: F) -> R
fn with_secret<F, R>(&self, f: F) -> R
Source§fn expose_secret(&self) -> &[T; N]
fn expose_secret(&self) -> &[T; N]
Source§impl<T> Serialize for Fixed<T>where
T: SerializableSecret,
Available on crate feature serde-serialize only.
impl<T> Serialize for Fixed<T>where
T: SerializableSecret,
serde-serialize only.Source§impl<const N: usize> TryFrom<&[u8]> for Fixed<[u8; N]>
impl<const N: usize> TryFrom<&[u8]> for Fixed<[u8; N]>
Source§fn try_from(slice: &[u8]) -> Result<Self, Self::Error>
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());impl<T: Zeroize> ZeroizeOnDrop for Fixed<T>
zeroize only.Zeroize on drop integration