aws_smithy_types/
base64.rs1use base64_simd::STANDARD;
9use std::error::Error;
10
11#[derive(Debug)]
13pub struct DecodeError(base64_simd::Error);
14
15impl Error for DecodeError {
16 fn source(&self) -> Option<&(dyn Error + 'static)> {
17 Some(&self.0)
18 }
19}
20
21impl std::fmt::Display for DecodeError {
22 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
23 write!(f, "failed to decode base64")
24 }
25}
26
27pub fn decode(input: impl AsRef<str>) -> Result<Vec<u8>, DecodeError> {
31 STANDARD.decode_to_vec(input.as_ref()).map_err(DecodeError)
32}
33
34pub fn encode(input: impl AsRef<[u8]>) -> String {
36 STANDARD.encode_to_string(input.as_ref())
37}
38
39pub fn encoded_length(length: usize) -> usize {
41 STANDARD.encoded_length(length)
42}