squaredb_enc 1.0.0-beta

Squaredb - Enhance your DB with extendability and performance.
Documentation
use crate::err::EncryptionError;
use pbkdf2:: {
  password_hash:: {
    PasswordHasher,
    Salt
  },
  Params,
  Pbkdf2,
};
use crate::SALT_B64;

pub struct PBKDF;

pub trait KeyDerivation {
    fn new(password: String) -> Result<Vec<u8>, EncryptionError>;
}

impl KeyDerivation for PBKDF {
  fn new(password: String) -> Result<Vec<u8>,EncryptionError> {
    let salt = Salt::from_b64(SALT_B64).unwrap();

    let params = Params {
      rounds: 4096,
      output_length: 32,
    };

    let hash = Pbkdf2
    .hash_password_customized(password.as_bytes(), None, None, params, salt)
    .map_err(|err| EncryptionError::KeyGenerationFailed(err.to_string()))?;
    
    Ok(hash.hash.unwrap().as_ref().to_vec())
  }
}