1use base64::Engine;
2use base64::engine::general_purpose::STANDARD;
3use log::info;
4
5pub fn encode(string: String) -> String {
7 STANDARD.encode(string)
8}
9pub fn url_encode(string: String) -> String {
11 let base64 = STANDARD.encode(string);
12 let base64 = base64.replace("=", "*");
13 let base64 = base64.replace("+", "-");
14 let base64 = base64.replace("/", "_");
15 base64
16}
17pub fn decode(base64: String) -> String {
19 if base64.is_empty() {
20 return "".to_string();
21 }
22 match STANDARD.decode(base64.clone()) {
23 Ok(e) => {
24 let tt = String::from_utf8_lossy(&*e);
25 tt.to_string()
26 }
27 Err(e) => {
28 info!("{}", e);
29 return base64;
30 }
31 }
32}
33pub fn url_decode(base64: String) -> String {
35 let base64 = base64.replace("*", "=");
36 let base64 = base64.replace("-", "+");
37 let base64 = base64.replace("_", "/");
38 if base64.is_empty() {
39 return "".to_string();
40 }
41 match STANDARD.decode(base64.clone()) {
42 Ok(e) => {
43 let tt = String::from_utf8_lossy(&*e);
44 tt.to_string()
45 }
46 Err(e) => {
47 info!("{}", e);
48 return base64;
49 }
50 }
51}