#proc-macro #macro #encryption #compiled #embed #binary #byte

include-crypt-bytes

Rust macro to embed encrypted files in compiled binary

4 releases

0.1.3 Nov 23, 2022
0.1.2 Jul 31, 2022
0.1.1 Jul 31, 2022
0.1.0 Jul 31, 2022

#573 in Procedural macros

Download history 30/week @ 2024-04-01 19/week @ 2024-04-08 2/week @ 2024-04-22 1/week @ 2024-05-20 1/week @ 2024-05-27 7/week @ 2024-06-03

95 downloads per month

MIT/Apache

10KB
89 lines

include-crypt-bytes

Procedural macro to embed encrypted binary data in compiled binaries.

The macro works similarly to std::include_str, but instead of embedding the UTF-8 string, it embeds encrypted [u8] array. Encryption uses the chacha20poly1305 crate.

Examples

// CONFIG_PASSWORD is the environment variable set to the
// string used to encrypt the contents of the file config.toml
// at compile time
//
// `password` is the variable used to decrypt the embedded data
// at runtime.
let file_bytes = include_bytes_crypt!(
                    "config.toml",
                    password.as_bytes(),
                    "CONFIG_PASSWORD");

Sometimes, its useful just to obfuscate the embedded data. In that case just the file name is required

// A random password is generated at compiled time
let file_bytes = include_bytes_obfuscate!("config.toml");

License: MIT OR Apache-2.0


lib.rs:

Procedural macro to embed encrypted binary data in compiled binaries.

The macro works similarly to std::include_str, but instead of embedding the UTF-8 string, it embeds encrypted [u8] array. Encryption uses the chacha20poly1305 crate.

Examples

// CONFIG_PASSWORD is the environment variable set to the
// string used to encrypt the contents of the file config.toml
// at compile time
//
// `password` is the variable used to decrypt the embedded data
// at runtime.
let file_bytes = include_bytes_crypt!(
                    "config.toml",
                    password.as_bytes(),
                    "CONFIG_PASSWORD");

Sometimes, its useful just to obfuscate the embedded data. In that case just the file name is required

// A random password is generated at compiled time
let file_bytes = include_bytes_obfuscate!("config.toml");

Dependencies

~1.9–2.6MB
~50K SLoC