trussed_core/client/
certificate.rs

1use super::{ClientError, ClientResult, PollClient};
2use crate::{
3    api::{reply, request},
4    types::{CertId, Location, Message},
5};
6
7/// Read/Write + Delete certificates
8pub trait CertificateClient: PollClient {
9    fn delete_certificate(
10        &mut self,
11        id: CertId,
12    ) -> ClientResult<'_, reply::DeleteCertificate, Self> {
13        self.request(request::DeleteCertificate { id })
14    }
15
16    fn read_certificate(&mut self, id: CertId) -> ClientResult<'_, reply::ReadCertificate, Self> {
17        self.request(request::ReadCertificate { id })
18    }
19
20    /// Currently, this writes the cert (assumed but not verified to be DER)
21    /// as-is. It might make sense to add attributes (such as "deletable").
22    /// (On the other hand, the attn CA certs are not directly accessible to clients,
23    /// and generated attn certs can be regenerated).
24    fn write_certificate(
25        &mut self,
26        location: Location,
27        der: &[u8],
28    ) -> ClientResult<'_, reply::WriteCertificate, Self> {
29        let der = Message::from_slice(der).map_err(|_| ClientError::DataTooLarge)?;
30        self.request(request::WriteCertificate { location, der })
31    }
32}