lber/structures/
mod.rs

1use crate::structure;
2
3pub mod boolean;
4pub mod explicit;
5pub mod integer;
6pub mod null;
7pub mod octetstring;
8pub mod sequence;
9
10// Reexport everything
11pub use self::boolean::Boolean;
12pub use self::explicit::ExplicitTag;
13pub use self::integer::{Enumerated, Integer};
14pub use self::null::Null;
15pub use self::octetstring::OctetString;
16pub use self::sequence::{Sequence, SequenceOf, Set, SetOf};
17
18/// Conversion of a tag into a serializable form.
19pub trait ASNTag {
20    /// Encode yourself into a generic Tag format.
21    ///
22    /// The only thing that changes between types is how to encode the wrapped value into bytes;
23    /// the encoding of the class and id does not change. By first converting the tag into
24    /// a more generic tag (with already encoded payload), we don't have to reimplement the
25    /// encoding step for class/id every time.
26    fn into_structure(self) -> structure::StructureTag;
27}
28
29#[derive(Clone, Debug, PartialEq)]
30/// Set of basic ASN.1 types used by LDAP.
31pub enum Tag {
32    /// Integer value.
33    Integer(integer::Integer),
34    /// Integer with a different tag.
35    Enumerated(integer::Enumerated),
36    /// Sequence of values.
37    Sequence(sequence::Sequence),
38    /// Set of values; doesn't allow duplicates.
39    Set(sequence::Set),
40    /// String of bytes.
41    OctetString(octetstring::OctetString),
42    /// Boolean value.
43    Boolean(boolean::Boolean),
44    /// Null value.
45    Null(null::Null),
46    /// Explicitly tagged value. LDAP uses implicit tagging, but external structures might not.
47    ExplicitTag(explicit::ExplicitTag),
48    /// Serializable value.
49    StructureTag(structure::StructureTag),
50}
51
52impl ASNTag for Tag {
53    fn into_structure(self) -> structure::StructureTag {
54        match self {
55            Tag::Integer(i) => i.into_structure(),
56            Tag::Enumerated(i) => i.into_structure(),
57            Tag::Sequence(i) => i.into_structure(),
58            Tag::Set(i) => i.into_structure(),
59            Tag::OctetString(i) => i.into_structure(),
60            Tag::Boolean(i) => i.into_structure(),
61            Tag::Null(i) => i.into_structure(),
62            Tag::ExplicitTag(i) => i.into_structure(),
63            Tag::StructureTag(s) => s,
64        }
65    }
66}