use std::{
io::{self, copy, Read, Write},
process::{Command, Stdio},
};
pub fn sign<R: Read + Send, W: Write>(mut mail: R, mut signature: W) -> io::Result<()> {
let mut gpg = Command::new("gpg")
.args(["--armor", "--detach-sign"])
.stdin(Stdio::piped())
.stdout(Stdio::piped())
.spawn()?;
{
let mut stdin = gpg
.stdin
.take()
.expect("gpg stdin was not captured. should not happen");
copy(&mut mail, &mut stdin)?;
}
signature.write_all(&gpg.wait_with_output()?.stdout)?;
Ok(())
}