helpers.rs

 1// Copyright (c) 2017 Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
 2//
 3// This Source Code Form is subject to the terms of the Mozilla Public
 4// License, v. 2.0. If a copy of the MPL was not distributed with this
 5// file, You can obtain one at http://mozilla.org/MPL/2.0/.
 6
 7use base64;
 8use error::Error;
 9
10/// Codec wrapping base64 encode/decode
11pub struct Base64;
12
13impl Base64 {
14    pub fn decode(s: &str) -> Result<Vec<u8>, Error> {
15        Ok(base64::decode(s)?)
16    }
17
18    pub fn encode(b: &Vec<u8>) -> String {
19        base64::encode(b)
20    }
21}