Module ldap3::controls

source ·
Expand description

Control construction and parsing.

A control can be associated with a request or a response. Several common controls, such as PagedResults, are implemented directly by this library. If an implemented control has the same form for the request and the response, there will be a single structure for both. (This is the case for PagedResults.) If the response control is different, its name will consist of the request control name with the Resp suffix.

A request control can be created by instantiating its structure and converting it to ASN.1 with into() when passing the instance or constructing the request control vector in the call to with_controls(). A third-party control must implement the conversion from an instance of itself to RawControl, a general form of control.

RawControl, together with an optional instance of ControlType, forms the type Control; a vector of Controls is part of the result of all LDAP operation which return one.

The first element of Control will have a value if the parser recognizes the control’s OID as one that is implemented by the library itself. Since the list of implemented controls is expected to grow, the ControlType enum cannot be exhaustively matched.

A recognized response control can be parsed by calling parse() on the instance of RawControl representing it. A third-party control must implement the ControlParser trait to support this interface.

Example

With an LdapResult in res, iterating through controls and matching the desired ones could be done like this:

for ctrl in res.ctrls {
    match ctrl {
        // matching a control implemented by the library
        Control(Some(ControlType::PagedResults), ref raw) => {
            dbg!(raw.parse::<PagedResults>());
        },
        // matching a control unknown to the library
        // the OID is actually that of PagedResults
        Control(None, ref raw) if raw.ctype == "1.2.840.113556.1.4.319" => {
            dbg!(raw.parse::<PagedResults>());
        },
        _ => (),
    }
}

Structs

Enums

Traits

Functions

Type Definitions