]> git.proxmox.com Git - proxmox.git/blob - proxmox-acme/src/b64u.rs
move to proxmox-acme
[proxmox.git] / proxmox-acme / src / b64u.rs
1 fn config() -> base64::Config {
2 base64::Config::new(base64::CharacterSet::UrlSafe, false)
3 }
4
5 /// Encode bytes as base64url into a `String`.
6 pub fn encode(data: &[u8]) -> String {
7 base64::encode_config(data, config())
8 }
9
10 // curiously currently unused as we don't deserialize any of that
11 // /// Decode bytes from a base64url string.
12 // pub fn decode(data: &str) -> Result<Vec<u8>, base64::DecodeError> {
13 // base64::decode_config(data, config())
14 // }
15
16 /// Our serde module for encoding bytes as base64url encoded strings.
17 pub mod bytes {
18 use serde::{Serialize, Serializer};
19 //use serde::{Deserialize, Deserializer};
20
21 pub fn serialize<S>(data: &[u8], serializer: S) -> Result<S::Ok, S::Error>
22 where
23 S: Serializer,
24 {
25 super::encode(data).serialize(serializer)
26 }
27
28 // curiously currently unused as we don't deserialize any of that
29 // pub fn deserialize<'de, D>(deserializer: D) -> Result<Vec<u8>, D::Error>
30 // where
31 // D: Deserializer<'de>,
32 // {
33 // use serde::de::Error;
34
35 // Ok(super::decode(&String::deserialize(deserializer)?)
36 // .map_err(|e| D::Error::custom(e.to_string()))?)
37 // }
38 }