1#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord)]
2pub enum StreamSecurity {
3 Unencrypted,
4 AnyEncryption,
5 ClassicEncryption,
6 QuantumEncryption,
7 DoubleEncryption,
8}
9
10impl Default
11for StreamSecurity {
12 fn default() -> Self {
13 StreamSecurity::AnyEncryption
14 }
15}
16
17impl StreamSecurity {
18 pub fn classic_encryption(&self) -> bool {
19 match self {
20 StreamSecurity::ClassicEncryption |
21 StreamSecurity::DoubleEncryption => {
22 true
23 },
24 _ => false
25 }
26 }
27
28 pub fn quantum_encryption(&self, https: bool) -> bool {
29 match self {
30 StreamSecurity::AnyEncryption => {
31 https == false
32 }
33 StreamSecurity::QuantumEncryption |
34 StreamSecurity::DoubleEncryption => {
35 true
36 },
37 _ => false
38 }
39 }
40}
41
42impl std::str::FromStr
43for StreamSecurity
44{
45 type Err = String;
46
47 fn from_str(s: &str) -> Result<Self, Self::Err> {
48 Ok(
49 match s {
50 "none" | "" | "no" | "unencrypted" => StreamSecurity::Unencrypted,
51 "any" | "anyencryption" | "encrypted" | "any_encryption" => {
52 StreamSecurity::AnyEncryption
53 },
54 "classic" => StreamSecurity::ClassicEncryption,
55 "quantum" => StreamSecurity::QuantumEncryption,
56 "double" => StreamSecurity::DoubleEncryption,
57 a => {
58 return Err(format!("stream security type ({}) is not valid - try: 'none', 'any', 'classic', 'quantum' or 'double'", a))
59 }
60 }
61 )
62 }
63}