Skip to main content

StringEncrypt

Struct StringEncrypt 

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

Stateful HTTP client: pass the activation key to the constructor, configure other options via setters, then StringEncrypt::send.

POST field code (activation key) is the value given at construction (empty string = demo).

For Command::ENCRYPT with compression enabled (StringEncrypt::set_compression), the API may return source as base64-encoded gzip of the decryptor text. StringEncrypt::send decodes that automatically so source is always plain text on success unless you call StringEncrypt::set_decompress_encrypt_source with false.

Implementations§

Source§

impl StringEncrypt

Source

pub fn new(api_key: impl Into<String>, prefer_curl: bool) -> Self

Create a client. api_key is sent as code (empty = demo). prefer_curl is ignored; kept for parity with the PHP SDK.

Examples found in repository?
examples/encrypt_simple.rs (line 19)
18async fn main() {
19    let mut string_encrypt = StringEncrypt::new("YOUR-API-KEY-HERE", false); // leave empty for demo mode
20
21    let result = string_encrypt
22        .encrypt_string("Hello!", "$label")
23        .await;
24
25    let Some(result) = result else {
26        println!("Cannot connect to the API.");
27        std::process::exit(1);
28    };
29
30    if result.error != Some(ErrorCode::SUCCESS as i64) {
31        println!("API error: {:?}", result.error);
32        std::process::exit(1);
33    }
34
35    println!("{}\n", result.source.unwrap_or_default());
36}
More examples
Hide additional examples
examples/encrypt.rs (line 19)
18async fn main() {
19    let mut string_encrypt = StringEncrypt::new("YOUR-API-KEY-HERE", false); // leave empty for demo mode
20    string_encrypt
21        .set_compression(false)
22        .set_unicode(true)
23        .set_lang_locale("en_US.utf8")
24        .set_new_lines(NewLine::LF)
25        .set_language(Language::CPP)
26        .set_cmd_min(1)
27        .set_cmd_max(3)
28        .set_local(false);
29
30    let result = string_encrypt
31        .encrypt_string("Hello!", "wszLabel")
32        .await;
33
34    let Some(result) = result else {
35        println!("Cannot connect to the API.");
36        std::process::exit(1);
37    };
38
39    if result.error != Some(ErrorCode::SUCCESS as i64) {
40        println!("API error: {:?}", result.error);
41        std::process::exit(1);
42    }
43
44    println!("{}\n", result.source.unwrap_or_default());
45}
examples/is_demo.rs (line 19)
18async fn main() {
19    let mut string_encrypt = StringEncrypt::new("", false); // leave empty for demo mode
20
21    let result = string_encrypt.is_demo().await;
22
23    let Some(result) = result else {
24        println!("Cannot connect to the API.");
25        std::process::exit(1);
26    };
27
28    if result.demo.unwrap_or(false) {
29        println!("DEMO mode");
30    } else {
31        println!("FULL mode");
32        println!("Credits left: {}", result.credits_left.unwrap_or(0));
33    }
34
35    println!("Label max length: {}", result.label_limit.unwrap_or(0));
36    println!("String max length: {}", result.string_limit.unwrap_or(0));
37    println!("Bytes max length: {}", result.bytes_limit.unwrap_or(0));
38    println!(
39        "cmd_min / cmd_max: {} / {}",
40        result.cmd_min.unwrap_or(0),
41        result.cmd_max.unwrap_or(0)
42    );
43}
examples/encrypt_file.rs (line 21)
20async fn main() {
21    let mut string_encrypt = StringEncrypt::new("YOUR-API-KEY-HERE", false); // leave empty for demo mode
22    string_encrypt
23        .set_compression(false)
24        .set_unicode(true)
25        .set_lang_locale("en_US.utf8")
26        .set_new_lines(NewLine::LF)
27        .set_ansi_encoding("WINDOWS-1250")
28        .set_language(Language::PHP)
29        .set_cmd_min(1)
30        .set_cmd_max(3)
31        .set_local(false);
32
33    let mut path = PathBuf::from(env!("CARGO_MANIFEST_DIR"));
34    path.push("examples");
35    path.push("sample.bin");
36
37    // Full license: raw bytes from file (demo may return ERROR_DEMO).
38    let result = string_encrypt
39        .encrypt_file_contents(&path, "$label")
40        .await;
41
42    let Some(result) = result else {
43        println!("Cannot connect to the API or file is missing/empty.");
44        std::process::exit(1);
45    };
46
47    if result.error != Some(ErrorCode::SUCCESS as i64) {
48        println!("API error: {:?}", result.error);
49        std::process::exit(1);
50    }
51
52    println!("{}\n", result.source.unwrap_or_default());
53}
Source

