pub struct Obfuscator { /* private fields */ }Expand description
The main obfuscator struct that provides text obfuscation functionality
Implementations§
Source§impl Obfuscator
impl Obfuscator
Sourcepub fn new(passphrase: &[u8]) -> Self
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}Sourcepub fn with_salt_length(self, length: u8) -> Self
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}Sourcepub fn with_separator(self, separator: &str) -> Self
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}Sourcepub fn obfuscate(&self, text: &str) -> Result<String, ObfuscatorError>
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}Sourcepub fn unobfuscate(
&self,
obfuscated_text: &str,
) -> Result<String, ObfuscatorError>
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§
impl Freeze for Obfuscator
impl RefUnwindSafe for Obfuscator
impl Send for Obfuscator
impl Sync for Obfuscator
impl Unpin for Obfuscator
impl UnwindSafe for Obfuscator
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more