1use super::Writer;
4use crate::Result;
5use core::fmt;
6use pem_rfc7468::{Encoder, LineEnding};
7
8pub struct PemWriter<'w>(Encoder<'static, 'w>);
10
11impl<'w> PemWriter<'w> {
12 pub fn new(
19 type_label: &'static str,
20 line_ending: LineEnding,
21 out: &'w mut [u8],
22 ) -> Result<Self> {
23 Ok(Self(Encoder::new(type_label, line_ending, out)?))
24 }
25
26 #[must_use]
29 pub fn type_label(&self) -> &'static str {
30 self.0.type_label()
31 }
32
33 pub fn finish(self) -> Result<usize> {
40 Ok(self.0.finish()?)
41 }
42}
43
44impl Writer for PemWriter<'_> {
45 fn write(&mut self, slice: &[u8]) -> Result<()> {
46 self.0.encode(slice)?;
47 Ok(())
48 }
49}
50
51impl fmt::Debug for PemWriter<'_> {
52 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
53 f.debug_struct("PemWriter").finish_non_exhaustive()
54 }
55}