Skip to content

Commit

Permalink
fix: rename SALT_LENGTH to SALT_SIZE for consistency
Browse files Browse the repository at this point in the history
  • Loading branch information
Xiretza committed Jun 21, 2022
1 parent 35a9492 commit 25de264
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 6 deletions.
4 changes: 2 additions & 2 deletions src/crypto.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use sodiumoxide::crypto::{
sign,
};

use crate::utils::{SALT_LENGTH, SYMMETRIC_KEY_SIZE};
use crate::utils::{SALT_SIZE, SYMMETRIC_KEY_SIZE};

use super::error::{Error, Result};

Expand All @@ -34,7 +34,7 @@ pub fn init() -> Result<()> {
to_enc_error!(sodiumoxide::init(), "Failed initialising libsodium")
}

pub fn derive_key(salt: &[u8; SALT_LENGTH], password: &str) -> Result<[u8; SYMMETRIC_KEY_SIZE]> {
pub fn derive_key(salt: &[u8; SALT_SIZE], password: &str) -> Result<[u8; SYMMETRIC_KEY_SIZE]> {
let mut key = [0; SYMMETRIC_KEY_SIZE];
let password = password.as_bytes();

Expand Down
6 changes: 3 additions & 3 deletions src/service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use std::convert::TryInto;
use std::iter;
use std::sync::Arc;

use crate::utils::{PRIVATE_KEY_SIZE, SALT_LENGTH};
use crate::utils::{PRIVATE_KEY_SIZE, SALT_SIZE};
use serde::{Deserialize, Serialize};

use super::{
Expand Down Expand Up @@ -196,7 +196,7 @@ impl Account {
// generation.
let salt = login_challenge
.salt
.get(..SALT_LENGTH)
.get(..SALT_SIZE)
.ok_or(Error::Encryption(
"Salt obtained from login challenge too short: expected at least 16 bytes",
))?
Expand Down Expand Up @@ -352,7 +352,7 @@ impl Account {

let salt = login_challenge
.salt
.get(..SALT_LENGTH)
.get(..SALT_SIZE)
.ok_or(Error::Encryption(
"Salt obtained from login challenge too short: expected at least 16 bytes",
))?
Expand Down
2 changes: 1 addition & 1 deletion src/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ pub type StrBase64 = str;
pub type StringBase64 = String;

/// The size of the salt added to the password to derive the symmetric encryption key
pub const SALT_LENGTH: usize = 16; // sodium.crypto_pwhash_argon2id_SALTBYTES
pub const SALT_SIZE: usize = 16; // sodium.crypto_pwhash_argon2id_SALTBYTES
/// The size of the private encryption key
pub const PRIVATE_KEY_SIZE: usize = 32; // sodium.crypto_box_curve25519xsalsa20poly1305_SECRETKEYBYTES;
/// The size of a symmetric encryption key
Expand Down

0 comments on commit 25de264

Please sign in to comment.