@@ -20,6 +20,7 @@ fn default_schemes() -> Vec<HashingScheme> {
20
20
cost: None ,
21
21
secret: None ,
22
22
secret_file: None ,
23
+ unicode_normalization: false ,
23
24
} ]
24
25
}
25
26
@@ -124,7 +125,7 @@ impl PasswordsConfig {
124
125
/// not be read.
125
126
pub async fn load (
126
127
& self ,
127
- ) -> Result < Vec < ( u16 , Algorithm , Option < u32 > , Option < Vec < u8 > > ) > , anyhow:: Error > {
128
+ ) -> Result < Vec < ( u16 , Algorithm , Option < u32 > , Option < Vec < u8 > > , bool ) > , anyhow:: Error > {
128
129
let mut schemes: Vec < & HashingScheme > = self . schemes . iter ( ) . collect ( ) ;
129
130
schemes. sort_unstable_by_key ( |a| Reverse ( a. version ) ) ;
130
131
schemes. dedup_by_key ( |a| a. version ) ;
@@ -151,13 +152,24 @@ impl PasswordsConfig {
151
152
( None , None ) => None ,
152
153
} ;
153
154
154
- mapped_result. push ( ( scheme. version , scheme. algorithm , scheme. cost , secret) ) ;
155
+ mapped_result. push ( (
156
+ scheme. version ,
157
+ scheme. algorithm ,
158
+ scheme. cost ,
159
+ secret,
160
+ scheme. unicode_normalization ,
161
+ ) ) ;
155
162
}
156
163
157
164
Ok ( mapped_result)
158
165
}
159
166
}
160
167
168
+ #[ allow( clippy:: trivially_copy_pass_by_ref) ]
169
+ const fn is_default_false ( value : & bool ) -> bool {
170
+ !* value
171
+ }
172
+
161
173
/// Parameters for a password hashing scheme
162
174
#[ derive( Debug , Clone , Serialize , Deserialize , JsonSchema ) ]
163
175
pub struct HashingScheme {
@@ -168,6 +180,14 @@ pub struct HashingScheme {
168
180
/// The hashing algorithm to use
169
181
pub algorithm : Algorithm ,
170
182
183
+ /// Whether to apply Unicode normalization to the password before hashing
184
+ ///
185
+ /// Defaults to `false`, and generally recommended to stay false. This is
186
+ /// although recommended when importing password hashs from Synapse, as it
187
+ /// applies an NFKC normalization to the password before hashing it.
188
+ #[ serde( default , skip_serializing_if = "is_default_false" ) ]
189
+ pub unicode_normalization : bool ,
190
+
171
191
/// Cost for the bcrypt algorithm
172
192
#[ serde( skip_serializing_if = "Option::is_none" ) ]
173
193
#[ schemars( default = "default_bcrypt_cost" ) ]
0 commit comments