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
impl Encoder
pub fn new() -> Encoder
pub fn as_bytes(&self) -> &[u8] ⓘ
pub fn into_bytes(self) -> Vec<u8> ⓘ
pub fn len(&self) -> usize
pub fn is_empty(&self) -> bool
Sourcepub fn element(&mut self, tag: u8, contents: &[u8]) -> &mut Encoder
pub fn element(&mut self, tag: u8, contents: &[u8]) -> &mut Encoder
One element: identifier octet, definite length, contents verbatim.
Sourcepub fn constructed(
&mut self,
tag: u8,
body: impl FnOnce(&mut Encoder),
) -> &mut Encoder
pub fn constructed( &mut self, tag: u8, body: impl FnOnce(&mut Encoder), ) -> &mut Encoder
A constructed element whose contents are written by body.
pub fn sequence(&mut self, body: impl FnOnce(&mut Encoder)) -> &mut Encoder
pub fn set(&mut self, body: impl FnOnce(&mut Encoder)) -> &mut Encoder
pub fn integer(&mut self, value: i64) -> &mut Encoder
pub fn enumerated(&mut self, value: i64) -> &mut Encoder
Sourcepub fn tagged_integer(&mut self, tag: u8, value: i64) -> &mut Encoder
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.
Sourcepub fn boolean(&mut self, value: bool) -> &mut Encoder
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.
pub fn octet_string(&mut self, contents: &[u8]) -> &mut Encoder
Sourcepub fn string(&mut self, value: &str) -> &mut Encoder
pub fn string(&mut self, value: &str) -> &mut Encoder
An LDAPString, which RFC 4511 defines as UTF-8 in an OCTET STRING.
Sourcepub fn tagged_string(&mut self, tag: u8, value: &str) -> &mut Encoder
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.