summaryrefslogtreecommitdiff
path: root/src/lib.rs
diff options
context:
space:
mode:
authordiogo464 <[email protected]>2026-02-17 11:41:02 +0000
committerdiogo464 <[email protected]>2026-02-17 11:41:02 +0000
commited0f17dea764fea93ea7c2b897fa4a9e31c9476e (patch)
treedd757fe08efbc863f7cac3c2e3288417ed550b93 /src/lib.rs
parent56ac8740b79e291eabe6427d722921533b3a9837 (diff)
add const key macro and internal base64 codec
Diffstat (limited to 'src/lib.rs')
-rw-r--r--src/lib.rs29
1 files changed, 29 insertions, 0 deletions
diff --git a/src/lib.rs b/src/lib.rs
index 8ba36eb..72fb58f 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -23,6 +23,35 @@ pub use view::*;
23 23
24pub use ipnet; 24pub use ipnet;
25 25
26#[doc(hidden)]
27pub const fn __decode_wg_key_const(
28 encoded: &str,
29) -> [u8; netlink_packet_wireguard::WireguardAttribute::WG_KEY_LEN] {
30 key::decode_wg_key_const(encoded)
31}
32
33/// Creates a [`Key`] from a canonical WireGuard base64 literal at compile time.
34///
35/// The literal must be exactly 44 characters of standard base64 and end with `=`.
36///
37/// ```
38/// use wireguard::{key, Key};
39///
40/// const PRIVATE_KEY: Key = key!("6F5rOtYE5A2KcXTKf9jdzWa9Y/kuV5gPS3LcKlxmOnY=");
41/// ```
42///
43/// ```compile_fail
44/// use wireguard::key;
45///
46/// const _BAD: wireguard::Key = key!("not-a-wireguard-key");
47/// ```
48#[macro_export]
49macro_rules! key {
50 ($value:literal) => {
51 $crate::Key::new_unchecked_from($crate::__decode_wg_key_const($value))
52 };
53}
54
26pub type Result<T, E = Error> = std::result::Result<T, E>; 55pub type Result<T, E = Error> = std::result::Result<T, E>;
27 56
28#[derive(Debug)] 57#[derive(Debug)]