Skip to content

Commit

Permalink
Helper macro to obfuscate to an owned String instead of a temporary &…
Browse files Browse the repository at this point in the history
…str (#54)
  • Loading branch information
CasualX authored May 30, 2023
1 parent 087aac4 commit ec1a20b
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 4 deletions.
8 changes: 4 additions & 4 deletions examples/stringify.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ The example presented here uses an enum because it can be challenging to return
*/

use std::fmt;
use obfstr::{obfstr, position};
use obfstr::{obfstr, obfstring, position};

// Let's try to obfuscate the string representation of this enum.
pub enum Example {
Expand All @@ -17,9 +17,9 @@ impl Example {
// Returns an owned String but this allocates memory.
pub fn to_str1(&self) -> String {
match self {
Example::Foo => String::from(obfstr!("Foo")),
Example::Bar => String::from(obfstr!("Bar")),
Example::Baz => String::from(obfstr!("Baz")),
Example::Foo => obfstring!("Foo"),
Example::Bar => obfstring!("Bar"),
Example::Baz => obfstring!("Baz"),
}
}

Expand Down
12 changes: 12 additions & 0 deletions src/bytes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,18 @@ macro_rules! obfstr {
};
}

/// Compiletime string constant obfuscation.
///
/// Returns an owned `String` instead of a temporary `&str`.
///
/// See [`obfstr!`] for more information.
#[macro_export]
macro_rules! obfstring {
($s:expr) => {
String::from($crate::obfstr!($s))
};
}

/// Compiletime byte string obfuscation.
#[macro_export]
macro_rules! obfbytes {
Expand Down

0 comments on commit ec1a20b

Please sign in to comment.