diff options
Diffstat (limited to 'src/lib.rs')
| -rw-r--r-- | src/lib.rs | 29 |
1 files changed, 29 insertions, 0 deletions
| @@ -23,6 +23,35 @@ pub use view::*; | |||
| 23 | 23 | ||
| 24 | pub use ipnet; | 24 | pub use ipnet; |
| 25 | 25 | ||
| 26 | #[doc(hidden)] | ||
| 27 | pub 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] | ||
| 49 | macro_rules! key { | ||
| 50 | ($value:literal) => { | ||
| 51 | $crate::Key::new_unchecked_from($crate::__decode_wg_key_const($value)) | ||
| 52 | }; | ||
| 53 | } | ||
| 54 | |||
| 26 | pub type Result<T, E = Error> = std::result::Result<T, E>; | 55 | pub type Result<T, E = Error> = std::result::Result<T, E>; |
| 27 | 56 | ||
| 28 | #[derive(Debug)] | 57 | #[derive(Debug)] |