pub fn demo() -> Self

Same as new("", false) for demo mode checks.

Source

pub fn prefer_curl(&self) -> bool

Source

pub fn set_prefer_curl(&mut self, prefer_curl: bool) -> &mut Self

Source

pub fn decompress_encrypt_source(&self) -> bool

Source

pub fn set_decompress_encrypt_source(&mut self, decompress: bool) -> &mut Self

Disable automatic gzip+base64 decoding of source for encrypt+compression responses if you need the raw payload from the API.

Source

pub fn command(&self) -> Option<&str>

Source

pub fn set_command(&mut self, command: &str) -> &mut Self

Source

pub fn label(&self) -> &str

Source

pub fn set_label(&mut self, label: impl Into<String>) -> &mut Self

Source

pub fn set_string(&mut self, string: impl Into<String>) -> &mut Self

UTF-8 text input; clears raw bytes input.

Source

pub fn set_bytes(&mut self, bytes: impl Into<Vec<u8>>) -> &mut Self

Raw binary input; clears string input.

Source

pub fn compression(&self) -> bool

Source

pub fn set_compression(&mut self, compression: bool) -> &mut Self

Examples found in repository?
examples/encrypt.rs (line 21)
18async fn main() {
19    let mut string_encrypt = StringEncrypt::new("YOUR-API-KEY-HERE", false); // leave empty for demo mode
20    string_encrypt
21        .set_compression(false)
22        .set_unicode(true)
23        .set_lang_locale("en_US.utf8")
24        .set_new_lines(NewLine::LF)
25        .set_language(Language::CPP)
26        .set_cmd_min(1)
27        .set_cmd_max(3)
28        .set_local(false);
29
30    let result = string_encrypt
31        .encrypt_string("Hello!", "wszLabel")
32        .await;
33
34    let Some(result) = result else {
35        println!("Cannot connect to the API.");
36        std::process::exit(1);
37    };
38
39    if result.error != Some(ErrorCode::SUCCESS as i64) {
40        println!("API error: {:?}", result.error);
41        std::process::exit(1);
42    }
43
44    println!("{}\n", result.source.unwrap_or_default());
45}
More examples
Hide additional examples
examples/encrypt_file.rs (line 23)
20async fn main() {
21    let mut string_encrypt = StringEncrypt::new("YOUR-API-KEY-HERE", false); // leave empty for demo mode
22    string_encrypt
23        .set_compression(false)
24        .set_unicode(true)
25        .set_lang_locale("en_US.utf8")
26        .set_new_lines(NewLine::LF)
27        .set_ansi_encoding("WINDOWS-1250")
28        .set_language(Language::PHP)
29        .set_cmd_min(1)
30        .set_cmd_max(3)
31        .set_local(false);
32
33    let mut path = PathBuf::from(env!("CARGO_MANIFEST_DIR"));
34    path.push("examples");
35    path.push("sample.bin");
36
37    // Full license: raw bytes from file (demo may return ERROR_DEMO).
38    let result = string_encrypt
39        .encrypt_file_contents(&path, "$label")
40        .await;
41
42    let Some(result) = result else {
43        println!("Cannot connect to the API or file is missing/empty.");
44        std::process::exit(1);
45    };
46
47    if result.error != Some(ErrorCode::SUCCESS as i64) {
48        println!("API error: {:?}", result.error);
49        std::process::exit(1);
50    }
51
52    println!("{}\n", result.source.unwrap_or_default());
53}
Source

pub fn language(&self) -> &str

