secure_gate/
macros.rs

1// src/macros.rs
2//! Ergonomic secret-handling macros.
3
4/// Create a secret — works for fixed-size arrays and heap types.
5#[macro_export]
6macro_rules! secure {
7    ([u8; $N:literal], $expr:expr $(,)?) => {
8        $crate::Fixed::new($expr)
9    };
10    ($ty:ty, $expr:expr $(,)?) => {
11        $crate::Fixed::<$ty>::new($expr)
12    };
13    (String, $expr:expr $(,)?) => {
14        $crate::Dynamic::new($expr)
15    };
16    (Vec<u8>, $expr:expr $(,)?) => {
17        $crate::Dynamic::new($expr)
18    };
19    (heap $ty:ty, $expr:expr $(,)?) => {
20        $crate::Dynamic::new($expr)
21    };
22}
23
24/// Create a zeroizing secret (auto-wiped on drop)
25#[macro_export]
26macro_rules! secure_zeroizing {
27    ($ty:ty, $expr:expr $(,)?) => {
28        $crate::FixedZeroizing::new($expr)
29    };
30    (heap $ty:ty, $expr:expr $(,)?) => {
31        $crate::DynamicZeroizing::new($expr)
32    };
33}
34
35/// Define a fixed-size secret alias with beautiful constructor syntax
36///
37/// The alias gets useful methods automatically because `Fixed` implements them
38/// for all array sizes (see `src/fixed.rs`).
39#[macro_export]
40macro_rules! fixed_alias {
41    ($name:ident, $size:literal) => {
42        /// Fixed-size secret of exactly `$size` bytes.
43        pub type $name = $crate::Fixed<[u8; $size]>;
44
45        // Only the type alias — no impls!
46        // All methods come from the generic impls in src/fixed.rs
47    };
48}
49
50/// Define a dynamic (heap) secret alias.
51#[macro_export]
52macro_rules! dynamic_alias {
53    ($name:ident, $ty:ty) => {
54        pub type $name = $crate::Dynamic<$ty>;
55    };
56}