use base64::prelude::*; // TODO: use hex instead use std::io; pub struct Encoder { passphrase: String } impl Encoder { pub fn from(passphrase: String) -> Encoder { Encoder { passphrase } } // TODO: get by ref pub fn encode(&self, line: String) -> String { // TODO: use passphrasee to encode BASE64_STANDARD.encode(line) } // TODO: review error type pub fn decode(&self, line: String) -> io::Result { let content = BASE64_STANDARD.decode(line).map_err(|e| io::Error::new(io::ErrorKind::InvalidData, e))?; match String::from_utf8(content) { Ok(s) => Ok(s), Err(e) => Err(io::Error::new(io::ErrorKind::InvalidData, e)) } } pub fn test_encoded_passphrase(&self, test_passphrase_encoded: String) -> bool { self.passphrase == test_passphrase_encoded } pub fn get_encoded_test_passphrase(&self) -> String { // TODO: encode SALT const with passphrase self.passphrase.clone() } }