sheave_core/handshake/
encryption_algorithm.rs

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
/// Representation of first 1 byte in handshake.
///
/// Variants correspond to respectively following numbers: 
///
/// |Pattern|Number|
/// | :- | :- |
/// |`NotEncrypted` (Default)|`3`|
/// |`DiffieHellman`|`6`|
/// |`Xtea`|`8`|
/// |`Blowfish`|`9`|
/// |`Other`|other numbers|
///
/// Because of the design policy, the variant to be used actually will only be `NotEncrypted`.
/// Other variants are prepared to keep their meaning of known numbers.
#[repr(u8)]
#[derive(Debug, Clone, Copy, Default, PartialEq, Eq)]
pub enum EncryptionAlgorithm {
    #[default]
    NotEncrypted = 3,
    DiffieHellman = 6,
    Xtea = 8,
    Blowfish = 9,
    Other = 0xff
}

impl From<u8> for EncryptionAlgorithm {
    fn from(encryption_algorithm: u8) -> Self {
        use EncryptionAlgorithm::*;

        match encryption_algorithm {
            3 => NotEncrypted,
            6 => DiffieHellman,
            8 => Xtea,
            9 => Blowfish,
            _ => Other
        }
    }
}

impl From<EncryptionAlgorithm> for u8 {
    fn from(encryption_algorithm: EncryptionAlgorithm) -> Self {
        encryption_algorithm as u8
    }
}