summaryrefslogtreecommitdiffstats
path: root/vendor/der/src/writer/pem.rs
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-05-04 12:47:55 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-05-04 12:47:55 +0000
commit2aadc03ef15cb5ca5cc2af8a7c08e070742f0ac4 (patch)
tree033cc839730fda84ff08db877037977be94e5e3a /vendor/der/src/writer/pem.rs
parentInitial commit. (diff)
downloadcargo-upstream.tar.xz
cargo-upstream.zip
Adding upstream version 0.70.1+ds1.upstream/0.70.1+ds1upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'vendor/der/src/writer/pem.rs')
-rw-r--r--vendor/der/src/writer/pem.rs41
1 files changed, 41 insertions, 0 deletions
diff --git a/vendor/der/src/writer/pem.rs b/vendor/der/src/writer/pem.rs
new file mode 100644
index 0000000..87a6f8f
--- /dev/null
+++ b/vendor/der/src/writer/pem.rs
@@ -0,0 +1,41 @@
+//! Streaming PEM writer.
+
+use super::Writer;
+use crate::Result;
+use pem_rfc7468::{Encoder, LineEnding};
+
+/// `Writer` type which outputs PEM-encoded data.
+pub struct PemWriter<'w>(Encoder<'static, 'w>);
+
+impl<'w> PemWriter<'w> {
+ /// Create a new PEM writer which outputs into the provided buffer.
+ ///
+ /// Uses the default 64-character line wrapping.
+ 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)?))
+ }
+
+ /// Get the PEM label which will be used in the encapsulation boundaries
+ /// for this document.
+ pub fn type_label(&self) -> &'static str {
+ self.0.type_label()
+ }
+
+ /// Finish encoding PEM, writing the post-encapsulation boundary.
+ ///
+ /// On success, returns the total number of bytes written to the output buffer.
+ 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(())
+ }
+}