bump version and reformat code.

This commit is contained in:
anvie
2025-02-13 16:53:58 +07:00
parent 2f3c75e952
commit 2484e7c20c
3 changed files with 35 additions and 23 deletions
Generated
+7
View File
@@ -34,6 +34,12 @@ dependencies = [
"wasi",
]
[[package]]
name = "lazy_static"
version = "1.5.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "bbd2bcb4c963f2ddae06a2efc7e9f3591312473c50c6685e1f298068316e66fe"
[[package]]
name = "libc"
version = "0.2.126"
@@ -45,6 +51,7 @@ name = "litcrypt"
version = "0.4.0"
dependencies = [
"expectest",
"lazy_static",
"proc-macro2",
"quote",
"rand",
+23 -18
View File
@@ -1,18 +1,19 @@
LITCRYPT [![Build Status](https://travis-ci.org/anvie/litcrypt.rs.svg?branch=master)](https://travis-ci.org/anvie/litcrypt.rs) ![Crates.io](https://img.shields.io/crates/v/litcrypt)
===========
# LITCRYPT [![Build Status](https://travis-ci.org/anvie/litcrypt.rs.svg?branch=master)](https://travis-ci.org/anvie/litcrypt.rs) ![Crates.io](https://img.shields.io/crates/v/litcrypt)
Is a short name of "Literal Encryption", a Rust proc macro that encrypts text using a basic XOR method. It protect plain text from static analysis tools and helps keep your important app safe from cracking activity.
Is a short name of "Literal Encryption", a Rust proc macro that encrypts text
using a basic XOR method. It protect plain text from static analysis tools and
helps keep your important app safe from cracking activity.
LITCRYPT encrypts strings when compiling, keeping them encrypted in both disk and memory while running, and only decrypting them when needed.
LITCRYPT encrypts strings when compiling, keeping them encrypted in both disk
and memory while running, and only decrypting them when needed.
USAGE
-----
## USAGE
Dependencies:
```rust
[dependencies]
litcrypt = "0.3"
litcrypt = "0.4"
```
Example:
@@ -28,27 +29,31 @@ fn main(){
}
```
`use_litcrypt!` macro call should be called first for initialization before you can
use `lc!` macro function. The first parameter is your secret key used for encrypt your
literal string. This key is also encrypted and will not visible under static analyzer.
`use_litcrypt!` macro call should be called first for initialization before you
can use `lc!` macro function. The first parameter is your secret key used for
encrypt your literal string. This key is also encrypted and will not visible
under static analyzer.
Please take note that you need to set your encryption key using environment variable
`LITCRYPT_ENCRYPT_KEY` before compile:
e.g:
Please take note that you need to set your encryption key using environment
variable `LITCRYPT_ENCRYPT_KEY` before compile: e.g:
$ export LITCRYPT_ENCRYPT_KEY="myverysuperdupermegaultrasecretkey"
export LITCRYPT_ENCRYPT_KEY="myverysuperdupermegaultrasecretkey"
Litcrypt will encrypt each string written inside `lc!` statically.
Check the output binary using `strings` command to verify:
$ strings target/debug/my_valuable_app | grep Voldemort
```
strings target/debug/my_valuable_app | grep Voldemort
```
If the output is blank then your valuable string in your app is safe from static analyzer tool
like Hexeditor etc.
If the output is blank then your valuable string in your app is safe from static
analyzer tool like Hexeditor etc.
For working example code see `./examples` directory, and test using:
$ cargo run --example simple
```
cargo run --example simple
```
[] Robin.
+5 -5
View File
@@ -58,8 +58,8 @@
//! ```
extern crate proc_macro;
extern crate proc_macro2;
extern crate rand;
extern crate quote;
extern crate rand;
#[cfg(test)]
#[macro_use(expect)]
@@ -67,8 +67,8 @@ extern crate expectest;
use proc_macro::{TokenStream, TokenTree};
use proc_macro2::Literal;
use rand::{rngs::OsRng, RngCore};
use quote::quote;
use rand::{rngs::OsRng, RngCore};
use std::env;
mod xor;
@@ -84,7 +84,7 @@ lazy_static::lazy_static! {
#[inline(always)]
fn get_magic_spell() -> Vec<u8> {
match env::var("LITCRYPT_ENCRYPT_KEY") {
Ok(key) => {key.as_bytes().to_vec()},
Ok(key) => key.as_bytes().to_vec(),
Err(_) => {
// `lc!` will call this function multi times
// we must provide exact same result for each invocation
@@ -184,7 +184,7 @@ pub fn lc(tokens: TokenStream) -> TokenStream {
}
}
something = String::from(&something[1..something.len() - 1]);
encrypt_string(something)
}
@@ -208,7 +208,7 @@ pub fn lc_env(tokens: TokenStream) -> TokenStream {
fn encrypt_string(something: String) -> TokenStream {
let magic_spell = get_magic_spell();
let encrypt_key = xor::xor(&magic_spell, b"l33t");
let encrypted = xor::xor(&something.as_bytes(), &encrypt_key);
let encrypted = xor::xor(something.as_bytes(), &encrypt_key);
let encrypted = Literal::byte_string(&encrypted);
let result = quote! {