Source

pub fn set_language(&mut self, language: &str) -> &mut Self

Examples found in repository?
examples/encrypt.rs (line 25)
18async fn main() {
19    let mut string_encrypt = StringEncrypt::new("YOUR-API-KEY-HERE", false); // leave empty for demo mode
20    string_encrypt
21        .set_compression(false)
22        .set_unicode(true)
23        .set_lang_locale("en_US.utf8")
24        .set_new_lines(NewLine::LF)
25        .set_language(Language::CPP)
26        .set_cmd_min(1)
27        .set_cmd_max(3)
28        .set_local(false);
29
30    let result = string_encrypt
31        .encrypt_string("Hello!", "wszLabel")
32        .await;
33
34    let Some(result) = result else {
35        println!("Cannot connect to the API.");
36        std::process::exit(1);
37    };
38
39    if result.error != Some(ErrorCode::SUCCESS as i64) {
40        println!("API error: {:?}", result.error);
41        std::process::exit(1);
42    }
43
44    println!("{}\n", result.source.unwrap_or_default());
45}
More examples
Hide additional examples
examples/encrypt_file.rs (line 28)
20async fn main() {
21    let mut string_encrypt = StringEncrypt::new("YOUR-API-KEY-HERE", false); // leave empty for demo mode
22    string_encrypt
23        .set_compression(false)
24        .set_unicode(true)
25        .set_lang_locale("en_US.utf8")
26        .set_new_lines(NewLine::LF)
27        .set_ansi_encoding("WINDOWS-1250")
28        .set_language(Language::PHP)
29        .set_cmd_min(1)
30        .set_cmd_max(3)
31        .set_local(false);
32
33    let mut path = PathBuf::from(env!("CARGO_MANIFEST_DIR"));
34    path.push("examples");
35    path.push("sample.bin");
36
37    // Full license: raw bytes from file (demo may return ERROR_DEMO).
38    let result = string_encrypt
39        .encrypt_file_contents(&path, "$label")
40        .await;
41
42    let Some(result) = result else {
43        println!("Cannot connect to the API or file is missing/empty.");
44        std::process::exit(1);
45    };
46
47    if result.error != Some(ErrorCode::SUCCESS as i64) {
48        println!("API error: {:?}", result.error);
49        std::process::exit(1);
50    }
51
52    println!("{}\n", result.source.unwrap_or_default());
53}
Source

pub fn highlight_off(&self) -> bool

Source

pub fn highlight_mode(&self) -> Option<&str>

Source

pub fn set_highlight(&mut self, highlight: impl Into<HighlightArg>) -> &mut Self

false disables highlight; pass a mode string such as geshi / js when supported server-side.

Source

pub fn cmd_min(&self) -> i32

Source

pub fn set_cmd_min(&mut self, cmd_min: i32) -> &mut Self

Examples found in repository?
examples/encrypt.rs (line 26)
18async fn main() {
19    let mut string_encrypt = StringEncrypt::new("YOUR-API-KEY-HERE", false); // leave empty for demo mode
20    string_encrypt
21        .set_compression(false)
22        .set_unicode(true)
23        .set_lang_locale("en_US.utf8")
24        .set_new_lines(NewLine::LF)
25        .set_language(Language::CPP)
26        .set_cmd_min(1)
27        .set_cmd_max(3)
28        .set_local(false);
29
30    let result = string_encrypt
31        .encrypt_string("Hello!", "wszLabel")
32        .await;
33
34    let Some(result) = result else {
35        println!("Cannot connect to the API.");
36        std::process::exit(1);
37    };
38
39    if result.error != Some(ErrorCode::SUCCESS as i64) {
40        println!("API error: {:?}", result.error);
41        std::process::exit(1);
42    }
43
44    println!("{}\n", result.source.unwrap_or_default());
45}
More examples
Hide additional examples
examples/encrypt_file.rs (line 29)
20async fn main() {
21    let mut string_encrypt = StringEncrypt::new("YOUR-API-KEY-HERE", false); // leave empty for demo mode
22    string_encrypt
23        .set_compression(false)
24        .set_unicode(true)
25        .set_lang_locale("en_US.utf8")
26        .set_new_lines(NewLine::LF)
27        .set_ansi_encoding("WINDOWS-1250")
28        .set_language(Language::PHP)
29        .set_cmd_min(1)
30        .set_cmd_max(3)
31        .set_local(false);
32
33    let mut path = PathBuf::from(env!("CARGO_MANIFEST_DIR"));
34    path.push("examples");
35    path.push("sample.bin");
36
37    // Full license: raw bytes from file (demo may return ERROR_DEMO).
38    let result = string_encrypt
39        .encrypt_file_contents(&path, "$label")
40        .await;
41
42    let Some(result) = result else {
43        println!("Cannot connect to the API or file is missing/empty.");
44        std::process::exit(1);
45    };
46
47    if result.error != Some(ErrorCode::SUCCESS as i64) {
48        println!("API error: {:?}", result.error);
49        std::process::exit(1);
50    }
51
52    println!("{}\n", result.source.unwrap_or_default());
53}
Source

