secure_gate/lib.rs
1// ==========================================================================
2// src/lib.rs
3// ==========================================================================
4
5// Allow unsafe_code when encoding or zeroize is enabled (encoding needs it for hex validation)
6#![cfg_attr(
7 not(any(
8 feature = "zeroize",
9 any(feature = "encoding-hex", feature = "encoding-base64")
10 )),
11 forbid(unsafe_code)
12)]
13#![doc = include_str!("../README.md")]
14
15extern crate alloc;
16
17/// Core secret wrapper types - always available with zero dependencies.
18/// These provide the fundamental secure storage abstractions.
19mod dynamic;
20mod fixed;
21
22pub use dynamic::Dynamic;
23pub use fixed::Fixed;
24
25/// Cloneable secret types - requires "zeroize" feature.
26/// Provides wrappers that can be safely duplicated while maintaining security guarantees.
27#[cfg(feature = "zeroize")]
28pub use cloneable::CloneableSecretMarker;
29#[cfg(feature = "zeroize")]
30pub mod cloneable;
31#[cfg(feature = "zeroize")]
32pub use cloneable::{CloneableArray, CloneableString, CloneableVec};
33
34/// Type alias macros - always available.
35/// Convenient macros for creating custom secret wrapper types.
36mod macros;
37
38/// Cryptographically secure random generation - requires "rand" feature.
39/// Provides RNG-backed secret generation with freshness guarantees.
40#[cfg(feature = "rand")]
41pub mod random;
42
43/// Constant-time equality comparison - requires "ct-eq" feature.
44/// Prevents timing attacks when comparing sensitive data.
45/// Provides the ConstantTimeEq trait for secure comparisons.
46#[cfg(feature = "ct-eq")]
47pub mod ct_eq;
48
49/// Encoding utilities for secrets - various encoding features available.
50/// Secure encoding/decoding with validation and zeroization.
51pub mod encoding;
52
53/// Re-exports for convenient access to feature-gated types.
54#[cfg(feature = "rand")]
55pub use random::{DynamicRng, FixedRng};
56
57#[cfg(feature = "encoding-hex")]
58pub use encoding::hex::HexString;
59
60#[cfg(feature = "encoding-base64")]
61pub use encoding::base64::Base64String;
62
63#[cfg(feature = "encoding-bech32")]
64pub use encoding::bech32::Bech32String;
65
66#[cfg(any(feature = "encoding-hex", feature = "encoding-base64"))]
67pub use crate::encoding::extensions::SecureEncodingExt;
68
69pub use fixed::FromSliceError;