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
use lber::common::TagClass;
use lber::structures::{OctetString, Tag};
mod whoami;
pub use self::whoami::{WhoAmI, WhoAmIResp};
mod starttls;
pub use self::starttls::StartTLS;
#[derive(Clone, Debug)]
pub struct Exop {
    
    pub name: Option<String>,
    
    pub val: Option<Vec<u8>>,
}
impl Exop {
    
    
    
    
    
    pub fn parse<T: ExopParser>(&self) -> T {
        T::parse(self.val.as_ref().expect("value"))
    }
}
pub trait ExopParser {
    
    fn parse(val: &[u8]) -> Self;
}
pub fn construct_exop(exop: Exop) -> Vec<Tag> {
    assert!(exop.name.is_some());
    let mut seq = vec![Tag::OctetString(OctetString {
        id: 0,
        class: TagClass::Context,
        inner: exop.name.unwrap().into_bytes(),
    })];
    if let Some(val) = exop.val {
        seq.push(Tag::OctetString(OctetString {
            id: 1,
            class: TagClass::Context,
            inner: val,
        }));
    }
    seq
}