Obfuscator

Struct Obfuscator 

Source
pub struct Obfuscator { /* private fields */ }
Expand description

The main obfuscator struct that provides text obfuscation functionality

Implementations§

Source§

impl Obfuscator

Source

pub fn new(passphrase: &[u8]) -> Self

Creates a new Obfuscator with the given passphrase

§Arguments
  • passphrase - The passphrase used for encryption/decryption
§Panics

Panics if the passphrase is empty

§Examples
use rustfuscator::Obfuscator;

let obfuscator = Obfuscator::new("my-secure-passphrase".as_bytes());
Examples found in repository?
examples/obfuscate.rs (line 5)
3fn main() {
4    let original_text = "simple text or password";
5    let o = Obfuscator::new("randompassphrase".as_bytes())
6        .with_salt_length(6)
7        .with_separator(rustfuscator::DEFAULT_SEPARATOR_STR);
8
9    // obfuscate
10    match o.obfuscate(original_text) {
11        Ok(obfuscated_text) => {
12            println!("Obfuscated text: {}", obfuscated_text);
13
14            // unobfuscate
15            match o.unobfuscate(&obfuscated_text) {
16                Ok(unobfuscated_text) => {
17                    println!("Unobfuscated text: {}", unobfuscated_text);
18                }
19                Err(err) => {
20                    println!("Error: {}", err);
21                }
22            }
23        }
24        Err(err) => {
25            println!("Error: {}", err);
26        }
27    }
28}
Source

pub fn with_salt_length(self, length: u8) -> Self

Sets a custom salt length

§Arguments
  • length - The salt length in bytes
§Panics

Panics if the salt length is 0

§Examples
use rustfuscator::Obfuscator;

let obfuscator = Obfuscator::new("passphrase".as_bytes())
    .with_salt_length(16);
Examples found in repository?
examples/obfuscate.rs (line 6)
3fn main() {
4    let original_text = "simple text or password";
5    let o = Obfuscator::new("randompassphrase".as_bytes())
6        .with_salt_length(6)
7        .with_separator(rustfuscator::DEFAULT_SEPARATOR_STR);
8
9    // obfuscate
10    match o.obfuscate(original_text) {
11        Ok(obfuscated_text) => {
12            println!("Obfuscated text: {}", obfuscated_text);
13
14            // unobfuscate
15            match o.unobfuscate(&obfuscated_text) {
16                Ok(unobfuscated_text) => {
17                    println!("Unobfuscated text: {}", unobfuscated_text);
18                }
19                Err(err) => {
20                    println!("Error: {}", err);
21                }
22            }
23        }
24        Err(err) => {
25            println!("Error: {}", err);
26        }
27    }
28}
Source

pub fn with_separator(self, separator: &str) -> Self

Sets a custom separator for the obfuscated string parts

§Arguments
  • separator - The separator string
§Examples
use rustfuscator::Obfuscator;

let obfuscator = Obfuscator::new("passphrase".as_bytes())
    .with_separator("#");
Examples found in repository?
examples/obfuscate.rs (line 7)
3fn main() {
4    let original_text = "simple text or password";
5    let o = Obfuscator::new("randompassphrase".as_bytes())
6        .with_salt_length(6)
7        .with_separator(rustfuscator::DEFAULT_SEPARATOR_STR);
8
9    // obfuscate
10    match o.obfuscate(original_text) {
11        Ok(obfuscated_text) => {
12            println!("Obfuscated text: {}", obfuscated_text);
13
14            // unobfuscate
15            match o.unobfuscate(&obfuscated_text) {
16                Ok(unobfuscated_text) => {
17                    println!("Unobfuscated text: {}", unobfuscated_text);
18                }
19                Err(err) => {
20                    println!("Error: {}", err);
21                }
22            }
23        }
24        Err(err) => {
25            println!("Error: {}", err);
26        }
27    }
28}
Source

pub fn obfuscate(&self, text: &str) -> Result<String, ObfuscatorError>

Obfuscates the given text using the configured passphrase

§Arguments
  • text - The text to obfuscate
§Returns
  • Result<String, ObfuscatorError> - The obfuscated string or an error
§Examples
use rustfuscator::Obfuscator;

let obfuscator = Obfuscator::new("passphrase".as_bytes());
let obfuscated = obfuscator.obfuscate("Hello, World!").unwrap();
println!("Obfuscated: {}", obfuscated);
Examples found in repository?
examples/obfuscate.rs (line 10)
3fn main() {
4    let original_text = "simple text or password";
5    let o = Obfuscator::new("randompassphrase".as_bytes())
6        .with_salt_length(6)
7        .with_separator(rustfuscator::DEFAULT_SEPARATOR_STR);
8
9    // obfuscate
10    match o.obfuscate(original_text) {
11        Ok(obfuscated_text) => {
12            println!("Obfuscated text: {}", obfuscated_text);
13
14            // unobfuscate
15            match o.unobfuscate(&obfuscated_text) {
16                Ok(unobfuscated_text) => {
17                    println!("Unobfuscated text: {}", unobfuscated_text);
18                }
19                Err(err) => {
20                    println!("Error: {}", err);
21                }
22            }
23        }
24        Err(err) => {
25            println!("Error: {}", err);
26        }
27    }
28}
Source

pub fn unobfuscate( &self, obfuscated_text: &str, ) -> Result<String, ObfuscatorError>

Unobfuscates the given obfuscated text using the configured passphrase

§Arguments
  • obfuscated_text - The obfuscated text to unobfuscate
§Returns
  • Result<String, ObfuscatorError> - The original text or an error
§Examples
use rustfuscator::Obfuscator;

let obfuscator = Obfuscator::new("passphrase".as_bytes());
let obfuscated = obfuscator.obfuscate("Hello, World!").unwrap();
let unobfuscated = obfuscator.unobfuscate(&obfuscated).unwrap();
assert_eq!(unobfuscated, "Hello, World!");
Examples found in repository?
examples/obfuscate.rs (line 15)
3fn main() {
4    let original_text = "simple text or password";
5    let o = Obfuscator::new("randompassphrase".as_bytes())
6        .with_salt_length(6)
7        .with_separator(rustfuscator::DEFAULT_SEPARATOR_STR);
8
9    // obfuscate
10    match o.obfuscate(original_text) {
11        Ok(obfuscated_text) => {
12            println!("Obfuscated text: {}", obfuscated_text);
13
14            // unobfuscate
15            match o.unobfuscate(&obfuscated_text) {
16                Ok(unobfuscated_text) => {
17                    println!("Unobfuscated text: {}", unobfuscated_text);
18                }
19                Err(err) => {
20                    println!("Error: {}", err);
21                }
22            }
23        }
24        Err(err) => {
25            println!("Error: {}", err);
26        }
27    }
28}

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V