sdp_rs/lines/key/
key_method.rs

1/// The key method as it appears in the key line (`k=`). It's not `Copy` type since it supports
2/// abstract types, not even defined in any RFC.
3#[derive(Debug, PartialEq, Eq, Ord, PartialOrd, Clone)]
4pub enum KeyMethod {
5    Clear,
6    Base64,
7    Uri,
8    Prompt,
9    Other(String),
10}
11
12impl<'a> From<&'a str> for KeyMethod {
13    fn from(s: &str) -> Self {
14        match s {
15            s if s.eq("clear") => Self::Clear,
16            s if s.eq("base64") => Self::Base64,
17            s if s.eq("uri") => Self::Uri,
18            s if s.eq("prompt") => Self::Prompt,
19            _ => Self::Other(s.into()),
20        }
21    }
22}
23
24impl std::fmt::Display for KeyMethod {
25    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
26        match self {
27            Self::Clear => write!(f, "clear"),
28            Self::Base64 => write!(f, "base64"),
29            Self::Uri => write!(f, "uri"),
30            Self::Prompt => write!(f, "prompt"),
31            Self::Other(other) => write!(f, "{}", other),
32        }
33    }
34}
35
36#[cfg(test)]
37mod tests {
38    use super::*;
39
40    #[test]
41    fn from_str1() {
42        assert_eq!(KeyMethod::from("clear"), KeyMethod::Clear);
43    }
44
45    #[test]
46    fn display1() {
47        assert_eq!(KeyMethod::Base64.to_string(), "base64");
48    }
49}