pub fn parse_certificate<'a>(certificate: &'a [u8]) -> Result<X509Certificate<'a>, Error> {
    use core::convert::TryFrom as _;
    let das = DataAlgorithmSignature::try_from(certificate)?;
    untrusted::Input::from(&*das.inner()).read_all(Error::BadDER, |input| {
        // We require extensions, which means we require version 3
        if input.read_bytes(5).map_err(|_| Error::BadDER)?
            != untrusted::Input::from(&[160, 3, 2, 1, 2])
        {
            return Err(Error::UnsupportedCertVersion);
        }
        // serialNumber
        let serial = der::positive_integer(input)
            .map_err(|_| Error::BadDER)?
            .big_endian_without_leading_zero();
        // signature
        if das::read_sequence(input)?.as_slice_less_safe() != das.algorithm() {
            // signature algorithms don’t match
            return Err(Error::SignatureAlgorithmMismatch);
        }
        // issuer
        let issuer = das::read_sequence(input)?.as_slice_less_safe();
        // validity
        let (not_before, not_after) =
            der::nested(input, der::Tag::Sequence, Error::BadDER, |input| {
                Ok((time::read_time(input)?, time::read_time(input)?))
            })?;
        if not_before > not_after {
            return Err(Error::InvalidCertValidity);
        }
        let subject = das::read_sequence(input)?.as_slice_less_safe();
        let subject_public_key_info = SubjectPublicKeyInfo::read(input)?;
        // subjectUniqueId and issuerUniqueId are unsupported

        let extensions = if !input.at_end() {
            let tag = der::Tag::ContextSpecificConstructed3;
            der::nested(input, tag, Error::BadDER, |input| {
                der::nested(input, der::Tag::Sequence, Error::BadDER, |input| {
                    if input.at_end() {
                        return Err(Error::BadDER);
                    }
                    Ok(ExtensionIterator(SequenceIterator::read(input)))
                })
            })
        } else {
            Ok(ExtensionIterator(SequenceIterator::read(input)))
        }?;

        Ok(X509Certificate {
            das,
            serial,
            subject,
            not_before,
            not_after,
            issuer,
            subject_public_key_info,
            extensions,
        })
    })
}
/// Extracts the algorithm id and public key from a certificate
Extracts the algorithm id and public key from a certificate
Extracts the algorithm id and public key from a certificate
pub fn parse_certificate<'a>(certificate: &'a [u8]) -> Result<X509Certificate<'a>, Error> {
    use core::convert::TryFrom as _;
    let das = DataAlgorithmSignature::try_from(certificate)?;
    untrusted::Input::from(&*das.inner()).read_all(Error::BadDER, |input| {
        // We require extensions, which means we require version 3
        if input.read_bytes(5).map_err(|_| Error::BadDER)?
            != untrusted::Input::from(&[160, 3, 2, 1, 2])
        {
            return Err(Error::UnsupportedCertVersion);
        }
        // serialNumber
        let serial = der::positive_integer(input)
            .map_err(|_| Error::BadDER)?
            .big_endian_without_leading_zero();
        // signature
        if das::read_sequence(input)?.as_slice_less_safe() != das.algorithm() {
            // signature algorithms don’t match
            return Err(Error::SignatureAlgorithmMismatch);
        }
        // issuer
        let issuer = das::read_sequence(input)?.as_slice_less_safe();
        // validity
        let (not_before, not_after) =
            der::nested(input, der::Tag::Sequence, Error::BadDER, |input| {
                Ok((time::read_time(input)?, time::read_time(input)?))
            })?;
        if not_before > not_after {
            return Err(Error::InvalidCertValidity);
        }
        let subject = das::read_sequence(input)?.as_slice_less_safe();
        let subject_public_key_info = SubjectPublicKeyInfo::read(input)?;
        // subjectUniqueId and issuerUniqueId are unsupported
        let extensions = if !input.at_end() {
            let tag = der::Tag::ContextSpecificConstructed3;
            der::nested(input, tag, Error::BadDER, |input| {
                der::nested(input, der::Tag::Sequence, Error::BadDER, |input| {
                    if input.at_end() {
                        return Err(Error::BadDER);
                    }
                    Ok(ExtensionIterator(SequenceIterator::read(input)))
                })
            })
        } else {
            Ok(ExtensionIterator(SequenceIterator::read(input)))
        }?;
        Ok(X509Certificate {
            das,
            serial,
            subject,
            not_before,
            not_after,
            issuer,
            subject_public_key_info,
            extensions,
        })
    })
}
pub fn parse_certificate < ' a > ( certificate : & ' a [ u8 ] ) -> Result < X509Certificate < ' a > , Error > { use core :: convert :: TryFrom as _ ; let das = DataAlgorithmSignature :: try_from ( certificate ) ? ; untrusted :: Input :: from ( & * das . inner ( ) ) . read_all ( Error :: BadDER , | input | { // We require extensions, which means we require version 3 if input . read_bytes ( 5 ) . map_err ( | _ | Error :: BadDER ) ? != untrusted :: Input :: from ( & [ 160 , 3 , 2 , 1 , 2 ] ) { return Err ( Error :: UnsupportedCertVersion ) ; } // serialNumber let serial = der :: positive_integer ( input ) . map_err ( | _ | Error :: BadDER ) ? . big_endian_without_leading_zero ( ) ; // signature if das :: read_sequence ( input ) ? . as_slice_less_safe ( ) != das . algorithm ( ) { // signature algorithms don’t match return Err ( Error :: SignatureAlgorithmMismatch ) ; } // issuer let issuer = das :: read_sequence ( input ) ? . as_slice_less_safe ( ) ; // validity let ( not_before , not_after ) = der :: nested ( input , der :: Tag :: Sequence , Error :: BadDER , | input | { Ok ( ( time :: read_time ( input ) ? , time :: read_time ( input ) ? ) ) } ) ? ; if not_before > not_after { return Err ( Error :: InvalidCertValidity ) ; } let subject = das :: read_sequence ( input ) ? . as_slice_less_safe ( ) ; let subject_public_key_info = SubjectPublicKeyInfo :: read ( input ) ? ; // subjectUniqueId and issuerUniqueId are unsupported let extensions = if ! input . at_end ( ) { let tag = der :: Tag :: ContextSpecificConstructed3 ; der :: nested ( input , tag , Error :: BadDER , | input | { der :: nested ( input , der :: Tag :: Sequence , Error :: BadDER , | input | { if input . at_end ( ) { return Err ( Error :: BadDER ) ; } Ok ( ExtensionIterator ( SequenceIterator :: read ( input ) ) ) } ) } ) } else { Ok ( ExtensionIterator ( SequenceIterator :: read ( input ) ) ) } ? ; Ok ( X509Certificate { das , serial , subject , not_before , not_after , issuer , subject_public_key_info , extensions , } ) } ) }
Extracts the algorithm id and public key from a certificate
Extracts the algorithm id and public key from a certificate
certificate
&'a [u8]
certificate
&'a [u8]