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