mirror of
https://gitlab.com/xmpp-rs/xmpp-rs.git
synced 2024-07-12 22:21:53 +00:00
add derive methods to Pbkdf2 secrets
This commit is contained in:
parent
d5e34be0c4
commit
714ee28006
1 changed files with 28 additions and 0 deletions
|
@ -18,6 +18,20 @@ pub struct Pbkdf2Sha1 {
|
||||||
pub digest: Vec<u8>,
|
pub digest: Vec<u8>,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl Pbkdf2Sha1 {
|
||||||
|
#[cfg(feature = "openssl")]
|
||||||
|
pub fn derive(password: &str, salt: &[u8], iterations: usize) -> Result<Pbkdf2Sha1, String> {
|
||||||
|
use common::scram::{ScramProvider, Sha1};
|
||||||
|
use common::Password;
|
||||||
|
let digest = Sha1::derive(&Password::Plain(password.to_owned()), salt, iterations)?;
|
||||||
|
Ok(Pbkdf2Sha1 {
|
||||||
|
salt: salt.to_vec(),
|
||||||
|
iterations: iterations,
|
||||||
|
digest: digest,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
impl Secret for Pbkdf2Sha1 {}
|
impl Secret for Pbkdf2Sha1 {}
|
||||||
|
|
||||||
impl Pbkdf2Secret for Pbkdf2Sha1 {
|
impl Pbkdf2Secret for Pbkdf2Sha1 {
|
||||||
|
@ -33,6 +47,20 @@ pub struct Pbkdf2Sha256 {
|
||||||
pub digest: Vec<u8>,
|
pub digest: Vec<u8>,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl Pbkdf2Sha256 {
|
||||||
|
#[cfg(feature = "openssl")]
|
||||||
|
pub fn derive(password: &str, salt: &[u8], iterations: usize) -> Result<Pbkdf2Sha256, String> {
|
||||||
|
use common::scram::{ScramProvider, Sha256};
|
||||||
|
use common::Password;
|
||||||
|
let digest = Sha256::derive(&Password::Plain(password.to_owned()), salt, iterations)?;
|
||||||
|
Ok(Pbkdf2Sha256 {
|
||||||
|
salt: salt.to_vec(),
|
||||||
|
iterations: iterations,
|
||||||
|
digest: digest,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
impl Secret for Pbkdf2Sha256 {}
|
impl Secret for Pbkdf2Sha256 {}
|
||||||
|
|
||||||
impl Pbkdf2Secret for Pbkdf2Sha256 {
|
impl Pbkdf2Secret for Pbkdf2Sha256 {
|
||||||
|
|
Loading…
Reference in a new issue