use totp_rs::{Algorithm, TotpUrlError, TOTP}; pub use totp_rs::Secret; // error #[derive(thiserror::Error)] // the rest #[derive(Debug)] pub enum Error { #[error("Totp url error: {0}")] Url(#[from] TotpUrlError), #[error("Totp secret error: {0}")] Secret(String), } pub fn new(secret: Vec, issuer: Option, account_name: String) -> Result { TOTP::new(Algorithm::SHA1, 6, 1, 30, secret, issuer, account_name).map_err(Error::Url) } pub fn secret_to_bytes(secret: &Secret) -> Result, Error> { secret .to_bytes() .map_err(|e| Error::Secret(format!("{:?}", e))) }