Module der_parser::ber
source · [−]Expand description
Basic Encoding Rules (BER) objects and parser
BER Objects
The main object of this crate is BerObject
. It contains a header (ber tag, class, and size)
and content.
To parse primitive objects (for ex. integers or strings), use the parse_ber_
set of
functions.
Constructed objects (like sequences, sets or tagged objects) require to use a combinator. This combinator takes a function or closure as input, and returns a new, specialized parser. See the nom parser combinator library for more details on combinators.
Examples
Parse two BER integers:
use der_parser::ber::parse_ber_integer;
let bytes = [ 0x02, 0x03, 0x01, 0x00, 0x01,
0x02, 0x03, 0x01, 0x00, 0x00,
];
let (rem, obj1) = parse_ber_integer(&bytes).expect("parsing failed");
let (rem, obj2) = parse_ber_integer(&bytes).expect("parsing failed");
Parse a BER sequence containing one integer and an octetstring:
use der_parser::ber::*;
let bytes = [ 0x30, 0x0a,
0x02, 0x03, 0x01, 0x00, 0x01,
0x04, 0x03, 0x62, 0x61, 0x64,
];
let (rem, seq) = parse_ber_sequence_defined(|content| {
let (rem, obj1) = parse_ber_integer(content)?;
let (rem, obj2) = parse_ber_octetstring(rem)?;
Ok((rem, vec![obj1, obj2]))
})(&bytes)
.expect("parsing failed");
Modules
Compatibility module for old (pre-7.0) types
Structs
Representation of a BER-encoded (X.690) object
BitString wrapper
BER/DER object header (identifier and length)
Pretty-print BER object
BER/DER Tag as defined in X.680 section 8.4
Enums
BER object content
BER Object class of tag
BER Object Length
Constants
Default maximum object size (2^32)
Default maximum recursion limit
Traits
BER object tree traversal to walk a shared borrow of a BER object
BER object tree traversal to walk a shared borrow of a BER object
Functions
Parse the next bytes as the content of a BER object.
Read an object header
Parse BER object recursively
Parse any BER object (not recursive)
Parse any BER object recursively, specifying the maximum recursion depth
Parse any BER object recursively, specifying the maximum recursion depth and expected tag
Read an bitstring value
Read a BmpString value
Read a boolean value
Parse a BER object and apply provided function to content
Parse the next bytes as the content of a BER object (combinator, header reference)
Parse the next bytes as the content of a BER object (combinator, owned header)
Read end of content marker
Read an enumerated value
Parse an optional tagged object, applying function to get content
Read a Generalized time value
Read a GeneralString value
Read a GraphicString value
Parse BER object and try to decode it as a 32-bits signed integer
Parse BER object and try to decode it as a 64-bits signed integer
Read an IA5 string value. The content is verified to be ASCII.
Parse an implicit tagged object, applying function to read content
Read an integer value
Read a null value
Read a numeric string value. The content is verified to contain only digits and spaces.
Read an ObjectDescriptor value
Read an octetstring value
Read an object identifier value
Combinator for building optional BER values
Read a printable string value. The content is verified to contain only the allowed characters.
Parse BER object recursively, specifying the maximum recursion depth
Read a relative object identifier value
Parse a sequence of BER elements
Parse a defined sequence of DER elements (function version)
Parse a defined SEQUENCE object (generic function)
Parse a SEQUENCE OF object
Parse a SEQUENCE OF object (returning a vec)
Parse a set of BER elements
Parse a defined set of DER elements (function version)
Parse a defined SET object (generic version)
Parse a SET OF object
Parse a SET OF object (returning a vec)
Parse BER object and get content as slice
Read a T61 string value
Read a TAGGED EXPLICIT value (combinator)
Read a TAGGED EXPLICIT value (generic version)
Read a TAGGED IMPLICIT value (combinator)
Read a TAGGED IMPLICIT value (generic version)
Parse BER object and try to decode it as a 32-bits unsigned integer
Parse BER object and try to decode it as a 64-bits unsigned integer
Read a UniversalString value
Read an UTC time value
Read a UTF-8 string value. The encoding is checked.
Read a Videotex string value
Read a visible string value. The content is verified to contain only the allowed characters.
Parse a BER object, expecting a value with specified tag