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