Skip to main content

Filter

Enum Filter 

Source
pub enum Filter {
    And(Vec<Filter>),
    Or(Vec<Filter>),
    Not(Box<Filter>),
    Equality {
        attribute: String,
        value: String,
    },
    GreaterOrEqual {
        attribute: String,
        value: String,
    },
    LessOrEqual {
        attribute: String,
        value: String,
    },
    Approximate {
        attribute: String,
        value: String,
    },
    Present {
        attribute: String,
    },
    Substrings {
        attribute: String,
        initial: Option<String>,
        any: Vec<String>,
        last: Option<String>,
    },
}
Expand description

A search filter, built as a value rather than pasted together as a string.

This is the security-relevant type in the package. The classic LDAP injection is a filter template — (&(objectClass=person)(uid=NAME)) — with a username interpolated into it: a username of * turns the lookup into a wildcard that matches every account, and one containing )(uid=admin re- writes the filter outright.

A Filter cannot be injected into, because it never becomes a string on the way to the directory. Filter::encode writes each assertion value as a length-delimited BER octet string, where * and ) are just bytes with no syntax of their own.

Display does produce RFC 4515 text — for logs, and for anything that genuinely needs the string form — and escapes every value on the way out.

Variants§

§

And(Vec<Filter>)

(&(a)(b)). An empty And is the absolute-true filter (&) of RFC 4526, which is well defined and matches everything.

§

Or(Vec<Filter>)

(|(a)(b)). An empty Or is RFC 4526’s absolute-false filter (|).

§

Not(Box<Filter>)

§

Equality

(attribute=value)

Fields

§attribute: String
§value: String
§

GreaterOrEqual

(attribute>=value)

Fields

§attribute: String
§value: String
§

LessOrEqual

(attribute<=value)

Fields

§attribute: String
§value: String
§

Approximate

(attribute~=value)

Fields

§attribute: String
§value: String
§

Present

(attribute=*) — the entry has this attribute at all.

Fields

§attribute: String
§

Substrings

(attribute=initial*any*any*last). RFC 4511 calls the trailing part final, which is a Rust keyword, so it is last here.

Fields

§attribute: String
§initial: Option<String>

Implementations§

Source§

impl Filter

Source

pub fn equals(attribute: impl Into<String>, value: impl Into<String>) -> Filter

Source

pub fn greater_or_equal( attribute: impl Into<String>, value: impl Into<String>, ) -> Filter

Source

pub fn less_or_equal( attribute: impl Into<String>, value: impl Into<String>, ) -> Filter

Source

pub fn approximately( attribute: impl Into<String>, value: impl Into<String>, ) -> Filter

Source

pub fn present(attribute: impl Into<String>) -> Filter

Source

pub fn starts_with( attribute: impl Into<String>, prefix: impl Into<String>, ) -> Filter

Source

pub fn ends_with( attribute: impl Into<String>, suffix: impl Into<String>, ) -> Filter

Source

pub fn contains( attribute: impl Into<String>, fragment: impl Into<String>, ) -> Filter

Source

pub fn and(filters: impl IntoIterator<Item = Filter>) -> Filter

Source

pub fn or(filters: impl IntoIterator<Item = Filter>) -> Filter

Source

pub fn negate(self) -> Filter

(!(…)). Also spelled !filter, through std::ops::Not; this form exists because it chains, and a filter is usually built left to right.

Source

pub fn encode(&self, encoder: &mut Encoder)

Write the filter as BER, per RFC 4511 §4.5.1.

Trait Implementations§

Source§

impl Clone for Filter

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Filter

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Display for Filter

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

The RFC 4515 string form, with every value escaped.

Source§

impl Eq for Filter

Source§

impl Not for Filter

!filter, for the times that reads better than Filter::negate.

Source§

type Output = Filter

The resulting type after applying the ! operator.
Source§

fn not(self) -> Filter

Performs the unary ! operation using logical or bitwise negation. Read more
Source§

impl PartialEq for Filter

Source§

fn eq(&self, other: &Self) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl StructuralPartialEq for Filter

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.