Skip to main content

Encoder

Struct Encoder 

Source
pub struct Encoder { /* private fields */ }
Expand description

A BER element under construction.

Nested elements are built into a temporary encoder and copied in once their length is known. BER puts the length before the contents, so something has to give: either the bytes move, or the length does. An LDAP message is a few hundred bytes and a handful of levels deep, so the copy is not worth out-thinking, and building inside-out is the version a reader can check.

Implementations§

Source§

impl Encoder

Source

pub fn new() -> Encoder

Source

pub fn as_bytes(&self) -> &[u8] ⓘ

Source

pub fn into_bytes(self) -> Vec<u8> ⓘ

Source

pub fn len(&self) -> usize

Source

pub fn is_empty(&self) -> bool

Source

pub fn element(&mut self, tag: u8, contents: &[u8]) -> &mut Encoder

One element: identifier octet, definite length, contents verbatim.

Source

pub fn constructed( &mut self, tag: u8, body: impl FnOnce(&mut Encoder), ) -> &mut Encoder

A constructed element whose contents are written by body.

Source

pub fn sequence(&mut self, body: impl FnOnce(&mut Encoder)) -> &mut Encoder

Source

pub fn set(&mut self, body: impl FnOnce(&mut Encoder)) -> &mut Encoder

Source

pub fn integer(&mut self, value: i64) -> &mut Encoder

Source

pub fn enumerated(&mut self, value: i64) -> &mut Encoder

Source

pub fn tagged_integer(&mut self, tag: u8, value: i64) -> &mut Encoder

An INTEGER under some other tag — LDAP tags a few of them contextually.

Source

pub fn boolean(&mut self, value: bool) -> &mut Encoder

TRUE is encoded as 0xff.

BER would accept any non-zero octet, but there is no reason to invent a second spelling on the way out, and DER-shaped output is what every directory expects to see.

Source

pub fn octet_string(&mut self, contents: &[u8]) -> &mut Encoder

Source

pub fn string(&mut self, value: &str) -> &mut Encoder

An LDAPString, which RFC 4511 defines as UTF-8 in an OCTET STRING.

Source

pub fn tagged_string(&mut self, tag: u8, value: &str) -> &mut Encoder

An OCTET STRING carrying a context-specific tag instead of its own — implicit tagging, which is what RFC 4511’s ASN.1 module asks for.

Source

pub fn null(&mut self) -> &mut Encoder

Source

pub fn raw(&mut self, encoded: &[u8]) -> &mut Encoder

Append bytes that are already a complete element.

Trait Implementations§

Source§

impl Default for Encoder

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

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> 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, 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.