use base64::Engine;
use base64::engine::general_purpose::STANDARD;
use log::info;
pub fn encode(string: String) -> String {
STANDARD.encode(string)
}
pub fn url_encode(string: String) -> String {
let base64 = STANDARD.encode(string);
let base64 = base64.replace("=", "*");
let base64 = base64.replace("+", "-");
let base64 = base64.replace("/", "_");
base64
}
pub fn decode(base64: String) -> String {
if base64.is_empty() {
return "".to_string();
}
match STANDARD.decode(base64.clone()) {
Ok(e) => {
let tt = String::from_utf8_lossy(&*e);
tt.to_string()
}
Err(e) => {
info!("{}", e);
return base64;
}
}
}
pub fn url_decode(base64: String) -> String {
let base64 = base64.replace("*", "=");
let base64 = base64.replace("-", "+");
let base64 = base64.replace("_", "/");
if base64.is_empty() {
return "".to_string();
}
match STANDARD.decode(base64.clone()) {
Ok(e) => {
let tt = String::from_utf8_lossy(&*e);
tt.to_string()
}
Err(e) => {
info!("{}", e);
return base64;
}
}
}