Skip to content

Commit

Permalink
Option<i32> for client_kdf_memory and client_kdf_parallelism
Browse files Browse the repository at this point in the history
  • Loading branch information
tessus committed Feb 7, 2023
1 parent 1399737 commit 17c334d
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 12 deletions.
12 changes: 6 additions & 6 deletions src/api/core/accounts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -156,11 +156,11 @@ pub async fn _register(data: JsonUpcase<RegisterData>, mut conn: DbConn) -> Json
Invitation::take(&email, &mut conn).await;

if let Some(client_kdf_parallelism) = data.KdfParallelism {
user.client_kdf_parallelism = client_kdf_parallelism;
user.client_kdf_parallelism = Some(client_kdf_parallelism);
}

if let Some(client_kdf_memory) = data.KdfMemory {
user.client_kdf_memory = client_kdf_memory;
user.client_kdf_memory = Some(client_kdf_memory);
}

if let Some(client_kdf_iter) = data.KdfIterations {
Expand Down Expand Up @@ -376,15 +376,15 @@ async fn post_kdf(data: JsonUpcase<ChangeKdfData>, headers: Headers, mut conn: D
if m < 15 || m > 1024 {
err!("Argon2 memory must be between 15 MB and 1024 MB.")
}
user.client_kdf_memory = m;
user.client_kdf_memory = data.KdfMemory;
} else {
err!("Argon2 memory parameter is required.")
}
if let Some(p) = data.KdfParallelism {
if p < 1 || p > 16 {
err!("Argon2 parallelism must be between 1 and 16.")
}
user.client_kdf_parallelism = p;
user.client_kdf_parallelism = data.KdfParallelism;
} else {
err!("Argon2 parallelism parameter is required.")
}
Expand Down Expand Up @@ -808,8 +808,8 @@ pub async fn _prelogin(data: JsonUpcase<PreloginData>, mut conn: DbConn) -> Json
None => (
User::CLIENT_KDF_TYPE_DEFAULT,
User::CLIENT_KDF_ITER_DEFAULT,
0, // This value is irrelevant, because it won't be in the JSON return value anyway
0, // This value is irrelevant, because it won't be in the JSON return value anyway
None,
None,
),
};

Expand Down
10 changes: 4 additions & 6 deletions src/db/models/user.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,8 @@ db_object! {

pub client_kdf_type: i32,
pub client_kdf_iter: i32,
pub client_kdf_memory: i32,
pub client_kdf_parallelism: i32,
pub client_kdf_memory: Option<i32>,
pub client_kdf_parallelism: Option<i32>,

pub api_key: Option<String>,

Expand Down Expand Up @@ -82,8 +82,6 @@ pub struct UserStampException {
impl User {
pub const CLIENT_KDF_TYPE_DEFAULT: i32 = UserKdfType::Pbkdf2 as i32;
pub const CLIENT_KDF_ITER_DEFAULT: i32 = 600_000;
pub const CLIENT_KDF_MEMO_DEFAULT: i32 = 19;
pub const CLIENT_KDF_PARA_DEFAULT: i32 = 1;

pub fn new(email: String) -> Self {
let now = Utc::now().naive_utc();
Expand Down Expand Up @@ -122,8 +120,8 @@ impl User {

client_kdf_type: Self::CLIENT_KDF_TYPE_DEFAULT,
client_kdf_iter: Self::CLIENT_KDF_ITER_DEFAULT,
client_kdf_memory: Self::CLIENT_KDF_MEMO_DEFAULT,
client_kdf_parallelism: Self::CLIENT_KDF_PARA_DEFAULT,
client_kdf_memory: None,
client_kdf_parallelism: None,

api_key: None,

Expand Down

0 comments on commit 17c334d

Please sign in to comment.