use crate::{
asn1::{
Asn1DecodeWrapper, Asn1EncodeWrapper, BitString, Len, SEQUENCE_TAG, asn1_writer,
decode_asn1_tlv,
},
codec::{Decode, DecodeWrapper, Encode, EncodeWrapper, GenericCodec},
x509::{AlgorithmIdentifier, TbsCertList, X509Error},
};
#[derive(Debug, PartialEq)]
pub struct Crl<'bytes> {
pub tbs_cert_list: TbsCertList<'bytes>,
pub signature_algorithm: AlgorithmIdentifier<'bytes>,
pub signature_value: BitString<&'bytes [u8]>,
}
impl<'de> Decode<'de, GenericCodec<Asn1DecodeWrapper, ()>> for Crl<'de> {
#[inline]
fn decode(dw: &mut DecodeWrapper<'de, Asn1DecodeWrapper>) -> crate::Result<Self> {
let (SEQUENCE_TAG, _, value, rest) = decode_asn1_tlv(dw.bytes)? else {
return Err(X509Error::InvalidCrl.into());
};
dw.bytes = value;
let tbs_cert_list = TbsCertList::decode(dw)?;
let signature_algorithm = AlgorithmIdentifier::decode(dw)?;
let signature_value = BitString::decode(dw)?;
dw.bytes = rest;
Ok(Self { signature_algorithm, signature_value, tbs_cert_list })
}
}
impl<'bytes> Encode<GenericCodec<(), Asn1EncodeWrapper>> for Crl<'bytes> {
#[inline]
fn encode(&self, ew: &mut EncodeWrapper<'_, Asn1EncodeWrapper>) -> crate::Result<()> {
asn1_writer(ew, Len::MAX_THREE_BYTES, SEQUENCE_TAG, |local_ew| {
self.tbs_cert_list.encode(local_ew)?;
self.signature_algorithm.encode(local_ew)?;
self.signature_value.encode(local_ew)?;
Ok(())
})
}
}