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§
- compat
- Compatibility module for old (pre-7.0) types
Structs§
- BerObject
- Representation of a BER-encoded (X.690) object
- BerObject
Into Iterator - BerObject
RefIterator - BitString
Object - BitString wrapper
- Header
- BER/DER object header (identifier and length)
- Pretty
Ber - Pretty-print BER object
- Tag
- BER/DER Tag as defined in X.680 section 8.4
Enums§
- BerObject
Content - BER object content
- Class
- BER Object class of tag
- Length
- BER Object Length
- Pretty
Printer Flag
Constants§
- MAX_
OBJECT_ SIZE - Default maximum object size (2^32)
- MAX_
RECURSION - Default maximum recursion limit
Traits§
- Visit
- BER object tree traversal to walk a shared borrow of a BER object
- Visit
Mut - BER object tree traversal to walk a shared borrow of a BER object
Functions§
- ber_
encode_ header serialize
- Encode header as object
- ber_
encode_ object serialize
- Encode object as BER
- ber_
encode_ object_ raw serialize
- Encode header and object content as BER, without any validation
- ber_
encode_ tagged_ explicit serialize
- Encode the provided object in an EXPLICIT tagged value, using the provided tag ans class
- ber_
encode_ tagged_ implicit serialize
- Encode the provided object in an IMPLICIT tagged value, using the provided tag and class
- ber_
read_ element_ content_ as - Parse the next bytes as the content of a BER object.
- ber_
read_ element_ header - Read an object header
- parse_
ber - Parse BER object recursively
- parse_
ber_ any - Parse any BER object (not recursive)
- parse_
ber_ any_ r - Parse any BER object recursively, specifying the maximum recursion depth
- parse_
ber_ any_ with_ tag_ r - Parse any BER object recursively, specifying the maximum recursion depth and expected tag
- parse_
ber_ bitstring - Read an bitstring value
- parse_
ber_ bmpstring - Read a BmpString value
- parse_
ber_ bool - Read a boolean value
- parse_
ber_ container - Parse a BER object and apply provided function to content
- parse_
ber_ content - Parse the next bytes as the content of a BER object (combinator, header reference)
- parse_
ber_ content2 - Parse the next bytes as the content of a BER object (combinator, owned header)
- parse_
ber_ endofcontent - Read end of content marker
- parse_
ber_ enum - Read an enumerated value
- parse_
ber_ explicit_ optional - Parse an optional tagged object, applying function to get content
- parse_
ber_ generalizedtime - Read a Generalized time value
- parse_
ber_ generalstring - Read a GeneralString value
- parse_
ber_ graphicstring - Read a GraphicString value
- parse_
ber_ i32 - Parse BER object and try to decode it as a 32-bits signed integer
- parse_
ber_ i64 - Parse BER object and try to decode it as a 64-bits signed integer
- parse_
ber_ ia5string - Read an IA5 string value. The content is verified to be ASCII.
- parse_
ber_ implicit - Parse an implicit tagged object, applying function to read content
- parse_
ber_ integer - Read an integer value
- parse_
ber_ null - Read a null value
- parse_
ber_ numericstring - Read a numeric string value. The content is verified to contain only digits and spaces.
- parse_
ber_ objectdescriptor - Read an ObjectDescriptor value
- parse_
ber_ octetstring - Read an octetstring value
- parse_
ber_ oid - Read an object identifier value
- parse_
ber_ optional - Combinator for building optional BER values
- parse_
ber_ printablestring - Read a printable string value. The content is verified to contain only the allowed characters.
- parse_
ber_ recursive - Parse BER object recursively, specifying the maximum recursion depth
- parse_
ber_ relative_ oid - Read a relative object identifier value
- parse_
ber_ sequence - Parse a sequence of BER elements
- parse_
ber_ sequence_ defined - Parse a defined sequence of DER elements (function version)
- parse_
ber_ sequence_ defined_ g - Parse a defined SEQUENCE object (generic function)
- parse_
ber_ sequence_ of - Parse a SEQUENCE OF object
- parse_
ber_ sequence_ of_ v - Parse a SEQUENCE OF object (returning a vec)
- parse_
ber_ set - Parse a set of BER elements
- parse_
ber_ set_ defined - Parse a defined set of DER elements (function version)
- parse_
ber_ set_ defined_ g - Parse a defined SET object (generic version)
- parse_
ber_ set_ of - Parse a SET OF object
- parse_
ber_ set_ of_ v - Parse a SET OF object (returning a vec)
- parse_
ber_ slice - Parse BER object and get content as slice
- parse_
ber_ t61string - Read a T61 string value
- parse_
ber_ tagged_ explicit - Read a TAGGED EXPLICIT value (combinator)
- parse_
ber_ tagged_ explicit_ g - Read a TAGGED EXPLICIT value (generic version)
- parse_
ber_ tagged_ implicit - Read a TAGGED IMPLICIT value (combinator)
- parse_
ber_ tagged_ implicit_ g - Read a TAGGED IMPLICIT value (generic version)
- parse_
ber_ u32 - Parse BER object and try to decode it as a 32-bits unsigned integer
- parse_
ber_ u64 - Parse BER object and try to decode it as a 64-bits unsigned integer
- parse_
ber_ universalstring - Read a UniversalString value
- parse_
ber_ utctime - Read an UTC time value
- parse_
ber_ utf8string - Read a UTF-8 string value. The encoding is checked.
- parse_
ber_ videotexstring - Read a Videotex string value
- parse_
ber_ visiblestring - Read a visible string value. The content is verified to contain only the allowed characters.
- parse_
ber_ with_ tag - Parse a BER object, expecting a value with specified tag