asnom/structures/
mod.rs

1use structure;
2
3pub mod integer;
4pub mod sequence;
5pub mod octetstring;
6pub mod boolean;
7pub mod null;
8
9// Reexport everything
10pub use self::integer::Integer;
11pub use self::sequence::{Sequence, SequenceOf, SetOf};
12pub use self::octetstring::OctetString;
13pub use self::boolean::Boolean;
14pub use self::null::Null;
15
16pub trait ASNTag {
17    /// Encode yourself into a generic Tag format.
18    /// 
19    /// The only thing that changes between types is how to encode the value they wrap into bytes,
20    /// however the encoding of the class and id does not change. By first converting the tag into
21    /// a more generic tag (with already encoded payload), we don't have to reimplement the
22    /// encoding step for class & id every time.
23    fn into_structure(self) -> structure::StructureTag;
24}
25
26#[derive(Clone, Debug)]
27/// This enum does not cover all ASN.1 Types but only the types needed for LDAPv3.
28pub enum Tag {
29    Integer(integer::Integer),
30    Sequence(sequence::Sequence),
31    OctetString(octetstring::OctetString),
32    Boolean(boolean::Boolean),
33    Null(null::Null),
34    StructureTag(structure::StructureTag),
35}
36
37impl ASNTag for Tag {
38    fn into_structure(self) -> structure::StructureTag {
39        match self {
40            Tag::Integer(i)      => i.into_structure(),
41            Tag::Sequence(i)     => i.into_structure(),
42            Tag::OctetString(i)  => i.into_structure(),
43            Tag::Boolean(i)      => i.into_structure(),
44            Tag::Null(i)         => i.into_structure(),
45            Tag::StructureTag(s) => s
46        }
47    }
48}