Interplane page as plain text, for reading tools and agents. English is the reference text: translate it with your own tool. Text in backticks and in ``` blocks (commands, fingerprints, file names) and link targets in <...> are exact: copy them, never translate them. Page: /drakestapleton/aienux/blob/main/vendor/der/src/writer/pem.rs # aienux Aienux, the AienOS kernel: boot, scheduling, IPC and capability boundaries. Pre-alpha; host, emulator and physical evidence are labelled separately. Brought by drakestapleton Sign in to star 0 stars 0 watching About Files History Releases Proposed changes Issues For developers branch `main` Branches Tags History `aienux / vendor / der / src / writer / pem.rs` 41 lines ยท 1135 bytes Raw Blame History 1 //! Streaming PEM writer. 2 3 use super::Writer; 4 use crate::Result; 5 use pem_rfc7468::{Encoder, LineEnding}; 6 7 /// `Writer` type which outputs PEM-encoded data. 8 pub struct PemWriter<'w>(Encoder<'static, 'w>); 9 10 impl<'w> PemWriter<'w> { 11 /// Create a new PEM writer which outputs into the provided buffer. 12 /// 13 /// Uses the default 64-character line wrapping. 14 pub fn new( 15 type_label: &'static str, 16 line_ending: LineEnding, 17 out: &'w mut [u8], 18 ) -> Result { 19 Ok(Self(Encoder::new(type_label, line_ending, out)?)) 20 } 21 22 /// Get the PEM label which will be used in the encapsulation boundaries 23 /// for this document. 24 pub fn type_label(&self) -> &'static str { 25 self.0.type_label() 26 } 27 28 /// Finish encoding PEM, writing the post-encapsulation boundary. 29 /// 30 /// On success, returns the total number of bytes written to the output buffer. 31 pub fn finish(self) -> Result { 32 Ok(self.0.finish()?) 33 } 34 } 35 36 impl Writer for PemWriter<'_> { 37 fn write(&mut self, slice: &[u8]) -> Result<()> { 38 self.0.encode(slice)?; 39 Ok(()) 40 } 41 }