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
impl StringEncrypt
Sourcepub fn new(api_key: impl Into<String>, prefer_curl: bool) -> Self
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?
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
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}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}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}pub fn prefer_curl(&self) -> bool
pub fn set_prefer_curl(&mut self, prefer_curl: bool) -> &mut Self
pub fn decompress_encrypt_source(&self) -> bool
Sourcepub fn set_decompress_encrypt_source(&mut self, decompress: bool) -> &mut Self
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.
pub fn command(&self) -> Option<&str>
pub fn set_command(&mut self, command: &str) -> &mut Self
pub fn label(&self) -> &str
pub fn set_label(&mut self, label: impl Into<String>) -> &mut Self
Sourcepub fn set_string(&mut self, string: impl Into<String>) -> &mut Self
pub fn set_string(&mut self, string: impl Into<String>) -> &mut Self
UTF-8 text input; clears raw bytes input.
Sourcepub fn set_bytes(&mut self, bytes: impl Into<Vec<u8>>) -> &mut Self
pub fn set_bytes(&mut self, bytes: impl Into<Vec<u8>>) -> &mut Self
Raw binary input; clears string input.
pub fn compression(&self) -> bool
Sourcepub fn set_compression(&mut self, compression: bool) -> &mut Self
pub fn set_compression(&mut self, compression: bool) -> &mut Self
Examples found in repository?
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
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}pub fn language(&self) -> &str
Sourcepub fn set_language(&mut self, language: &str) -> &mut Self
pub fn set_language(&mut self, language: &str) -> &mut Self
Examples found in repository?
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
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}pub fn highlight_off(&self) -> bool
pub fn highlight_mode(&self) -> Option<&str>
Sourcepub fn set_highlight(&mut self, highlight: impl Into<HighlightArg>) -> &mut Self
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.
pub fn cmd_min(&self) -> i32
Sourcepub fn set_cmd_min(&mut self, cmd_min: i32) -> &mut Self
pub fn set_cmd_min(&mut self, cmd_min: i32) -> &mut Self
Examples found in repository?
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
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}pub fn cmd_max(&self) -> i32
Sourcepub fn set_cmd_max(&mut self, cmd_max: i32) -> &mut Self
pub fn set_cmd_max(&mut self, cmd_max: i32) -> &mut Self
Examples found in repository?
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
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}pub fn local(&self) -> bool
Sourcepub fn set_local(&mut self, local: bool) -> &mut Self
pub fn set_local(&mut self, local: bool) -> &mut Self
Examples found in repository?
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
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}pub fn unicode(&self) -> bool
Sourcepub fn set_unicode(&mut self, unicode: bool) -> &mut Self
pub fn set_unicode(&mut self, unicode: bool) -> &mut Self
Examples found in repository?
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
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}pub fn lang_locale(&self) -> &str
Sourcepub fn set_lang_locale(&mut self, lang_locale: impl Into<String>) -> &mut Self
pub fn set_lang_locale(&mut self, lang_locale: impl Into<String>) -> &mut Self
Examples found in repository?
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
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}pub fn ansi_encoding(&self) -> &str
Sourcepub fn set_ansi_encoding(
&mut self,
ansi_encoding: impl Into<String>,
) -> &mut Self
pub fn set_ansi_encoding( &mut self, ansi_encoding: impl Into<String>, ) -> &mut Self
Examples found in repository?
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}pub fn new_lines(&self) -> &str
Sourcepub fn set_new_lines(&mut self, new_lines: &str) -> &mut Self
pub fn set_new_lines(&mut self, new_lines: &str) -> &mut Self
Examples found in repository?
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
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}pub fn template(&self) -> Option<&str>
pub fn set_template(&mut self, template: Option<String>) -> &mut Self
pub fn return_template(&self) -> bool
pub fn set_return_template(&mut self, return_template: bool) -> &mut Self
pub fn include_example(&self) -> bool
pub fn set_include_example(&mut self, include_example: bool) -> &mut Self
pub fn include_debug_comments(&self) -> bool
pub fn set_include_debug_comments( &mut self, include_debug_comments: bool, ) -> &mut Self
pub fn api_url(&self) -> &str
pub fn set_api_url(&mut self, url: impl Into<String>) -> &mut Self
Sourcepub fn reset(&mut self) -> &mut Self
pub fn reset(&mut self) -> &mut Self
Reset request fields to defaults (reuse the same client for another call).
Sourcepub async fn is_demo(&mut self) -> Option<ApiResponse>
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?
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}Sourcepub async fn encrypt_file_contents(
&mut self,
file_path: impl AsRef<Path>,
label: &str,
) -> Option<ApiResponse>
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?
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}Sourcepub async fn encrypt_string(
&mut self,
string: &str,
label: &str,
) -> Option<ApiResponse>
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?
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
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}Sourcepub async fn send(&mut self) -> Option<ApiResponse>
pub async fn send(&mut self) -> Option<ApiResponse>
Send the request and return decoded JSON, or None on transport / JSON failure.