1use crate::errors;
4use core::default::Default;
5
6pub const ROUNDS_DEFAULT: usize = 5_000;
8
9pub const ROUNDS_MIN: usize = 1_000;
11
12pub const ROUNDS_MAX: usize = 999_999_999;
14
15#[derive(Debug, Clone)]
17pub struct Sha512Params {
18 pub(crate) rounds: usize,
19}
20
21impl Default for Sha512Params {
22 fn default() -> Self {
23 Sha512Params {
24 rounds: ROUNDS_DEFAULT,
25 }
26 }
27}
28
29impl Sha512Params {
30 pub fn new(rounds: usize) -> Result<Sha512Params, errors::CryptError> {
32 if (ROUNDS_MIN..=ROUNDS_MAX).contains(&rounds) {
33 Ok(Sha512Params { rounds })
34 } else {
35 Err(errors::CryptError::RoundsError)
36 }
37 }
38}
39
40#[derive(Debug, Clone)]
42pub struct Sha256Params {
43 pub(crate) rounds: usize,
44}
45
46impl Default for Sha256Params {
47 fn default() -> Self {
48 Sha256Params {
49 rounds: ROUNDS_DEFAULT,
50 }
51 }
52}
53
54impl Sha256Params {
55 pub fn new(rounds: usize) -> Result<Sha256Params, errors::CryptError> {
57 if (ROUNDS_MIN..=ROUNDS_MAX).contains(&rounds) {
58 Ok(Sha256Params { rounds })
59 } else {
60 Err(errors::CryptError::RoundsError)
61 }
62 }
63}