pub fn cmd_max(&self) -> i32

Source

pub fn set_cmd_max(&mut self, cmd_max: i32) -> &mut Self

Examples found in repository?
examples/encrypt.rs (line 27)
18async fn main() {
19    let mut string_encrypt = StringEncrypt::new("YOUR-API-KEY-HERE", false); // leave empty for demo mode
20    string_encrypt
21        .set_compression(false)
22        .set_unicode(true)
23        .set_lang_locale("en_US.utf8")
24        .set_new_lines(NewLine::LF)
25        .set_language(Language::CPP)
26        .set_cmd_min(1)
27        .set_cmd_max(3)
28        .set_local(false);
29
30    let result = string_encrypt
31        .encrypt_string("Hello!", "wszLabel")
32        .await;
33
34    let Some(result) = result else {
35        println!("Cannot connect to the API.");
36        std::process::exit(1);
37    };
38
39    if result.error != Some(ErrorCode::SUCCESS as i64) {
40        println!("API error: {:?}", result.error);
41        std::process::exit(1);
42    }
43
44    println!("{}\n", result.source.unwrap_or_default());
45}
More examples
Hide additional examples
examples/encrypt_file.rs (line 30)
20async fn main() {
21    let mut string_encrypt = StringEncrypt::new("YOUR-API-KEY-HERE", false); // leave empty for demo mode
22    string_encrypt
23        .set_compression(false)
24        .set_unicode(true)
25        .set_lang_locale("en_US.utf8")
26        .set_new_lines(NewLine::LF)
27        .set_ansi_encoding("WINDOWS-1250")
28        .set_language(Language::PHP)
29        .set_cmd_min(1)
30        .set_cmd_max(3)
31        .set_local(false);
32
33    let mut path = PathBuf::from(env!("CARGO_MANIFEST_DIR"));
34    path.push("examples");
35    path.push("sample.bin");
36
37    // Full license: raw bytes from file (demo may return ERROR_DEMO).
38    let result = string_encrypt
39        .encrypt_file_contents(&path, "$label")
40        .await;
41
42    let Some(result) = result else {
43        println!("Cannot connect to the API or file is missing/empty.");
44        std::process::exit(1);
45    };
46
47    if result.error != Some(ErrorCode::SUCCESS as i64) {
48        println!("API error: {:?}", result.error);
49        std::process::exit(1);
50    }
51
52    println!("{}\n", result.source.unwrap_or_default());
53}
Source

pub fn local(&self) -> bool

Source

pub fn set_local(&mut self, local: bool) -> &mut Self

