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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
pub(crate) mod encryption;
pub(crate) mod hash;
pub(crate) mod key_exchange;
pub(crate) mod mac;
pub(crate) mod public_key;

use crate::constant::algorithms as constant;

use self::{hash::HashCtx, key_exchange::KeyExchange};

pub enum Enc {
    Chacha20Poly1305Openssh,
    Aes128Ctr,
}

impl Enc {
    pub(crate) fn as_str(&self) -> &'static str {
        match self {
            Enc::Chacha20Poly1305Openssh => constant::enc::CHACHA20_POLY1305_OPENSSH,
            Enc::Aes128Ctr => constant::enc::AES128_CTR,
        }
    }
}
pub enum Kex {
    Curve25519Sha256,
    EcdhSha2Nistrp256,
}

impl Kex {
    pub(crate) fn as_str(&self) -> &'static str {
        match self {
            Kex::Curve25519Sha256 => constant::kex::CURVE25519_SHA256,
            Kex::EcdhSha2Nistrp256 => constant::kex::ECDH_SHA2_NISTP256,
        }
    }
}

pub enum PubKey {
    SshEd25519,
    #[cfg(feature = "dangerous-rsa-sha1")]
    SshRsa,
    RsaSha2_256,
}

impl PubKey {
    pub(crate) fn as_str(&self) -> &'static str {
        match self {
            PubKey::SshEd25519 => constant::pubkey::SSH_ED25519,
            #[cfg(feature = "dangerous-rsa-sha1")]
            PubKey::SshRsa => constant::pubkey::SSH_RSA,
            PubKey::RsaSha2_256 => constant::pubkey::RSA_SHA2_256,
        }
    }
}

pub enum Mac {
    HmacSha1,
}

impl Mac {
    pub(crate) fn as_str(&self) -> &'static str {
        match self {
            Mac::HmacSha1 => constant::mac::HMAC_SHA1,
        }
    }
}

pub enum Compress {
    None,
}

impl Compress {
    pub(crate) fn as_str(&self) -> &'static str {
        match self {
            Compress::None => constant::compress::NONE,
        }
    }
}

#[derive(Default)]
pub(crate) struct Digest {
    pub hash_ctx: HashCtx,
    pub key_exchange: Option<Box<dyn KeyExchange>>,
}

impl Digest {
    pub fn new() -> Self {
        Self {
            ..Default::default()
        }
    }
}