Start ldap library crate

- Struct `User`
This commit is contained in:
Candifloss 2026-07-29 20:16:10 +05:30
parent 8a2b9d0952
commit 21f16b7dcc
5 changed files with 42 additions and 17 deletions

View File

@ -11,8 +11,8 @@ license = "GPL-3.0-or-later"
repository = "https://git.candifloss.cc/candifloss/ldap-kit.git"
[workspace.dependencies]
anyhow = "1.0.102"
clap = { version = "4.6.1", features = ["derive"] }
anyhow = "1.0.104"
clap = { version = "4.6.4", features = ["derive"] }
ldap3 = "0.12.1"
serde = { version = "1.0.228", features = ["derive"] }
toml = "1.1.2"
serde = { version = "1.0.229", features = ["derive"] }
toml = "1.1.4"

View File

@ -6,3 +6,6 @@ license.workspace = true
repository.workspace = true
[dependencies]
anyhow.workspace = true
config = { version = "0.1.0", path = "../config" }
ldap3.workspace = true

View File

View File

@ -1,14 +1,5 @@
pub fn add(left: u64, right: u64) -> u64 {
left + right
}
mod client;
mod user;
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn it_works() {
let result = add(2, 2);
assert_eq!(result, 4);
}
}
//pub use client::LdapClient;
pub use user::User;

31
crates/ldap/src/user.rs Normal file
View File

@ -0,0 +1,31 @@
//! LDAP user.
use std::collections::HashMap;
/// LDAP user entry.
#[derive(Debug, Clone)]
pub struct User {
/// Distinguished Name.
pub dn: String,
/// LDAP attributes.
///
/// Keys are attribute names.
/// Values contain all values of that attribute.
pub attributes: HashMap<String, Vec<String>>,
}
impl User {
/// Return the first value of an attribute.
pub fn attribute(&self, name: &str) -> Option<&str> {
self.attributes
.get(name)
.and_then(|values| values.first())
.map(String::as_str)
}
/// Check whether an attribute exists.
pub fn has_attribute(&self, name: &str) -> bool {
self.attributes.contains_key(name)
}
}