Module der_parser::oid [−][src]
Expand description
Object ID (OID) representations.
The parser does not copy oids when parsing. The Oid struct only has a reference to the DER encoded form of the oid.
The der_parser::oid!
macro
Since the DER encoded oids are not very readable we provide a
procedural macro oid!
. The macro can be used the following ways:
oid!(1.4.42.23)
: Create a const expression for the correspondingOid<'static>
oid!(rel 42.23)
: Create a const expression for the corresponding relativeOid<'static>
oid!(raw 1.4.42.23)
/oid!(raw rel 42.23)
: Obtain the DER encoded form as a byte array.
Comparing oids
Comparing a parsed oid to a static oid is probably the most common
thing done with oids in your code. The oid!
macro can be used in expression positions for
this purpose. For example
use der_parser::{oid, oid::Oid}; const SOME_STATIC_OID: Oid<'static> = oid!(1.2.456); assert_eq!(some_oid, SOME_STATIC_OID)
To get a relative Oid use oid!(rel 1.2)
.
Because of limitations for procedural macros (rust issue)
and constants used in patterns (rust issue)
the oid
macro can not directly be used in patterns, also not through constants.
You can do this, though:
const SOME_OID: Oid<'static> = oid!(1.2.456); if some_oid == SOME_OID || some_oid == oid!(1.2.456) { println!("match"); } // Alternatively, compare the DER encoded form directly: const SOME_OID_RAW: &[u8] = &oid!(raw 1.2.456); match some_oid.bytes() { SOME_OID_RAW => println!("match"), _ => panic!("no match"), }
Attention, be aware that the latter version might not handle the case of a relative oid correctly. An extra check might be necessary.
Structs
Object ID (OID) representation which can be relative or non-relative. An example for an oid in string representation is “1.2.840.113549.1.1.5”.