more API simplifications

This commit is contained in:
lumi 2017-03-25 23:45:30 +01:00
commit 97f597d89d
6 changed files with 34 additions and 55 deletions

View file

@ -1,39 +1,26 @@
pub trait SecretKind {
type Value: PartialEq;
}
pub trait Secret {}
pub trait Pbkdf2SecretValue {
pub trait Pbkdf2Secret {
fn salt(&self) -> &[u8];
fn iterations(&self) -> usize;
fn digest(&self) -> &[u8];
}
pub struct Plain;
#[derive(Clone, Debug, PartialEq, Eq)]
pub struct Plain(pub String);
#[derive(PartialEq)]
pub struct PlainValue(pub String);
impl SecretKind for Plain {
type Value = PlainValue;
}
impl Secret for Plain {}
#[derive(Clone, Debug, PartialEq, Eq)]
pub struct Pbkdf2Sha1 {
pub salt: Vec<u8>,
pub iterations: usize,
}
#[derive(PartialEq)]
pub struct Pbkdf2Sha1Value {
pub salt: Vec<u8>,
pub iterations: usize,
pub digest: Vec<u8>,
}
impl SecretKind for Pbkdf2Sha1 {
type Value = Pbkdf2Sha1Value;
}
impl Secret for Pbkdf2Sha1 {}
impl Pbkdf2SecretValue for Pbkdf2Sha1Value {
impl Pbkdf2Secret for Pbkdf2Sha1 {
fn salt(&self) -> &[u8] {
&self.salt
}
@ -45,23 +32,16 @@ impl Pbkdf2SecretValue for Pbkdf2Sha1Value {
}
}
#[derive(Clone, Debug, PartialEq, Eq)]
pub struct Pbkdf2Sha256 {
pub salt: Vec<u8>,
pub iterations: usize,
}
#[derive(PartialEq)]
pub struct Pbkdf2Sha256Value {
pub salt: Vec<u8>,
pub iterations: usize,
pub digest: Vec<u8>,
}
impl SecretKind for Pbkdf2Sha256 {
type Value = Pbkdf2Sha256Value;
}
impl Secret for Pbkdf2Sha256 {}
impl Pbkdf2SecretValue for Pbkdf2Sha256Value {
impl Pbkdf2Secret for Pbkdf2Sha256 {
fn salt(&self) -> &[u8] {
&self.salt
}