/rust/registry/src/index.crates.io-1949cf8c6b5b557f/der-0.7.10/src/writer.rs
Line | Count | Source |
1 | | //! Writer trait. |
2 | | |
3 | | #[cfg(feature = "pem")] |
4 | | pub(crate) mod pem; |
5 | | pub(crate) mod slice; |
6 | | |
7 | | use crate::Result; |
8 | | |
9 | | #[cfg(feature = "std")] |
10 | | use std::io; |
11 | | |
12 | | /// Writer trait which outputs encoded DER. |
13 | | pub trait Writer { |
14 | | /// Write the given DER-encoded bytes as output. |
15 | | fn write(&mut self, slice: &[u8]) -> Result<()>; |
16 | | |
17 | | /// Write a single byte. |
18 | 0 | fn write_byte(&mut self, byte: u8) -> Result<()> { |
19 | 0 | self.write(&[byte]) |
20 | 0 | } |
21 | | } |
22 | | |
23 | | #[cfg(feature = "std")] |
24 | | impl<W: io::Write> Writer for W { |
25 | | fn write(&mut self, slice: &[u8]) -> Result<()> { |
26 | | <Self as io::Write>::write(self, slice)?; |
27 | | Ok(()) |
28 | | } |
29 | | } |