Skip to content

Commit

Permalink
[chore] update README.md with new doctests (#17)
Browse files Browse the repository at this point in the history
* update `readme.md`
  • Loading branch information
orph3usLyre authored Apr 3, 2024
1 parent e56d15b commit c8e4004
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 11 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
* bump --all-- CI/CD checkout@v3 to checkout@v4 and set timeout (#12)
* add strict clippy lints (#13)
* reduce output text at build time (#15)
* update README with doctests (#17)

## 0.2.0
* Initial published crate version
28 changes: 18 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,13 @@ It functions by encrypting texts at buildtime, and decrypting them lazily at run
## Usage & Examples

```rust

extern crate muddy;
use muddy::{m, muddy_init};

muddy_init!();

fn main() {
println!("{}", m!("My highly obfuscated text"));
println!("{}", "My non obfuscated static str - ripgrep me");
}
println!("{}", m!("My highly obfuscated text"));
println!("{}", "My non obfuscated static str - ripgrep me");

```


Expand All @@ -39,34 +36,48 @@ for decrypting the strings at runtime and should be placed at the `root` of the
These macros can be used as an in-place text replacement with `m!("my text")`:

```rust
use muddy::{muddy_init, m};

muddy_init!();

println!("{}", m!("my plaintext"));
```

As an annotated `&'static str` with the [`muddy`] attribute:

```rust
use muddy::{muddy, muddy_init};

muddy_init!();

#[muddy]
static MY_STR: &str = "my plaintext";

```

Or as an invocation around multiple annotated `&'static str`s with [`muddy_all`]:

```rust
use muddy::{muddy_all, muddy_init};

muddy_init!();

muddy_all! {
pub static MY_STR: &str = "my plaintext";
pub static MY_SECOND_STR: &str = "my second plaintext";
static MY_THIRD_STR: &str = "my module-specific third plaintext";
}

```

By default, `muddy` will encrypt the static strings with the [`chacha20poly1305`] implementation,
and embed the key inside the binary.

To avoid hardcoding the deobfuscation key into your binary, you may use:

// NOTE: this test will fail if run by tests since the key needs to be provided at runtime
```rust

extern crate muddy;
use muddy::{m, muddy_init};

muddy_init!("env");
Expand All @@ -78,11 +89,8 @@ muddy_init!("env");

// This key needs to be provided at runtime else the program will panic.
// `MUDDY='D47A372C13DEFED74FD3B9B4C741C355F9CB2C23C43F98ADE2C02FD50CA55C3D' ./target/debug/examples/env`

fn main() {
println!("{}", m!("My highly obfuscated text"));
println!("{}", "My non obfuscated static str - ripgrep me");
}
```


Expand Down
1 change: 0 additions & 1 deletion muddy/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,6 @@
//! As an annotated `&'static str` with the [`muddy`] attribute:
//!
//! ```rust
//! #[macro_use] extern crate muddy;
//! use muddy::{muddy, muddy_init};
//!
//! muddy_init!();
Expand Down

0 comments on commit c8e4004

Please sign in to comment.