Skip to main content

ssh2_config/
default_algorithms.rs

1mod openssh;
2pub use openssh::defaults as default_algorithms;
3
4/// Default algorithms for ssh.
5#[derive(Debug, Clone, PartialEq, Eq)]
6pub struct DefaultAlgorithms {
7    pub ca_signature_algorithms: Vec<String>,
8    pub ciphers: Vec<String>,
9    pub host_key_algorithms: Vec<String>,
10    pub kex_algorithms: Vec<String>,
11    pub mac: Vec<String>,
12    pub pubkey_accepted_algorithms: Vec<String>,
13}
14
15impl Default for DefaultAlgorithms {
16    fn default() -> Self {
17        default_algorithms()
18    }
19}
20
21impl DefaultAlgorithms {
22    /// Create a new instance of [`DefaultAlgorithms`] with empty fields.
23    pub fn empty() -> Self {
24        Self {
25            ca_signature_algorithms: vec![],
26            ciphers: vec![],
27            host_key_algorithms: vec![],
28            kex_algorithms: vec![],
29            mac: vec![],
30            pubkey_accepted_algorithms: vec![],
31        }
32    }
33}
34
35#[cfg(test)]
36mod tests {
37    use super::*;
38
39    #[test]
40    fn test_default_algorithms_default() {
41        let default_algos = DefaultAlgorithms::default();
42        // Default should have non-empty algorithms from openssh defaults
43        assert!(!default_algos.ciphers.is_empty());
44        assert!(!default_algos.kex_algorithms.is_empty());
45        assert!(!default_algos.mac.is_empty());
46        assert!(!default_algos.host_key_algorithms.is_empty());
47    }
48
49    #[test]
50    fn test_default_algorithms_empty() {
51        let empty = DefaultAlgorithms::empty();
52        assert!(empty.ca_signature_algorithms.is_empty());
53        assert!(empty.ciphers.is_empty());
54        assert!(empty.host_key_algorithms.is_empty());
55        assert!(empty.kex_algorithms.is_empty());
56        assert!(empty.mac.is_empty());
57        assert!(empty.pubkey_accepted_algorithms.is_empty());
58    }
59
60    #[test]
61    fn test_default_algorithms_equality() {
62        let algos1 = DefaultAlgorithms::default();
63        let algos2 = DefaultAlgorithms::default();
64        assert_eq!(algos1, algos2);
65
66        let empty1 = DefaultAlgorithms::empty();
67        let empty2 = DefaultAlgorithms::empty();
68        assert_eq!(empty1, empty2);
69
70        assert_ne!(algos1, empty1);
71    }
72
73    #[test]
74    fn test_default_algorithms_clone() {
75        let original = DefaultAlgorithms::default();
76        let cloned = original.clone();
77        assert_eq!(original, cloned);
78    }
79
80    #[test]
81    fn test_default_algorithms_debug() {
82        let algos = DefaultAlgorithms::empty();
83        let debug_str = format!("{:?}", algos);
84        assert!(debug_str.contains("DefaultAlgorithms"));
85    }
86}