ldap_rs/
model.rs

1//! Data structures
2
3use bytes::Bytes;
4pub use rasn_ldap::{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.to_vec().into(),
36        )
37    }
38}
39
40impl From<Attribute> for rasn_ldap::Attribute {
41    fn from(attr: Attribute) -> Self {
42        rasn_ldap::Attribute::new(attr.name.into(), attr.values.into())
43    }
44}
45
46/// An entry found during the search
47#[derive(Clone, Debug, Eq, PartialEq)]
48pub struct SearchEntry {
49    /// The name of the object found (Distinguished Name)
50    pub dn: String,
51    /// The attributes associated with the object
52    pub attributes: Attributes,
53}
54
55impl From<rasn_ldap::SearchResultEntry> for SearchEntry {
56    fn from(raw: rasn_ldap::SearchResultEntry) -> Self {
57        SearchEntry {
58            dn: raw.object_name.0,
59            attributes: raw.attributes.into_iter().map(Into::into).collect(),
60        }
61    }
62}