use crate::error::Error; use crate::hash::Hash; #[derive(Debug)] pub struct PaperKey(Hash); impl PaperKey { pub fn generate() -> Result { use gen_passphrase::{dictionary::EFF_SHORT_2, generate}; let passphrase = generate(&[EFF_SHORT_2], 7, Some("-")); Ok(Self(Hash::from_plain(passphrase)?)) } pub fn from_hash(hash: impl Into) -> Self { Self(Hash::from_hash(hash)) } pub fn plain(&self) -> Option<&str> { self.0.plain() } pub fn hash(&self) -> &str { self.0.hash() } pub fn compare(&self, plain: &str) -> Result { self.0.compare(plain).map_err(Error::from) } }