rust_comptime_encryption_ex.../build.rs

28 lines
914 B
Rust

use std::{
collections::HashMap,
fs::{self, File},
io::Read,
path::Path,
};
fn main() {
println!("cargo:rerun-if-changed=enc_data.json");
let mut file = File::open("enc_data.json").expect("Failed to open enc_data.json");
let mut content = vec![];
file.read_to_end(&mut content)
.expect("Failed to read enc_data.json");
let deserialized = serde_json::from_slice::<HashMap<String, String>>(&content)
.expect("Failed to deserialize enc_data.json");
let encrypted = deserialized
.into_iter()
.map(|(k, v)| (k, base64::encode(v)))
.collect::<HashMap<_, _>>();
let serialized =
bincode::serialize(&encrypted).expect("Failed to seralize enc_data.json to bincode");
let out_path = Path::new(&std::env::var("OUT_DIR").unwrap()).join("enc_data.bin");
fs::write(out_path, serialized).expect("Failed to write outfile");
}