Debian Codegraph @

build/rust/base64_13/lib.rs

raw
1 /* This Source Code Form is subject to the terms of the Mozilla Public
2 * License, v. 2.0. If a copy of the MPL was not distributed with this
3 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
4
5 pub use base64::engine::general_purpose::*;
6 pub use base64::DecodeError;
7 use base64::Engine;
8
9 // Re-implement some of the 0.13 APIs on top of 0.21
10
11 pub fn decode<T: AsRef<[u8]>>(input: T) -> Result<Vec<u8>, DecodeError> {
12 STANDARD.decode(input)
13 }
14
15 pub fn encode<T: AsRef<[u8]>>(input: T) -> String {
16 STANDARD.encode(input)
17 }
18
19 pub fn decode_config<T: AsRef<[u8]>>(
20 input: T,
21 engine: GeneralPurpose,
22 ) -> Result<Vec<u8>, DecodeError> {
23 engine.decode(input)
24 }
25
26 pub fn encode_config<T: AsRef<[u8]>>(input: T, engine: GeneralPurpose) -> String {
27 engine.encode(input)
28 }
29
30 pub fn encode_config_slice<T: AsRef<[u8]>>(
31 input: T,
32 engine: GeneralPurpose,
33 output: &mut [u8],
34 ) -> usize {
35 engine
36 .encode_slice(input, output)
37 .expect("Output buffer too small")
38 }
39
40 pub fn encode_config_buf<T: AsRef<[u8]>>(input: T, engine: GeneralPurpose, buf: &mut String) {
41 engine.encode_string(input, buf)
42 }