bcder/decode/
mod.rs

1//! Parsing BER-encoded data.
2//!
3//! This modules provides the means to parse BER-encoded data.
4//!
5//! The basic idea is that for each type a function exists that knows how
6//! to decode one value of that type. For constructed types, this function
7//! in turn relies on similar functions provided for its constituent types.
8//! For a detailed introduction to how to write these functions, please
9//! refer to the [decode section of the guide][crate::guide::decode].
10//!
11//! The two most important types of this module are [`Primitive`] and
12//! [`Constructed`], representing the content octets of a value in primitive
13//! and constructed encoding, respectively. Each provides a number of methods
14//! allowing to parse the content.
15//!
16//! You will never create a value of either type. Rather, you get handed a
17//! reference to one as an argument to a closure or function argument to be
18//! provided to these methods. 
19//!
20//! The enum [`Content`] is used for cases where a value can be either
21//! primitive or constructed such as most string types.
22//!
23//! The data for decoding is provided by any type that implements the
24//! [`Source`] trait – or can be converted into such a type via the
25//! [`IntoSource`] trait. Implementations for both `bytes::Bytes` and
26//! `&[u8]` are available.
27//!
28//! During decoding, errors can happen. There are two kinds of errors: for
29//! one, the source can fail to gather more data, e.g., when reading from a
30//! file fails. Such errors are called _source errors._ Their type is
31//! provided by the source.
32//!
33//! Second, data that cannot be decoded according to the syntax is said to
34//! result in a _content error._ The [`ContentError`] type is used for such
35//! errors.
36//!
37//! When decoding data from a source, both errors can happen. The type
38//! `DecodeError` provides a way to store either of them and is the error
39//! type you will likely encounter the most.
40
41pub use self::content::{Content, Constructed, Primitive};
42pub use self::error::{ContentError, DecodeError};
43pub use self::source::{
44    BytesSource, CaptureSource, IntoSource, Pos, LimitedSource, SliceSource,
45    Source
46};
47
48mod content;
49mod error;
50mod source;
51