init
This commit is contained in:
commit
1b7912850a
5 changed files with 59 additions and 0 deletions
2
.gitignore
vendored
Normal file
2
.gitignore
vendored
Normal file
|
@ -0,0 +1,2 @@
|
||||||
|
/target
|
||||||
|
Cargo.lock
|
16
Cargo.toml
Normal file
16
Cargo.toml
Normal file
|
@ -0,0 +1,16 @@
|
||||||
|
[package]
|
||||||
|
name = "rust_comptime_encryption_example"
|
||||||
|
version = "0.1.0"
|
||||||
|
edition = "2018"
|
||||||
|
|
||||||
|
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||||
|
|
||||||
|
[dependencies]
|
||||||
|
bincode = "1.3.3"
|
||||||
|
serde = "1.0.130"
|
||||||
|
|
||||||
|
[build-dependencies]
|
||||||
|
base64 = "0.13.0"
|
||||||
|
bincode = "1.3.3"
|
||||||
|
serde = "1.0.130"
|
||||||
|
serde_json = "1.0.68"
|
27
build.rs
Normal file
27
build.rs
Normal file
|
@ -0,0 +1,27 @@
|
||||||
|
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");
|
||||||
|
}
|
4
enc_data.json
Normal file
4
enc_data.json
Normal file
|
@ -0,0 +1,4 @@
|
||||||
|
{
|
||||||
|
"foo": "bar",
|
||||||
|
"some_key": "some_data"
|
||||||
|
}
|
10
src/main.rs
Normal file
10
src/main.rs
Normal file
|
@ -0,0 +1,10 @@
|
||||||
|
use std::collections::HashMap;
|
||||||
|
|
||||||
|
const ENC_DATA: &[u8] = include_bytes!(concat!(env!("OUT_DIR"), "/enc_data.bin"));
|
||||||
|
|
||||||
|
fn main() {
|
||||||
|
let enc_data = bincode::deserialize::<HashMap<String, String>>(ENC_DATA)
|
||||||
|
.expect("Failed to deserialize enc_data");
|
||||||
|
|
||||||
|
dbg!(enc_data);
|
||||||
|
}
|
Loading…
Reference in a new issue