Skip to main content

der/
writer.rs

1//! Writer trait.
2
3#[cfg(feature = "pem")]
4pub(crate) mod pem;
5pub(crate) mod slice;
6
7use crate::Result;
8
9#[cfg(feature = "std")]
10use std::io;
11
12/// Writer trait which outputs encoded DER.
13pub trait Writer {
14    /// Write the given DER-encoded bytes as output.
15    ///
16    /// # Errors
17    /// If the write operation failed.
18    fn write(&mut self, slice: &[u8]) -> Result<()>;
19
20    /// Write a single byte.
21    ///
22    /// # Errors
23    /// If the write operation failed.
24    fn write_byte(&mut self, byte: u8) -> Result<()> {
25        self.write(&[byte])
26    }
27}
28
29#[cfg(feature = "std")]
30impl<W: io::Write> Writer for W {
31    fn write(&mut self, slice: &[u8]) -> Result<()> {
32        <Self as io::Write>::write(self, slice)?;
33        Ok(())
34    }
35}