include_crypt_codegen/
lib.rs

1use implementations::{aes, files, xor};
2use proc_macro::TokenStream;
3
4mod implementations;
5mod utils;
6
7/// Encrypts a file with a random or custom key.
8///
9/// # Example
10///
11/// ## Custom key
12///
13/// ```
14/// # use include_crypt_codegen::encrypt_xor;
15/// let (key, encrypted) = encrypt_xor!("src/lib.rs", 0xdeadbeef);
16/// ```
17///
18/// ## Random key
19///
20/// ```
21/// # use include_crypt_codegen::encrypt_xor;
22/// let (key, encrypted) = encrypt_xor!("src/lib.rs");
23/// ```
24#[proc_macro]
25pub fn encrypt_xor(input: TokenStream) -> TokenStream {
26    match xor::impl_encrypt_xor(input) {
27        Ok(ts) => ts,
28        Err(err) => err.to_compile_error().into(),
29    }
30}
31
32/// Encrypts a file with a random or custom key.
33///
34/// # Example
35///
36/// ## Custom key
37///
38/// ```
39/// # use include_crypt_codegen::encrypt_aes;
40/// let (key, nonce, encrypted) = encrypt_aes!("src/lib.rs", 0xdeadbeef);
41/// ```
42///
43/// ## Random key
44///
45/// ```
46/// # use include_crypt_codegen::encrypt_aes;
47/// let (key, nonce, encrypted) = encrypt_aes!("src/lib.rs");
48/// ```
49#[proc_macro]
50pub fn encrypt_aes(input: TokenStream) -> TokenStream {
51    match aes::impl_encrypt_aes(input) {
52        Ok(ts) => ts,
53        Err(err) => err.to_compile_error().into(),
54    }
55}
56
57/// Encrypts all the files in the specified folder.
58///
59/// # Example
60///
61/// ```
62/// # use include_crypt_codegen::include_files;
63/// let files = include_files!("XOR", "src");
64/// ```
65#[proc_macro]
66pub fn include_files(input: TokenStream) -> TokenStream {
67    match files::impl_include_files(input) {
68        Ok(ts) => ts,
69        Err(err) => err.to_compile_error().into(),
70    }
71}