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")]
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/// Re-export of the [`Dynamic`] type.
29pub use dynamic::Dynamic;
30/// Re-export of the [`Fixed`] type.
31pub use fixed::Fixed;
32
33/// Re-export of the [`CloneSafe`] trait.
34#[cfg(feature = "zeroize")]
35pub use cloneable::CloneSafe;
36
37/// Cloneable secret types (requires the `zeroize` feature).
38/// Provides wrappers that can be safely duplicated while maintaining security guarantees.
39#[cfg(feature = "zeroize")]
40pub mod cloneable;
41/// Re-exports of cloneable secret types: [`CloneableArray`], [`CloneableString`], [`CloneableVec`].
42#[cfg(feature = "zeroize")]
43pub use cloneable::{CloneableArray, CloneableString, CloneableVec};
44
45/// Type alias macros (always available).
46/// Convenient macros for creating custom secret wrapper types.
47mod macros;
48
49/// Available macros (exported globally for convenience):
50/// - `dynamic_alias!`: Create type aliases for heap-allocated secrets (`Dynamic<T>`).
51/// - `dynamic_generic_alias!`: Create generic heap-allocated secret aliases.
52/// - `fixed_alias!`: Create type aliases for fixed-size secrets (`Fixed<[u8; N]>`).
53/// - `fixed_generic_alias!`: Create generic fixed-size secret aliases.
54/// - `fixed_alias_random!`: Create type aliases for random-only fixed-size secrets (`FixedRandom<N>`, requires `rand` feature).
55/// Cryptographically secure random generation (requires the `rand` feature).
56/// Provides RNG-backed secret generation with freshness guarantees.
57#[cfg(feature = "rand")]
58pub mod random;
59
60/// Constant-time equality comparison (requires the `ct-eq` feature).
61/// Prevents timing attacks when comparing sensitive data.
62/// Provides the ConstantTimeEq trait for secure comparisons.
63#[cfg(feature = "ct-eq")]
64pub mod ct_eq;
65
66/// Encoding utilities for secrets (various encoding features available).
67/// Secure encoding/decoding with validation and zeroization.
68pub mod encoding;
69
70/// Re-exports for convenient access to feature-gated types.
71#[cfg(feature = "rand")]
72pub use random::{DynamicRandom, FixedRandom};
73
74/// Re-export of [`HexString`] for convenience when using hex encoding.
75#[cfg(feature = "encoding-hex")]
76pub use encoding::hex::HexString;
77
78/// Re-export of [`Base64String`] for convenience when using base64 encoding.
79#[cfg(feature = "encoding-base64")]
80pub use encoding::base64::Base64String;
81
82/// Re-export of [`Bech32String`] for convenience when using bech32 encoding.
83#[cfg(feature = "encoding-bech32")]
84pub use encoding::bech32::Bech32String;
85
86/// Re-export of [`Bech32EncodingError`] for convenience when using bech32 encoding.
87#[cfg(feature = "encoding-bech32")]
88pub use error::Bech32EncodingError;
89
90/// Re-export of [`SecureEncodingExt`] trait for convenient encoding extensions.
91#[cfg(any(
92 feature = "encoding-hex",
93 feature = "encoding-base64",
94 feature = "encoding-bech32"
95))]
96pub use crate::encoding::extensions::SecureEncodingExt;
97
98/// Re-export of the [`FromSliceError`] type.
99pub use error::FromSliceError;