Module bcder::encode

source ·
Expand description

Encoding data in BER.

This modules provides means to encode data in BER.

Encoding is done using helper types called encoders that represent the structure of the BER encoding. These types implement the trait Values. A type that can be encoded as BER typically provides a method named encode that produces a value of its encoder type representing the value’s encoding. If necessary, they can also provide a method encode_as that does the same thing but allows the caller to provide an tag to use for encoding as is necessary for implicit tagging.

The Values type can then be used to simply write the encoding to anything that implements the standard library’s io::Write trait.

The trait PrimitiveContent helps with producing encoders for types that use the primitive encoding. Through this trait the types can declare how their content is encoded and receive an automatic encoder type based on that.

The module also provides a number of helper types that make it easier to implement encoders in various situations.

For a more detailed introduction to writing the encode methods of types, see the encode section of the guide.

Structs

A value encoder for a single constructed value.
A wrapper for an iterator of values.
A encoder for nothing.
A value encoder for primitively encoded types.

Enums

A value encoder for a two-variant enum.
A value encoder for a three-variant enum.

Traits

A type that is encoded as a primitive value.
A type that is a value encoder.

Functions

Returns a value encoder for a SEQUENCE containing inner.
Returns a value encoder for a SEQUENCE with the given tag.
Returns a value encoder for a SET containing inner.
Returns a value encoder for a SET with the given tag.
Returns the length for a structure based on the tag and content length.
Writes the header for a value.