secure_gate/
lib.rs

1// Allow unsafe_code when encoding or zeroize is enabled (encoding needs it for hex validation)
2#![cfg_attr(
3    not(any(
4        feature = "zeroize",
5        any(feature = "encoding-hex", feature = "encoding-base64")
6    )),
7    forbid(unsafe_code)
8)]
9// #![doc = include_str!("../README.md")]  // uncomment for doctest runs
10//! Zero-cost secure wrappers for secrets — [`Fixed<T>`] for stack, [`Dynamic<T>`] for heap.
11//!
12//! This crate provides explicit wrappers for sensitive data like [`CloneableArray`], [`CloneableString`], and [`CloneSafe`], ensuring no accidental exposure.
13//! See [README.md](https://github.com/Slurp9187/secure-gate) for usage and examples.
14
15extern crate alloc;
16
17/// Dynamic secret wrapper types - always available with zero dependencies.
18/// These provide fundamental secure storage abstractions for dynamic data.
19mod dynamic;
20
21/// Fixed-size secret wrapper types - always available with zero dependencies.
22/// These provide fundamental secure storage abstractions for fixed-size data.
23mod fixed;
24
25/// Centralized error types - always available.
26mod error;
27
28/// Core traits for wrapper polymorphism - always available.
29mod traits;
30
31/// Re-export of the [`Dynamic`] type.
32pub use dynamic::Dynamic;
33/// Re-export of the [`Fixed`] type.
34pub use fixed::Fixed;
35
36/// Re-export of the traits.
37pub use traits::{ExposeSecret, ExposeSecretMut};
38
39/// Re-export of SecureRandom (requires `rand` feature).
40#[cfg(feature = "rand")]
41pub use traits::SecureRandom;
42
43/// Re-export of the [`CloneSafe`] trait.
44#[cfg(feature = "zeroize")]
45pub use traits::CloneSafe;
46
47/// Re-export of the [`ConstantTimeEq`] trait.
48#[cfg(feature = "ct-eq")]
49pub use traits::ConstantTimeEq;
50
51/// Cloneable secret types (requires the `zeroize` feature).
52/// Provides wrappers that can be safely duplicated while maintaining security guarantees.
53#[cfg(feature = "zeroize")]
54pub mod cloneable;
55/// Re-exports of cloneable secret types: [`CloneableArray`], [`CloneableString`], [`CloneableVec`].
56#[cfg(feature = "zeroize")]
57pub use cloneable::{CloneableArray, CloneableString, CloneableVec};
58
59/// Type alias macros (always available).
60/// Convenient macros for creating custom secret wrapper types.
61mod macros;
62
63/// Available macros (exported globally for convenience):
64/// - `dynamic_alias!`: Create type aliases for heap-allocated secrets (`Dynamic<T>`).
65/// - `dynamic_generic_alias!`: Create generic heap-allocated secret aliases.
66/// - `fixed_alias!`: Create type aliases for fixed-size secrets (`Fixed<[u8; N]>`).
67/// - `fixed_generic_alias!`: Create generic fixed-size secret aliases.
68/// - `fixed_alias_random!`: Create type aliases for random-only fixed-size secrets (`FixedRandom<N>`, requires `rand` feature).
69/// Cryptographically secure random generation (requires the `rand` feature).
70/// Provides RNG-backed secret generation with freshness guarantees.
71#[cfg(feature = "rand")]
72pub mod random;
73
74/// Encoding utilities for secrets (various encoding features available).
75/// Secure encoding/decoding with validation and zeroization.
76pub mod encoding;
77
78/// Re-exports for convenient access to feature-gated types.
79#[cfg(feature = "rand")]
80pub use random::{DynamicRandom, FixedRandom};
81
82/// Re-export of [`HexString`] for convenience when using hex encoding.
83#[cfg(feature = "encoding-hex")]
84pub use encoding::hex::HexString;
85
86/// Re-export of [`Base64String`] for convenience when using base64 encoding.
87#[cfg(feature = "encoding-base64")]
88pub use encoding::base64::Base64String;
89
90/// Re-export of [`Bech32String`] for convenience when using bech32 encoding.
91#[cfg(feature = "encoding-bech32")]
92pub use encoding::bech32::Bech32String;
93
94/// Re-export of [`Bech32EncodingError`] for convenience when using bech32 encoding.
95#[cfg(feature = "encoding-bech32")]
96pub use error::Bech32EncodingError;
97
98/// Re-export of [`SecureEncoding`] trait for convenient encoding extensions.
99/// Re-export of the [`SecureEncoding`] trait.
100#[cfg(any(
101    feature = "encoding-hex",
102    feature = "encoding-base64",
103    feature = "encoding-bech32"
104))]
105pub use traits::SecureEncoding;
106
107/// Re-export of the [`FromSliceError`] type.
108pub use error::FromSliceError;