2017-03-25 22:45:30 +00:00
|
|
|
pub trait Secret {}
|
2017-03-25 22:15:34 +00:00
|
|
|
|
2017-03-25 22:45:30 +00:00
|
|
|
pub trait Pbkdf2Secret {
|
2017-03-25 22:15:34 +00:00
|
|
|
fn salt(&self) -> &[u8];
|
|
|
|
fn iterations(&self) -> usize;
|
|
|
|
fn digest(&self) -> &[u8];
|
|
|
|
}
|
|
|
|
|
2017-03-25 22:45:30 +00:00
|
|
|
#[derive(Clone, Debug, PartialEq, Eq)]
|
|
|
|
pub struct Plain(pub String);
|
2017-03-25 22:15:34 +00:00
|
|
|
|
2017-03-25 22:45:30 +00:00
|
|
|
impl Secret for Plain {}
|
2017-03-25 22:15:34 +00:00
|
|
|
|
2017-03-25 22:45:30 +00:00
|
|
|
#[derive(Clone, Debug, PartialEq, Eq)]
|
2017-03-25 22:15:34 +00:00
|
|
|
pub struct Pbkdf2Sha1 {
|
|
|
|
pub salt: Vec<u8>,
|
|
|
|
pub iterations: usize,
|
|
|
|
pub digest: Vec<u8>,
|
|
|
|
}
|
|
|
|
|
2017-03-25 22:45:30 +00:00
|
|
|
impl Secret for Pbkdf2Sha1 {}
|
2017-03-25 22:15:34 +00:00
|
|
|
|
2017-03-25 22:45:30 +00:00
|
|
|
impl Pbkdf2Secret for Pbkdf2Sha1 {
|
2017-03-25 22:15:34 +00:00
|
|
|
fn salt(&self) -> &[u8] {
|
|
|
|
&self.salt
|
|
|
|
}
|
|
|
|
fn iterations(&self) -> usize {
|
|
|
|
self.iterations
|
|
|
|
}
|
|
|
|
fn digest(&self) -> &[u8] {
|
|
|
|
&self.digest
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-03-25 22:45:30 +00:00
|
|
|
#[derive(Clone, Debug, PartialEq, Eq)]
|
2017-03-25 22:15:34 +00:00
|
|
|
pub struct Pbkdf2Sha256 {
|
|
|
|
pub salt: Vec<u8>,
|
|
|
|
pub iterations: usize,
|
|
|
|
pub digest: Vec<u8>,
|
|
|
|
}
|
|
|
|
|
2017-03-25 22:45:30 +00:00
|
|
|
impl Secret for Pbkdf2Sha256 {}
|
2017-03-25 22:15:34 +00:00
|
|
|
|
2017-03-25 22:45:30 +00:00
|
|
|
impl Pbkdf2Secret for Pbkdf2Sha256 {
|
2017-03-25 22:15:34 +00:00
|
|
|
fn salt(&self) -> &[u8] {
|
|
|
|
&self.salt
|
|
|
|
}
|
|
|
|
fn iterations(&self) -> usize {
|
|
|
|
self.iterations
|
|
|
|
}
|
|
|
|
fn digest(&self) -> &[u8] {
|
|
|
|
&self.digest
|
|
|
|
}
|
|
|
|
}
|