Skip to main content

cliquenet/
noise.rs

1use std::{collections::HashMap, sync::LazyLock};
2
3use snow::params::NoiseParams;
4
5static NOISE_PARAMS: LazyLock<HashMap<Protocol, NoiseParams>> = LazyLock::new(|| {
6    HashMap::from_iter([
7        (
8            Protocol::IK_25519_AesGcm_Blake2s,
9            "Noise_IK_25519_AESGCM_BLAKE2s"
10                .parse()
11                .expect("valid noise params"),
12        ),
13        (
14            Protocol::IK_25519_ChaChaPoly_Blake2s,
15            "Noise_IK_25519_ChaChaPoly_BLAKE2s"
16                .parse()
17                .expect("valid noise params"),
18        ),
19    ])
20});
21
22/// Supported noise protocol names.
23///
24/// A protocol name contains the handshake pattern, DH, cipher, and
25/// hash function names. See https://noiseprotocol.org for details.
26#[derive(Debug, Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
27#[allow(non_camel_case_types)]
28#[non_exhaustive]
29pub enum Protocol {
30    IK_25519_AesGcm_Blake2s,
31    IK_25519_ChaChaPoly_Blake2s,
32}
33
34impl Protocol {
35    pub(crate) fn noise_params(self) -> NoiseParams {
36        NOISE_PARAMS
37            .get(&self)
38            .cloned()
39            .expect("All protocol names are in NOISE_PARAMS.")
40    }
41}