use std::io::Read;
use logicaffeine_kernel::certificate::{recheck, Certificate};
fn main() {
let json = match read_input() {
Ok(s) => s,
Err(e) => {
eprintln!("REJECTED: could not read certificate: {}", e);
std::process::exit(1);
}
};
let cert: Certificate = match serde_json::from_str(&json) {
Ok(c) => c,
Err(e) => {
eprintln!("REJECTED: malformed certificate: {}", e);
std::process::exit(1);
}
};
match recheck(&cert) {
Ok(()) => {
println!("VERIFIED");
std::process::exit(0);
}
Err(e) => {
eprintln!("REJECTED: {}", e);
std::process::exit(1);
}
}
}
fn read_input() -> std::io::Result<String> {
if let Some(path) = std::env::args().nth(1) {
std::fs::read_to_string(path)
} else {
let mut buf = String::new();
std::io::stdin().read_to_string(&mut buf)?;
Ok(buf)
}
}