Struct x509_parser::extensions::X509Extension
source · pub struct X509Extension<'a> {
pub oid: Oid<'a>,
pub critical: bool,
pub value: &'a [u8],
/* private fields */
}
Expand description
X.509 version 3 extension
X.509 extensions allow adding attributes to objects like certificates or revocation lists.
Each extension in a certificate is designated as either critical or non-critical. A certificate using system MUST reject the certificate if it encounters a critical extension it does not recognize; however, a non-critical extension MAY be ignored if it is not recognized.
Each extension includes an OID and an ASN.1 structure. When an extension appears in a certificate, the OID appears as the field extnID and the corresponding ASN.1 encoded structure is the value of the octet string extnValue. A certificate MUST NOT include more than one instance of a particular extension.
When parsing an extension, the global extension structure (described above) is parsed,
and the object is returned if it succeeds.
During this step, it also attempts to parse the content of the extension, if known.
The returned object has a
X509Extension::parsed_extension()
method. The returned
enum is either a known extension, or the special value ParsedExtension::UnsupportedExtension
.
§Example
use x509_parser::prelude::FromDer;
use x509_parser::extensions::{X509Extension, ParsedExtension};
static DER: &[u8] = &[
0x30, 0x1D, 0x06, 0x03, 0x55, 0x1D, 0x0E, 0x04, 0x16, 0x04, 0x14, 0xA3, 0x05, 0x2F, 0x18,
0x60, 0x50, 0xC2, 0x89, 0x0A, 0xDD, 0x2B, 0x21, 0x4F, 0xFF, 0x8E, 0x4E, 0xA8, 0x30, 0x31,
0x36 ];
let res = X509Extension::from_der(DER);
match res {
Ok((_rem, ext)) => {
println!("Extension OID: {}", ext.oid);
println!(" Critical: {}", ext.critical);
let parsed_ext = ext.parsed_extension();
assert!(!parsed_ext.unsupported());
assert!(parsed_ext.error().is_none());
if let ParsedExtension::SubjectKeyIdentifier(key_id) = parsed_ext {
assert!(key_id.0.len() > 0);
} else {
panic!("Extension has wrong type");
}
},
_ => panic!("x509 extension parsing failed: {:?}", res),
}
Fields§
§oid: Oid<'a>
OID describing the extension content
critical: bool
Boolean value describing the ‘critical’ attribute of the extension
An extension includes the boolean critical, with a default value of FALSE.
value: &'a [u8]
Raw content of the extension
Implementations§
source§impl<'a> X509Extension<'a>
impl<'a> X509Extension<'a>
sourcepub const fn new(
oid: Oid<'a>,
critical: bool,
value: &'a [u8],
parsed_extension: ParsedExtension<'a>,
) -> X509Extension<'a>
pub const fn new( oid: Oid<'a>, critical: bool, value: &'a [u8], parsed_extension: ParsedExtension<'a>, ) -> X509Extension<'a>
Creates a new extension with the provided values.
sourcepub fn parsed_extension(&self) -> &ParsedExtension<'a>
pub fn parsed_extension(&self) -> &ParsedExtension<'a>
Return the extension type or UnsupportedExtension
if the extension is not implemented.
Trait Implementations§
source§impl<'a> Clone for X509Extension<'a>
impl<'a> Clone for X509Extension<'a>
source§fn clone(&self) -> X509Extension<'a>
fn clone(&self) -> X509Extension<'a>
1.0.0 · source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read moresource§impl<'a> Debug for X509Extension<'a>
impl<'a> Debug for X509Extension<'a>
source§impl<'a> FromDer<'a, X509Error> for X509Extension<'a>
impl<'a> FromDer<'a, X509Error> for X509Extension<'a>
Extension ::= SEQUENCE { extnID OBJECT IDENTIFIER, critical BOOLEAN DEFAULT FALSE, extnValue OCTET STRING }
source§fn from_der(i: &'a [u8]) -> X509Result<'_, Self>
fn from_der(i: &'a [u8]) -> X509Result<'_, Self>
source§impl<'a> Parser<&'a [u8], X509Extension<'a>, X509Error> for X509ExtensionParser
impl<'a> Parser<&'a [u8], X509Extension<'a>, X509Error> for X509ExtensionParser
source§fn parse(
&mut self,
input: &'a [u8],
) -> IResult<&'a [u8], X509Extension<'a>, X509Error>
fn parse( &mut self, input: &'a [u8], ) -> IResult<&'a [u8], X509Extension<'a>, X509Error>
Result
containing
either the remaining input and the output value, or an errorsource§fn flat_map<G, H, O2>(self, g: G) -> FlatMap<Self, G, O>
fn flat_map<G, H, O2>(self, g: G) -> FlatMap<Self, G, O>
source§fn and_then<G, O2>(self, g: G) -> AndThen<Self, G, O>
fn and_then<G, O2>(self, g: G) -> AndThen<Self, G, O>
source§fn and<G, O2>(self, g: G) -> And<Self, G>
fn and<G, O2>(self, g: G) -> And<Self, G>
source§impl<'a> PartialEq for X509Extension<'a>
impl<'a> PartialEq for X509Extension<'a>
impl<'a> StructuralPartialEq for X509Extension<'a>
Auto Trait Implementations§
impl<'a> Freeze for X509Extension<'a>
impl<'a> RefUnwindSafe for X509Extension<'a>
impl<'a> Send for X509Extension<'a>
impl<'a> Sync for X509Extension<'a>
impl<'a> Unpin for X509Extension<'a>
impl<'a> UnwindSafe for X509Extension<'a>
Blanket Implementations§
source§impl<'a, T, E> AsTaggedExplicit<'a, E> for Twhere
T: 'a,
impl<'a, T, E> AsTaggedExplicit<'a, E> for Twhere
T: 'a,
source§impl<'a, T, E> AsTaggedImplicit<'a, E> for Twhere
T: 'a,
impl<'a, T, E> AsTaggedImplicit<'a, E> for Twhere
T: 'a,
source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
source§unsafe fn clone_to_uninit(&self, dst: *mut T)
unsafe fn clone_to_uninit(&self, dst: *mut T)
clone_to_uninit
)