Skip to content

Commit f648ed8

Browse files
committed
fix(config): Use salt hex as-is
1 parent 84bb8cb commit f648ed8

File tree

1 file changed

+7
-5
lines changed

1 file changed

+7
-5
lines changed

src/models/users.rs

+7-5
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ pub enum UserError {
1515
Uuid(#[from] uuid::Error),
1616
#[error("error decoding hex data: {0}")]
1717
Hex(#[from] hex::FromHexError),
18+
#[error("error decoding UTF-8 data: {0}")]
19+
Utf8(#[from] std::string::FromUtf8Error),
1820
}
1921

2022
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
@@ -31,7 +33,7 @@ pub struct User {
3133
deserialize_with = "hex::deserialize"
3234
)]
3335
pub token: Vec<u8>,
34-
pub salt: Vec<u8>,
36+
pub salt: String,
3537
#[serde(default = "default_none")]
3638
pub comment: Option<String>,
3739
#[serde(default = "default_none")]
@@ -47,7 +49,7 @@ impl User {
4749
let name = "Hyperion".to_owned();
4850
let salt = Self::generate_salt();
4951
let token = Self::generate_token();
50-
let password = Self::hash_password("hyperion", &salt);
52+
let password = Self::hash_password("hyperion", salt.as_bytes());
5153
let created_at = chrono::Utc::now();
5254
let last_use = created_at;
5355

@@ -69,8 +71,8 @@ impl User {
6971
hasher.finalize().to_vec()
7072
}
7173

72-
pub fn generate_salt() -> Vec<u8> {
73-
hex::encode(Self::generate_token()).into_bytes()
74+
pub fn generate_salt() -> String {
75+
hex::encode(Self::generate_token())
7476
}
7577

7678
pub fn hash_password(password: &str, salt: &[u8]) -> Vec<u8> {
@@ -89,7 +91,7 @@ impl TryFrom<db_models::DbUser> for User {
8991
name: db.user,
9092
password: hex::decode(db.password)?,
9193
token: hex::decode(db.token)?,
92-
salt: hex::decode(db.salt)?,
94+
salt: String::from_utf8(db.salt)?,
9395
comment: db.comment,
9496
id: db.id,
9597
created_at: chrono::DateTime::parse_from_rfc3339(&db.created_at)?

0 commit comments

Comments
 (0)