der_parser/ber/mod.rs
1//! Basic Encoding Rules (BER) objects and parser
2//!
3//! # BER Objects
4//!
5//! The main object of this crate is [`BerObject`]. It contains a header (ber tag, class, and size)
6//! and content.
7//!
8//! To parse primitive objects (for ex. integers or strings), use the `parse_ber_` set of
9//! functions.
10//!
11//! Constructed objects (like sequences, sets or tagged objects) require to use a combinator. This
12//! combinator takes a function or closure as input, and returns a new, specialized parser.
13//! See the [nom](https://github.com/geal/nom) parser combinator library for more details on
14//! combinators.
15//!
16//! # Examples
17//!
18//! Parse two BER integers:
19//!
20//! ```rust
21//! use der_parser::ber::parse_ber_integer;
22//!
23//! let bytes = [ 0x02, 0x03, 0x01, 0x00, 0x01,
24//! 0x02, 0x03, 0x01, 0x00, 0x00,
25//! ];
26//!
27//! let (rem, obj1) = parse_ber_integer(&bytes).expect("parsing failed");
28//! let (rem, obj2) = parse_ber_integer(&bytes).expect("parsing failed");
29//! ```
30//!
31//! Parse a BER sequence containing one integer and an octetstring:
32//!
33//! ```rust
34//! use der_parser::ber::*;
35//!
36//! let bytes = [ 0x30, 0x0a,
37//! 0x02, 0x03, 0x01, 0x00, 0x01,
38//! 0x04, 0x03, 0x62, 0x61, 0x64,
39//! ];
40//!
41//! let (rem, seq) = parse_ber_sequence_defined(|content| {
42//! let (rem, obj1) = parse_ber_integer(content)?;
43//! let (rem, obj2) = parse_ber_octetstring(rem)?;
44//! Ok((rem, vec![obj1, obj2]))
45//! })(&bytes)
46//! .expect("parsing failed");
47//! ```
48
49mod ber;
50mod integer;
51mod multi;
52mod parser;
53mod print;
54#[cfg(feature = "serialize")]
55mod serialize;
56mod tagged;
57mod visit;
58mod visit_mut;
59mod wrap_any;
60
61pub use crate::ber::ber::*;
62pub use crate::ber::multi::*;
63pub use crate::ber::parser::*;
64pub use crate::ber::print::*;
65#[cfg(feature = "serialize")]
66pub use crate::ber::serialize::*;
67pub use crate::ber::tagged::*;
68pub use crate::ber::visit::*;
69pub use crate::ber::visit_mut::*;
70pub use crate::ber::wrap_any::*;
71
72pub mod compat;
73
74pub use asn1_rs::{Class, Header, Length, Tag};
75
76use alloc::boxed::Box;
77use alloc::vec::Vec;
78use core::convert::Into;