waves_rust/util/
base64.rs

1use base64::DecodeError;
2
3pub struct Base64;
4
5impl Base64 {
6    pub fn decode(source: &str) -> Result<Vec<u8>, DecodeError> {
7        let base64str = if source.starts_with("base64:") {
8            source.replace("base64:", "")
9        } else {
10            source.to_owned()
11        };
12        base64::decode(base64str)
13    }
14
15    pub fn encode(bytes: &Vec<u8>, with_prefix: bool) -> String {
16        let base64string = base64::encode(bytes).as_str().to_owned();
17        if with_prefix {
18            return format!("base64:{}", base64string);
19        }
20        base64string
21    }
22}