Examples found in repository?
examples/encrypt.rs (line 28)
18async fn main() {
19    let mut string_encrypt = StringEncrypt::new("YOUR-API-KEY-HERE", false); // leave empty for demo mode
20    string_encrypt
21        .set_compression(false)
22        .set_unicode(true)
23        .set_lang_locale("en_US.utf8")
24        .set_new_lines(NewLine::LF)
25        .set_language(Language::CPP)
26        .set_cmd_min(1)
27        .set_cmd_max(3)
28        .set_local(false);
29
30    let result = string_encrypt
31        .encrypt_string("Hello!", "wszLabel")
32        .await;
33
34    let Some(result) = result else {
35        println!("Cannot connect to the API.");
36        std::process::exit(1);
37    };
38
39    if result.error != Some(ErrorCode::SUCCESS as i64) {
40        println!("API error: {:?}", result.error);
41        std::process::exit(1);
42    }
43
44    println!("{}\n", result.source.unwrap_or_default());
45}
More examples
Hide additional examples
examples/encrypt_file.rs (line 31)
20async fn main() {
21    let mut string_encrypt = StringEncrypt::new("YOUR-API-KEY-HERE", false); // leave empty for demo mode
22    string_encrypt
23        .set_compression(false)
24        .set_unicode(true)
25        .set_lang_locale("en_US.utf8")
26        .set_new_lines(NewLine::LF)
27        .set_ansi_encoding("WINDOWS-1250")
28        .set_language(Language::PHP)
29        .set_cmd_min(1)
30        .set_cmd_max(3)
31        .set_local(false);
32
33    let mut path = PathBuf::from(env!("CARGO_MANIFEST_DIR"));
34    path.push("examples");
35    path.push("sample.bin");
36
37    // Full license: raw bytes from file (demo may return ERROR_DEMO).
38    let result = string_encrypt
39        .encrypt_file_contents(&path, "$label")
40        .await;
41
42    let Some(result) = result else {
43        println!("Cannot connect to the API or file is missing/empty.");
44        std::process::exit(1);
45    };
46
47    if result.error != Some(ErrorCode::SUCCESS as i64) {
48        println!("API error: {:?}", result.error);
49        std::process::exit(1);
50    }
51
52    println!("{}\n", result.source.unwrap_or_default());
53}
Source

pub fn unicode(&self) -> bool

Source

pub fn set_unicode(&mut self, unicode: bool) -> &mut Self

Examples found in repository?
examples/encrypt.rs (line 22)
18async fn main() {
19    let mut string_encrypt = StringEncrypt::new("YOUR-API-KEY-HERE", false); // leave empty for demo mode
20    string_encrypt
21        .set_compression(false)
22        .set_unicode(true)
23        .set_lang_locale("en_US.utf8")
24        .set_new_lines(NewLine::LF)
25        .set_language(Language::CPP)
26        .set_cmd_min(1)
27        .set_cmd_max(3)
28        .set_local(false);
29
30    let result = string_encrypt
31        .encrypt_string("Hello!", "wszLabel")
32        .await;
33
34    let Some(result) = result else {
35        println!("Cannot connect to the API.");
36        std::process::exit(1);
37    };
38
39    if result.error != Some(ErrorCode::SUCCESS as i64) {
40        println!("API error: {:?}", result.error);
41        std::process::exit(1);
42    }
43
44    println!("{}\n", result.source.unwrap_or_default());
45}
More examples
Hide additional examples
examples/encrypt_file.rs (line 24)
20async fn main() {
21    let mut string_encrypt = StringEncrypt::new("YOUR-API-KEY-HERE", false); // leave empty for demo mode
22    string_encrypt
23        .set_compression(false)
24        .set_unicode(true)
25        .set_lang_locale("en_US.utf8")
26        .set_new_lines(NewLine::LF)
27        .set_ansi_encoding("WINDOWS-1250")
28        .set_language(Language::PHP)
29        .set_cmd_min(1)
30        .set_cmd_max(3)
31        .set_local(false);
32
33    let mut path = PathBuf::from(env!("CARGO_MANIFEST_DIR"));
34    path.push("examples");
35    path.push("sample.bin");
36
37    // Full license: raw bytes from file (demo may return ERROR_DEMO).
38    let result = string_encrypt
39        .encrypt_file_contents(&path, "$label")
40        .await;
41
42    let Some(result) = result else {
43        println!("Cannot connect to the API or file is missing/empty.");
44        std::process::exit(1);
45    };
46
47    if result.error != Some(ErrorCode::SUCCESS as i64) {
48        println!("API error: {:?}", result.error);
49        std::process::exit(1);
50    }
51
52    println!("{}\n", result.source.unwrap_or_default());
53}
Source

