(input: TokenStream)
| 157 | /// A procedural macro that encrypts a string literal at compile time. |
| 158 | #[proc_macro] |
| 159 | pub fn encrypt_string(input: TokenStream) -> TokenStream { |
| 160 | let input = parse_macro_input!(input as LitStr); |
| 161 | let string = input.value(); |
| 162 | |
| 163 | // Set key to seeded env key or default |
| 164 | let key = env::var("CRYPTIFY_KEY").unwrap_or_else(|_| "xnasff3wcedj".to_string()); |
| 165 | |
| 166 | let encrypted_string = xor_cipher(&string, &key); |
| 167 | |
| 168 | let output = quote! { |
| 169 | cryptify::decrypt_string(#encrypted_string).as_ref() |
| 170 | }; |
| 171 | |
| 172 | TokenStream::from(output) |
| 173 | } |
| 174 | |
| 175 | fn xor_cipher(input: &str, key: &str) -> String { |
| 176 | let key_bytes = key.as_bytes(); |
nothing calls this directly
no test coverage detected