Joel Galenson | 1d90639 | 2021-08-11 15:58:47 +0000 | [diff] [blame^] | 1 | use crate::error::X509Result; |
| 2 | |
| 3 | /// Parse a DER-encoded object, and return the remaining of the input and the built |
| 4 | /// object. |
| 5 | /// |
| 6 | /// The returned object uses zero-copy, and so has the same lifetime as the input. |
| 7 | /// |
| 8 | /// Note that only parsing is done, not validation (see the [`Validate`](crate::validate::Validate) trait). |
| 9 | /// |
| 10 | /// # Example |
| 11 | /// |
| 12 | /// To parse a certificate and print the subject and issuer: |
| 13 | /// |
| 14 | /// ```rust |
| 15 | /// # use x509_parser::prelude::*; |
| 16 | /// # |
| 17 | /// # static DER: &'static [u8] = include_bytes!("../assets/IGC_A.der"); |
| 18 | /// # |
| 19 | /// # fn main() { |
| 20 | /// let res = X509Certificate::from_der(DER); |
| 21 | /// match res { |
| 22 | /// Ok((_rem, x509)) => { |
| 23 | /// let subject = x509.subject(); |
| 24 | /// let issuer = x509.issuer(); |
| 25 | /// println!("X.509 Subject: {}", subject); |
| 26 | /// println!("X.509 Issuer: {}", issuer); |
| 27 | /// }, |
| 28 | /// _ => panic!("x509 parsing failed: {:?}", res), |
| 29 | /// } |
| 30 | /// # } |
| 31 | /// ``` |
| 32 | |
| 33 | pub trait FromDer<'a>: Sized { |
| 34 | /// Attempt to parse input bytes into a DER object |
| 35 | fn from_der(bytes: &'a [u8]) -> X509Result<'a, Self>; |
| 36 | } |