forge
Explore
Log in

Don't you dare go Hollow

edith_codecs

Clone
★ 0

0 watching0 forksRust381.5 MiBcdccbc2Tahinli12 hours ago4263 commits

main.rs67 lines, 1.6 KiBHistoryRawDownload
1#![forbid(unsafe_code)]
2
3mod audio;
4mod demux;
5mod encode_audio;
6mod encode_video;
7mod image;
8mod mux;
9mod subs;
10mod video;
11
12use sha2::{Digest, Sha256};
13use std::fmt::Display;
14use std::path::Path;
15
16const 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
27pub 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
33pub fn text(case: &str, line: impl Display) {
34 println!("{case}\t{line}");
35}
36
37pub fn error(case: &str, err: impl Display) {
38 println!("{case}\tERR {err}");
39}
40
41pub 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
47pub fn name(path: &Path) -> String {
48 let root = ec_testkit::root();
49 path.strip_prefix(&root).unwrap_or(path).display().to_string()
50}
51
52fn 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}