use crate::FBError; use base64::prelude::{BASE64_STANDARD, Engine}; use bincode::{Options, DefaultOptions}; pub struct FBKey { pub(crate) indices: Vec>, } impl FBKey { pub fn export(&self) -> String { let binc = DefaultOptions::new(); let indice_bytes = binc.serialize(&self.indices) .unwrap(); BASE64_STANDARD.encode(&indice_bytes) } pub fn import(key_str: &str) -> Result { let binc = DefaultOptions::new(); let indice_bytes = BASE64_STANDARD.decode(key_str) .map_err(|_| FBError::DecodeError)?; let indices: Vec<_> = binc.deserialize(&indice_bytes) .map_err(|_| FBError::DecodeError)?; if indices.len() < 2 { return Err(FBError::DecodeError); } Ok (FBKey {indices}) } }