This commit is contained in:
nora 2024-08-23 13:57:28 +02:00
parent cd3628e168
commit dd029f03bd
6 changed files with 328 additions and 0 deletions

View file

@ -0,0 +1,34 @@
use std::{
error::Error,
io::{BufReader, Read, Write},
};
use clap::Parser;
#[derive(clap::Parser)]
struct Args {
file: Option<String>,
}
fn main() -> Result<(), Box<dyn Error>> {
let args = Args::parse();
match args.file {
None => unpem(&mut std::io::stdin().lock()),
Some(file) => {
let file = std::fs::File::open(file)?;
let mut file = BufReader::new(file);
unpem(&mut file)
}
}
}
fn unpem(input: &mut dyn Read) -> Result<(), Box<dyn Error>> {
let mut v = Vec::new();
input.read_to_end(&mut v)?;
let pem = pem::parse(v)?;
std::io::stdout().write_all(pem.contents())?;
Ok(())
}