use core::fmt;
use mbedtls_sys::*;
#[cfg(not(feature = "std"))]
use crate::alloc_prelude::*;
use crate::error::{IntoResult, Result};
use crate::hash::Type as MdType;
define!(
#[c_ty(x509_crl)]
struct Crl;
pub const new: fn() -> Self = x509_crl_init;
const drop: fn(&mut Self) = x509_crl_free;
impl<'a> Into<ptr> {}
);
impl Crl {
pub fn push_from_der(&mut self, der: &[u8]) -> Result<()> {
unsafe {
x509_crl_parse_der(&mut self.inner, der.as_ptr(), der.len())
.into_result()
.map(|_| ())
}
}
pub fn push_from_pem(&mut self, pem: &[u8]) -> Result<()> {
unsafe {
x509_crl_parse(&mut self.inner, pem.as_ptr(), pem.len())
.into_result()
.map(|_| ())
}
}
pub fn issuer(&self) -> Result<String> {
crate::private::alloc_string_repeat(|buf, size| unsafe { x509_dn_gets(buf, size, &self.inner.issuer) })
}
pub fn issuer_raw(&self) -> Result<Vec<u8>> {
Ok(super::x509_buf_to_vec(&self.inner.issuer_raw))
}
pub fn tbs_raw(&self) -> Result<Vec<u8>> {
Ok(super::x509_buf_to_vec(&self.inner.tbs))
}
pub fn signature(&self) -> Result<Vec<u8>> {
Ok(super::x509_buf_to_vec(&self.inner.sig))
}
pub fn digest_type(&self) -> MdType {
MdType::from(self.inner.sig_md)
}
}
impl fmt::Debug for Crl {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
match crate::private::alloc_string_repeat(|buf, size| unsafe {
x509_crl_info(buf, size, b"\0".as_ptr() as *const _, &self.inner)
}) {
Err(_) => Err(fmt::Error),
Ok(s) => f.write_str(&s),
}
}
}