pub fn lang_locale(&self) -> &str

Source

pub fn set_lang_locale(&mut self, lang_locale: impl Into<String>) -> &mut Self

Examples found in repository?
examples/encrypt.rs (line 23)
18async fn main() {
19    let mut string_encrypt = StringEncrypt::new("YOUR-API-KEY-HERE", false); // leave empty for demo mode
20    string_encrypt
21        .set_compression(false)
22        .set_unicode(true)
23        .set_lang_locale("en_US.utf8")
24        .set_new_lines(NewLine::LF)
25        .set_language(Language::CPP)
26        .set_cmd_min(1)
27        .set_cmd_max(3)
28        .set_local(false);
29
30    let result = string_encrypt
31        .encrypt_string("Hello!", "wszLabel")
32        .await;
33
34    let Some(result) = result else {
35        println!("Cannot connect to the API.");
36        std::process::exit(1);
37    };
38
39    if result.error != Some(ErrorCode::SUCCESS as i64) {
40        println!("API error: {:?}", result.error);
41        std::process::exit(1);
42    }
43
44    println!("{}\n", result.source.unwrap_or_default());
45}
More examples
Hide additional examples
examples/encrypt_file.rs (line 25)
20async fn main() {
21    let mut string_encrypt = StringEncrypt::new("YOUR-API-KEY-HERE", false); // leave empty for demo mode
22    string_encrypt
23        .set_compression(false)
24        .set_unicode(true)
25        .set_lang_locale("en_US.utf8")
26        .set_new_lines(NewLine::LF)
27        .set_ansi_encoding("WINDOWS-1250")
28        .set_language(Language::PHP)
29        .set_cmd_min(1)
30        .set_cmd_max(3)
31        .set_local(false);
32
33    let mut path = PathBuf::from(env!("CARGO_MANIFEST_DIR"));
34    path.push("examples");
35    path.push("sample.bin");
36
37    // Full license: raw bytes from file (demo may return ERROR_DEMO).
38    let result = string_encrypt
39        .encrypt_file_contents(&path, "$label")
40        .await;
41
42    let Some(result) = result else {
43        println!("Cannot connect to the API or file is missing/empty.");
44        std::process::exit(1);
45    };
46
47    if result.error != Some(ErrorCode::SUCCESS as i64) {
48        println!("API error: {:?}", result.error);
49        std::process::exit(1);
50    }
51
52    println!("{}\n", result.source.unwrap_or_default());
53}
Source

pub fn ansi_encoding(&self) -> &str

Source

pub fn set_ansi_encoding( &mut self, ansi_encoding: impl Into<String>, ) -> &mut Self

Examples found in repository?
examples/encrypt_file.rs (line 27)
20async fn main() {
21    let mut string_encrypt = StringEncrypt::new("YOUR-API-KEY-HERE", false); // leave empty for demo mode
22    string_encrypt
23        .set_compression(false)
24        .set_unicode(true)
25        .set_lang_locale("en_US.utf8")
26        .set_new_lines(NewLine::LF)
27        .set_ansi_encoding("WINDOWS-1250")
28        .set_language(Language::PHP)
29        .set_cmd_min(1)
30        .set_cmd_max(3)
31        .set_local(false);
32
33    let mut path = PathBuf::from(env!("CARGO_MANIFEST_DIR"));
34    path.push("examples");
35    path.push("sample.bin");
36
37    // Full license: raw bytes from file (demo may return ERROR_DEMO).
38    let result = string_encrypt
39        .encrypt_file_contents(&path, "$label")
40        .await;
41
42    let Some(result) = result else {
43        println!("Cannot connect to the API or file is missing/empty.");
44        std::process::exit(1);
45    };
46
47    if result.error != Some(ErrorCode::SUCCESS as i64) {
48        println!("API error: {:?}", result.error);
49        std::process::exit(1);
50    }
51
52    println!("{}\n", result.source.unwrap_or_default());
53}
Source

pub fn new_lines(&self) -> &str

