use std::io::{Result, Write}; use crate::TLockAgeError; /// Writer that applies the age ASCII armor format. pub struct ArmoredWriter { inner: age::armor::ArmoredWriter, } impl ArmoredWriter { /// Wraps the given output in an ArmoredWriter. pub fn wrap_output(w: W) -> anyhow::Result { let inner = age::armor::ArmoredWriter::wrap_output(w, age::armor::Format::AsciiArmor) .map_err(TLockAgeError::IO)?; Ok(Self { inner }) } /// Writes the end marker of the age file, if armoring was enabled. /// /// You MUST call finish when you are done writing, in order to `finish` the armoring process. Failing to call `finish` will result in a truncated file that that will fail to decrypt. pub fn finish(self) -> Result { self.inner.finish() } } impl Write for ArmoredWriter { fn write(&mut self, buf: &[u8]) -> Result { self.inner.write(buf) } fn flush(&mut self) -> Result<()> { self.inner.flush() } }