| 1 | #![forbid(unsafe_code)] |
| 2 | |
| 3 | mod audio; |
| 4 | mod demux; |
| 5 | mod encode_audio; |
| 6 | mod encode_video; |
| 7 | mod image; |
| 8 | mod mux; |
| 9 | mod subs; |
| 10 | mod video; |
| 11 | |
| 12 | use sha2::{Digest, Sha256}; |
| 13 | use std::fmt::Display; |
| 14 | use std::path::Path; |
| 15 | |
| 16 | const DOMAINS: [(&str, fn()); 8] = [ |
| 17 | ("video", video::run), |
| 18 | ("audio", audio::run), |
| 19 | ("image", image::run), |
| 20 | ("subs", subs::run), |
| 21 | ("demux", demux::run), |
| 22 | ("mux", mux::run), |
| 23 | ("encode_video", encode_video::run), |
| 24 | ("encode_audio", encode_audio::run), |
| 25 | ]; |
| 26 | |
| 27 | pub fn hash(case: &str, bytes: &[u8]) { |
| 28 | let digest = Sha256::digest(bytes); |
| 29 | let hex: String = digest.iter().map(|b| format!("{b:02x}")).collect(); |
| 30 | println!("{case}\t{hex}"); |
| 31 | } |
| 32 | |
| 33 | pub fn text(case: &str, line: impl Display) { |
| 34 | println!("{case}\t{line}"); |
| 35 | } |
| 36 | |
| 37 | pub fn error(case: &str, err: impl Display) { |
| 38 | println!("{case}\tERR {err}"); |
| 39 | } |
| 40 | |
| 41 | pub fn guard(case: &str, f: impl FnOnce()) { |
| 42 | if std::panic::catch_unwind(std::panic::AssertUnwindSafe(f)).is_err() { |
| 43 | text(case, "PANIC"); |
| 44 | } |
| 45 | } |
| 46 | |
| 47 | pub fn name(path: &Path) -> String { |
| 48 | let root = ec_testkit::root(); |
| 49 | path.strip_prefix(&root).unwrap_or(path).display().to_string() |
| 50 | } |
| 51 | |
| 52 | fn main() { |
| 53 | std::panic::set_hook(Box::new(|_| {})); |
| 54 | let wanted = std::env::args().nth(1).unwrap_or_default(); |
| 55 | let mut ran = false; |
| 56 | for (domain, run) in DOMAINS { |
| 57 | if wanted == "all" || wanted == domain { |
| 58 | run(); |
| 59 | ran = true; |
| 60 | } |
| 61 | } |
| 62 | if !ran { |
| 63 | let names: Vec<&str> = DOMAINS.iter().map(|(domain, _)| *domain).collect(); |
| 64 | eprintln!("usage: golden <all|{}>", names.join("|")); |
| 65 | std::process::exit(2); |
| 66 | } |
| 67 | } |