Source

pub fn set_new_lines(&mut self, new_lines: &str) -> &mut Self

Examples found in repository?
examples/encrypt.rs (line 24)
18async fn main() {
19    let mut string_encrypt = StringEncrypt::new("YOUR-API-KEY-HERE", false); // leave empty for demo mode
20    string_encrypt
21        .set_compression(false)
22        .set_unicode(true)
23        .set_lang_locale("en_US.utf8")
24        .set_new_lines(NewLine::LF)
25        .set_language(Language::CPP)
26        .set_cmd_min(1)
27        .set_cmd_max(3)
28        .set_local(false);
29
30    let result = string_encrypt
31        .encrypt_string("Hello!", "wszLabel")
32        .await;
33
34    let Some(result) = result else {
35        println!("Cannot connect to the API.");
36        std::process::exit(1);
37    };
38
39    if result.error != Some(ErrorCode::SUCCESS as i64) {
40        println!("API error: {:?}", result.error);
41        std::process::exit(1);
42    }
43
44    println!("{}\n", result.source.unwrap_or_default());
45}
More examples
Hide additional examples
examples/encrypt_file.rs (line 26)
20async fn main() {
21    let mut string_encrypt = StringEncrypt::new("YOUR-API-KEY-HERE", false); // leave empty for demo mode
22    string_encrypt
23        .set_compression(false)
24        .set_unicode(true)
25        .set_lang_locale("en_US.utf8")
26        .set_new_lines(NewLine::LF)
27        .set_ansi_encoding("WINDOWS-1250")
28        .set_language(Language::PHP)
29        .set_cmd_min(1)
30        .set_cmd_max(3)
31        .set_local(false);
32
33    let mut path = PathBuf::from(env!("CARGO_MANIFEST_DIR"));
34    path.push("examples");
35    path.push("sample.bin");
36
37    // Full license: raw bytes from file (demo may return ERROR_DEMO).
38    let result = string_encrypt
39        .encrypt_file_contents(&path, "$label")
40        .await;
41
42    let Some(result) = result else {
43        println!("Cannot connect to the API or file is missing/empty.");
44        std::process::exit(1);
45    };
46
47    if result.error != Some(ErrorCode::SUCCESS as i64) {
48        println!("API error: {:?}", result.error);
49        std::process::exit(1);
50    }
51
52    println!("{}\n", result.source.unwrap_or_default());
53}
Source

pub fn template(&self) -> Option<&str>

Source

pub fn set_template(&mut self, template: Option<String>) -> &mut Self

Source

pub fn return_template(&self) -> bool

Source

pub fn set_return_template(&mut self, return_template: bool) -> &mut Self

Source

pub fn include_tags(&self) -> bool

Source

pub fn set_include_tags(&mut self, include_tags: bool) -> &mut Self

Source

pub fn include_example(&self) -> bool

Source

pub fn set_include_example(&mut self, include_example: bool) -> &mut Self

Source

pub fn include_debug_comments(&self) -> bool

Source

pub fn set_include_debug_comments( &mut self, include_debug_comments: bool, ) -> &mut Self

Source

pub fn api_url(&self) -> &str

Source

pub fn set_api_url(&mut self, url: impl Into<String>) -> &mut Self

Source

pub fn reset(&mut self) -> &mut Self

Reset request fields to defaults (reuse the same client for another call).

Source

pub async fn is_demo(&mut self) -> Option<ApiResponse>

Activation status and limits for the activation key passed to the constructor.

Examples found in repository?
examples/is_demo.rs (line 21)
18async fn main() {
19    let mut string_encrypt = StringEncrypt::new("", false); // leave empty for demo mode
20
21    let result = string_encrypt.is_demo().await;
22
23    let Some(result) = result else {
24        println!("Cannot connect to the API.");
25        std::process::exit(1);
26    };
27
28    if result.demo.unwrap_or(false) {
29        println!("DEMO mode");
30    } else {
31        println!("FULL mode");
32        println!("Credits left: {}", result.credits_left.unwrap_or(0));
33    }
34
35    println!("Label max length: {}", result.label_limit.unwrap_or(0));
36    println!("String max length: {}", result.string_limit.unwrap_or(0));
37    println!("Bytes max length: {}", result.bytes_limit.unwrap_or(0));
38    println!(
39        "cmd_min / cmd_max: {} / {}",
40        result.cmd_min.unwrap_or(0),
41        result.cmd_max.unwrap_or(0)
42    );
43}
Source

