@@ -15,6 +15,8 @@ pub enum UserError {
15
15
Uuid ( #[ from] uuid:: Error ) ,
16
16
#[ error( "error decoding hex data: {0}" ) ]
17
17
Hex ( #[ from] hex:: FromHexError ) ,
18
+ #[ error( "error decoding UTF-8 data: {0}" ) ]
19
+ Utf8 ( #[ from] std:: string:: FromUtf8Error ) ,
18
20
}
19
21
20
22
#[ derive( Debug , Clone , PartialEq , Serialize , Deserialize ) ]
@@ -31,7 +33,7 @@ pub struct User {
31
33
deserialize_with = "hex::deserialize"
32
34
) ]
33
35
pub token : Vec < u8 > ,
34
- pub salt : Vec < u8 > ,
36
+ pub salt : String ,
35
37
#[ serde( default = "default_none" ) ]
36
38
pub comment : Option < String > ,
37
39
#[ serde( default = "default_none" ) ]
@@ -47,7 +49,7 @@ impl User {
47
49
let name = "Hyperion" . to_owned ( ) ;
48
50
let salt = Self :: generate_salt ( ) ;
49
51
let token = Self :: generate_token ( ) ;
50
- let password = Self :: hash_password ( "hyperion" , & salt) ;
52
+ let password = Self :: hash_password ( "hyperion" , salt. as_bytes ( ) ) ;
51
53
let created_at = chrono:: Utc :: now ( ) ;
52
54
let last_use = created_at;
53
55
@@ -69,8 +71,8 @@ impl User {
69
71
hasher. finalize ( ) . to_vec ( )
70
72
}
71
73
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 ( ) )
74
76
}
75
77
76
78
pub fn hash_password ( password : & str , salt : & [ u8 ] ) -> Vec < u8 > {
@@ -89,7 +91,7 @@ impl TryFrom<db_models::DbUser> for User {
89
91
name : db. user ,
90
92
password : hex:: decode ( db. password ) ?,
91
93
token : hex:: decode ( db. token ) ?,
92
- salt : hex :: decode ( db. salt ) ?,
94
+ salt : String :: from_utf8 ( db. salt ) ?,
93
95
comment : db. comment ,
94
96
id : db. id ,
95
97
created_at : chrono:: DateTime :: parse_from_rfc3339 ( & db. created_at ) ?
0 commit comments