secure_gate/macros/dynamic.rs
1// secure-gate/src/macros/dynamic_macros.rs
2
3/// Creates a type alias for a heap-allocated secure secret.
4///
5/// # Examples
6///
7/// Public alias:
8/// ```
9/// #[cfg(feature = "std")]
10/// {
11/// use secure_gate::dynamic_alias;
12/// dynamic_alias!(pub Password, String);
13/// let pw: Password = "hunter2".into();
14/// assert_eq!(pw.expose_secret(), "hunter2");
15/// # }
16/// ```
17///
18/// Private alias:
19/// ```
20/// #[cfg(feature = "std")]
21/// {
22/// use secure_gate::dynamic_alias;
23/// dynamic_alias!(SecretString, String); // No visibility modifier = private
24/// let secret = SecretString::new("hidden".to_string());
25/// # }
26/// ```
27#[macro_export]
28macro_rules! dynamic_alias {
29 ($vis:vis $name:ident, $inner:ty) => {
30 #[doc = concat!("Secure heap-allocated ", stringify!($inner))]
31 $vis type $name = $crate::Dynamic<$inner>;
32 };
33 ($name:ident, $inner:ty) => {
34 #[doc = concat!("Secure heap-allocated ", stringify!($inner))]
35 type $name = $crate::Dynamic<$inner>;
36 };
37}
38
39/// Creates a generic heap-allocated secure secret type alias.
40///
41/// # Examples
42///
43/// ```
44/// #[cfg(feature = "std")]
45/// {
46/// use secure_gate::dynamic_generic_alias;
47/// dynamic_generic_alias!(pub SecureVec, Vec<u8>, "Secure dynamic byte vector");
48/// let vec = SecureVec::new(vec![1, 2, 3]);
49/// assert_eq!(vec.len(), 3);
50/// # }
51/// ```
52#[macro_export]
53macro_rules! dynamic_generic_alias {
54 ($vis:vis $name:ident, $inner:ty, $doc:literal) => {
55 #[doc = $doc]
56 $vis type $name = $crate::Dynamic<$inner>;
57 };
58 ($vis:vis $name:ident, $inner:ty) => {
59 #[doc = concat!("Secure heap-allocated ", stringify!($inner))]
60 $vis type $name = $crate::Dynamic<$inner>;
61 };
62}