pub async fn encrypt_file_contents( &mut self, file_path: impl AsRef<Path>, label: &str, ) -> Option<ApiResponse>

Encrypt raw file contents (binary). Uses other encrypt options already set on this client.

Examples found in repository?
examples/encrypt_file.rs (line 39)
20async fn main() {
21    let mut string_encrypt = StringEncrypt::new("YOUR-API-KEY-HERE", false); // leave empty for demo mode
22    string_encrypt
23        .set_compression(false)
24        .set_unicode(true)
25        .set_lang_locale("en_US.utf8")
26        .set_new_lines(NewLine::LF)
27        .set_ansi_encoding("WINDOWS-1250")
28        .set_language(Language::PHP)
29        .set_cmd_min(1)
30        .set_cmd_max(3)
31        .set_local(false);
32
33    let mut path = PathBuf::from(env!("CARGO_MANIFEST_DIR"));
34    path.push("examples");
35    path.push("sample.bin");
36
37    // Full license: raw bytes from file (demo may return ERROR_DEMO).
38    let result = string_encrypt
39        .encrypt_file_contents(&path, "$label")
40        .await;
41
42    let Some(result) = result else {
43        println!("Cannot connect to the API or file is missing/empty.");
44        std::process::exit(1);
45    };
46
47    if result.error != Some(ErrorCode::SUCCESS as i64) {
48        println!("API error: {:?}", result.error);
49        std::process::exit(1);
50    }
51
52    println!("{}\n", result.source.unwrap_or_default());
53}
Source

pub async fn encrypt_string( &mut self, string: &str, label: &str, ) -> Option<ApiResponse>

Encrypt a UTF-8 string. Uses other encrypt options already set on this client.

Examples found in repository?
examples/encrypt_simple.rs (line 22)
18async fn main() {
19    let mut string_encrypt = StringEncrypt::new("YOUR-API-KEY-HERE", false); // leave empty for demo mode
20
21    let result = string_encrypt
22        .encrypt_string("Hello!", "$label")
23        .await;
24
25    let Some(result) = result else {
26        println!("Cannot connect to the API.");
27        std::process::exit(1);
28    };
29
30    if result.error != Some(ErrorCode::SUCCESS as i64) {
31        println!("API error: {:?}", result.error);
32        std::process::exit(1);
33    }
34
35    println!("{}\n", result.source.unwrap_or_default());
36}
More examples
Hide additional examples
examples/encrypt.rs (line 31)
18async fn main() {
19    let mut string_encrypt = StringEncrypt::new("YOUR-API-KEY-HERE", false); // leave empty for demo mode
20    string_encrypt
21        .set_compression(false)
22        .set_unicode(true)
23        .set_lang_locale("en_US.utf8")
24        .set_new_lines(NewLine::LF)
25        .set_language(Language::CPP)
26        .set_cmd_min(1)
27        .set_cmd_max(3)
28        .set_local(false);
29
30    let result = string_encrypt
31        .encrypt_string("Hello!", "wszLabel")
32        .await;
33
34    let Some(result) = result else {
35        println!("Cannot connect to the API.");
36        std::process::exit(1);
37    };
38
39    if result.error != Some(ErrorCode::SUCCESS as i64) {
40        println!("API error: {:?}", result.error);
41        std::process::exit(1);
42    }
43
44    println!("{}\n", result.source.unwrap_or_default());
45}
Source

pub async fn send(&mut self) -> Option<ApiResponse>

Send the request and return decoded JSON, or None on transport / JSON failure.

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> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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> PolicyExt for T
where T: ?Sized,

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow only if self and other return Action::Follow. Read more
Source§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow if either self or other returns Action::Follow. Read more
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<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more