ldap_rs/
model.rs

1//! Data structures
2
3use bytes::Bytes;
4pub use rasn_ldap::{AttributeValue, ResultCode, SearchRequestDerefAliases, SearchRequestScope};
5
6/// LDAP attribute definition
7#[derive(Clone, Debug, Eq, PartialEq)]
8pub struct Attribute {
9    /// Attribute name
10    pub name: String,
11    /// Attribute values
12    pub values: Vec<Bytes>,
13}
14
15pub type Attributes = Vec<Attribute>;
16
17impl From<rasn_ldap::PartialAttribute> for Attribute {
18    fn from(raw: rasn_ldap::PartialAttribute) -> Self {
19        Attribute {
20            name: raw.r#type.0,
21            values: raw
22                .vals
23                .to_vec()
24                .into_iter()
25                .map(|v| Bytes::copy_from_slice(v))
26                .collect(),
27        }
28    }
29}
30
31impl From<Attribute> for rasn_ldap::PartialAttribute {
32    fn from(attr: Attribute) -> Self {
33        rasn_ldap::PartialAttribute::new(
34            attr.name.into(),
35            attr.values
36                .into_iter()
37                .map(|value| AttributeValue::from(value.as_ref()))
38                .collect::<Vec<_>>()
39                .into(),
40        )
41    }
42}
43
44impl From<Attribute> for rasn_ldap::Attribute {
45    fn from(attr: Attribute) -> Self {
46        rasn_ldap::Attribute::new(
47            attr.name.into(),
48            attr.values
49                .into_iter()
50                .map(|value| AttributeValue::from(value.as_ref()))
51                .collect::<Vec<_>>()
52                .into(),
53        )
54    }
55}
56
57/// An entry found during the search
58#[derive(Clone, Debug, Eq, PartialEq)]
59pub struct SearchEntry {
60    /// The name of the object found (Distinguished Name)
61    pub dn: String,
62    /// The attributes associated with the object
63    pub attributes: Attributes,
64}
65
66impl From<rasn_ldap::SearchResultEntry> for SearchEntry {
67    fn from(raw: rasn_ldap::SearchResultEntry) -> Self {
68        SearchEntry {
69            dn: raw.object_name.0,
70            attributes: raw.attributes.into_iter().map(Into::into).collect(),
71        }
72    }
73}