tiny_crypto/encoding/
mod.rs1pub trait Encoder {
6 type Error: std::error::Error;
7
8 fn to_text(&self, input: &[u8]) -> String;
9 fn from_text(&self, input: &str) -> Result<Vec<u8>, Self::Error>;
10}
11
12mod base64;
13pub const BASE64: base64::Base64 = base64::Base64;
15
16mod hex;
17pub const HEX: hex::Hex = hex::Hex;
19
20#[cfg(test)]
21mod tests {
22 use super::*;
23 use rstest::*;
24
25 #[rstest]
26 #[case(BASE64)]
27 #[case(HEX)]
28 fn to_and_from_text(#[case] encoder: impl Encoder) {
29 let plain = "some text".as_bytes();
30 assert_eq!(plain, &encoder.from_text(&encoder.to_text(plain)).unwrap());
31 }
32}