Expand description
Distinguished Encoding Rules (DER) objects and parser
All functions in this crate use BER parsing functions (see the ber
module)
internally, adding constraints verification where needed.
The objects BerObject
and DerObject
are the same (type alias): all BER functions,
combinators and macros can be used, and provide additional tools for DER parsing.
However, DER parsing functions enforce DER constraints in addition of their BER counterparts.
§DER Objects
The main object of this crate is DerObject
. It contains a header (ber tag, class, and size)
and content.
To parse primitive objects (for ex. integers or strings), use the parse_der_
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 DER integers:
use der_parser::der::parse_der_integer;
let bytes = [ 0x02, 0x03, 0x01, 0x00, 0x01,
0x02, 0x03, 0x01, 0x00, 0x00,
];
let (rem, obj1) = parse_der_integer(&bytes).expect("parsing failed");
let (rem, obj2) = parse_der_integer(&bytes).expect("parsing failed");
Parse a BER sequence containing one integer and an octetstring:
use der_parser::der::*;
let bytes = [ 0x30, 0x0a,
0x02, 0x03, 0x01, 0x00, 0x01,
0x04, 0x03, 0x62, 0x61, 0x64,
];
let (rem, seq) = parse_der_sequence_defined(|content| {
let (rem, obj1) = parse_der_integer(content)?;
let (rem, obj2) = parse_der_octetstring(rem)?;
Ok((rem, vec![obj1, obj2]))
})(&bytes)
.expect("parsing failed");
Structs§
Enums§
- Class
- BER Object class of tag
Functions§
- der_
read_ element_ content - Parse DER object content recursively
- der_
read_ element_ content_ as - Parse the next bytes as the content of a DER object.
- der_
read_ element_ header - Read an object header (DER)
- parse_
der - Parse DER object recursively
- parse_
der_ bitstring - Read an bitstring value
- parse_
der_ bmpstring - Read a BmpString value
- parse_
der_ bool - Read a boolean value
- parse_
der_ container - Parse a DER object and apply provided function to content
- parse_
der_ content - Parse the next bytes as the content of a DER object (combinator, header reference)
- parse_
der_ content2 - Parse the next bytes as the content of a DER object (combinator, owned header)
- parse_
der_ endofcontent - Read end of content marker
- parse_
der_ enum - Read an enumerated value
- parse_
der_ explicit_ optional - Parse an optional tagged object, applying function to get content
- parse_
der_ generalizedtime - Read a Generalized time value
- parse_
der_ generalstring - Read a GeneralString value
- parse_
der_ graphicstring - Read a GraphicString value
- parse_
der_ i32 - Parse DER object and try to decode it as a 32-bits signed integer
- parse_
der_ i64 - Parse DER object and try to decode it as a 64-bits signed integer
- parse_
der_ ia5string - Read an IA5 string value. The content is verified to be ASCII.
- parse_
der_ implicit - Parse an implicit tagged object, applying function to read content
- parse_
der_ integer - Read an integer value
- parse_
der_ null - Read a null value
- parse_
der_ numericstring - Read a numeric string value. The content is verified to contain only digits and spaces.
- parse_
der_ objectdescriptor - Read a ObjectDescriptor value
- parse_
der_ octetstring - Read an octetstring value
- parse_
der_ oid - Read an object identifier value
- parse_
der_ printablestring - Read a printable string value. The content is verified to contain only the allowed characters.
- parse_
der_ recursive - Parse DER object recursively, specifying the maximum recursion depth
- parse_
der_ relative_ oid - Read a relative object identifier value
- parse_
der_ sequence - Parse a sequence of DER elements
- parse_
der_ sequence_ defined - Parse a defined sequence of DER elements (function version)
- parse_
der_ sequence_ defined_ g - Parse a defined SEQUENCE object (generic function)
- parse_
der_ sequence_ of - Parse a SEQUENCE OF object
- parse_
der_ sequence_ of_ v - Parse a SEQUENCE OF object (returning a vec)
- parse_
der_ set - Parse a set of DER elements
- parse_
der_ set_ defined - Parse a defined set of DER elements (function version)
- parse_
der_ set_ defined_ g - Parse a defined SET object (generic version)
- parse_
der_ set_ of - Parse a SET OF object
- parse_
der_ set_ of_ v - Parse a SET OF object (returning a vec)
- parse_
der_ slice - Parse DER object and get content as slice
- parse_
der_ t61string - Read a T61 string value
- parse_
der_ tagged_ explicit - Read a TAGGED EXPLICIT value (combinator)
- parse_
der_ tagged_ explicit_ g - Read a TAGGED EXPLICIT value (generic version)
- parse_
der_ tagged_ implicit - Read a TAGGED IMPLICIT value (combinator)
- parse_
der_ tagged_ implicit_ g - Read a TAGGED IMPLICIT value (generic version)
- parse_
der_ u32 - Parse DER object and try to decode it as a 32-bits unsigned integer
- parse_
der_ u64 - Parse DER object and try to decode it as a 64-bits unsigned integer
- parse_
der_ universalstring - Read a UniversalString value
- parse_
der_ utctime - Read an UTC time value
- parse_
der_ utf8string - Read a UTF-8 string value. The encoding is checked.
- parse_
der_ videotexstring - Read a Videotex string value
- parse_
der_ visiblestring - Read a printable string value. The content is verified to contain only the allowed characters.
- parse_
der_ with_ tag - Parse a DER object, expecting a value with specified tag
- visiblestring
Deprecated
Type Aliases§
- DerClass
Deprecated - DER Object class of tag (same as
BerClass
) - DerObject
- Representation of a DER-encoded (X.690) object
- DerObject
Content - BER object content
- DerObject
Header Deprecated - DER object header (identifier and length)
- DerTag
Deprecated - DER tag (same as BER tag)