der/writer/
pem.rs
1use super::Writer;
4use crate::Result;
5use pem_rfc7468::{Encoder, LineEnding};
6
7pub struct PemWriter<'w>(Encoder<'static, 'w>);
9
10impl<'w> PemWriter<'w> {
11 pub fn new(
15 type_label: &'static str,
16 line_ending: LineEnding,
17 out: &'w mut [u8],
18 ) -> Result<Self> {
19 Ok(Self(Encoder::new(type_label, line_ending, out)?))
20 }
21
22 pub fn type_label(&self) -> &'static str {
25 self.0.type_label()
26 }
27
28 pub fn finish(self) -> Result<usize> {
32 Ok(self.0.finish()?)
33 }
34}
35
36impl Writer for PemWriter<'_> {
37 fn write(&mut self, slice: &[u8]) -> Result<()> {
38 self.0.encode(slice)?;
39 Ok(())
40 }
41}