settings/security: generate paper key
This commit is contained in:
parent
c1daa34f2c
commit
a67c7559b9
12 changed files with 183 additions and 4 deletions
|
|
@ -9,3 +9,4 @@ rand_core = { version = "0.6", features = ["std"] }
|
|||
thiserror = { workspace = true }
|
||||
nanoid = { workspace = true }
|
||||
nanoid-dictionary = { workspace = true }
|
||||
gen_passphrase = { version = "0.1", features = ["eff_short_2"] }
|
||||
|
|
@ -1,8 +1,10 @@
|
|||
mod error;
|
||||
mod hash;
|
||||
mod paper_key;
|
||||
mod password;
|
||||
mod secret;
|
||||
|
||||
pub use error::Error;
|
||||
pub use paper_key::PaperKey;
|
||||
pub use password::Password;
|
||||
pub use secret::{Secret, SecretString};
|
||||
|
|
|
|||
26
crates/hash/src/paper_key.rs
Normal file
26
crates/hash/src/paper_key.rs
Normal file
|
|
@ -0,0 +1,26 @@
|
|||
use crate::error::Error;
|
||||
use crate::hash::Hash;
|
||||
|
||||
#[derive(Debug)]
|
||||
pub struct PaperKey(Hash);
|
||||
|
||||
impl PaperKey {
|
||||
pub fn generate() -> Result<Self, Error> {
|
||||
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<String>) -> 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<bool, Error> {
|
||||
self.0.compare(plain).map_err(Error::from)
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue