clean up lots of things, server-side API improved

This commit is contained in:
lumi 2017-03-25 23:15:34 +01:00
commit 6c11716926
8 changed files with 419 additions and 272 deletions

74
sasl/src/secret.rs Normal file
View file

@ -0,0 +1,74 @@
pub trait SecretKind {
type Value: PartialEq;
}
pub trait Pbkdf2SecretValue {
fn salt(&self) -> &[u8];
fn iterations(&self) -> usize;
fn digest(&self) -> &[u8];
}
pub struct Plain;
#[derive(PartialEq)]
pub struct PlainValue(pub String);
impl SecretKind for Plain {
type Value = PlainValue;
}
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 Pbkdf2SecretValue for Pbkdf2Sha1Value {
fn salt(&self) -> &[u8] {
&self.salt
}
fn iterations(&self) -> usize {
self.iterations
}
fn digest(&self) -> &[u8] {
&self.digest
}
}
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 Pbkdf2SecretValue for Pbkdf2Sha256Value {
fn salt(&self) -> &[u8] {
&self.salt
}
fn iterations(&self) -> usize {
self.iterations
}
fn digest(&self) -> &[u8] {
&self.digest
}
}