@@ -33,9 +33,9 @@ fn normalize(pass: &[u8]) -> Vec<u8> {
33
33
}
34
34
}
35
35
36
- fn hi ( str : & [ u8 ] , salt : & [ u8 ] , i : u32 ) -> io :: Result < GenericArray < u8 , U32 > > {
36
+ fn hi ( str : & [ u8 ] , salt : & [ u8 ] , i : u32 ) -> GenericArray < u8 , U32 > {
37
37
let mut hmac = Hmac :: < Sha256 > :: new ( str)
38
- . map_err ( |_| invalid_key_length_error ( ) ) ? ;
38
+ . expect ( "HMAC is able to accept all key sizes" ) ;
39
39
hmac. input ( salt) ;
40
40
hmac. input ( & [ 0 , 0 , 0 , 1 ] ) ;
41
41
let mut prev = hmac. result ( ) . code ( ) ;
@@ -52,7 +52,7 @@ fn hi(str: &[u8], salt: &[u8], i: u32) -> io::Result<GenericArray<u8, U32>> {
52
52
}
53
53
}
54
54
55
- Ok ( hi )
55
+ hi
56
56
}
57
57
58
58
enum State {
@@ -149,10 +149,10 @@ impl ScramSha256 {
149
149
Err ( e) => return Err ( io:: Error :: new ( io:: ErrorKind :: InvalidInput , e) ) ,
150
150
} ;
151
151
152
- let salted_password = hi ( & password, & salt, parsed. iteration_count ) ? ;
152
+ let salted_password = hi ( & password, & salt, parsed. iteration_count ) ;
153
153
154
154
let mut hmac = Hmac :: < Sha256 > :: new ( & salted_password)
155
- . map_err ( |_| invalid_key_length_error ( ) ) ? ;
155
+ . expect ( "HMAC is able to accept all key sizes" ) ;
156
156
hmac. input ( b"Client Key" ) ;
157
157
let client_key = hmac. result ( ) . code ( ) ;
158
158
@@ -166,7 +166,7 @@ impl ScramSha256 {
166
166
let auth_message = format ! ( "n=,r={},{},{}" , client_nonce, message, self . message) ;
167
167
168
168
let mut hmac = Hmac :: < Sha256 > :: new ( & stored_key)
169
- . map_err ( |_| invalid_key_length_error ( ) ) ? ;
169
+ . expect ( "HMAC is able to accept all key sizes" ) ;
170
170
hmac. input ( auth_message. as_bytes ( ) ) ;
171
171
let client_signature = hmac. result ( ) ;
172
172
@@ -219,12 +219,12 @@ impl ScramSha256 {
219
219
} ;
220
220
221
221
let mut hmac = Hmac :: < Sha256 > :: new ( & salted_password)
222
- . map_err ( |_| invalid_key_length_error ( ) ) ? ;
222
+ . expect ( "HMAC is able to accept all key sizes" ) ;
223
223
hmac. input ( b"Server Key" ) ;
224
224
let server_key = hmac. result ( ) ;
225
225
226
226
let mut hmac = Hmac :: < Sha256 > :: new ( & server_key. code ( ) )
227
- . map_err ( |_| invalid_key_length_error ( ) ) ? ;
227
+ . expect ( "HMAC is able to accept all key sizes" ) ;
228
228
hmac. input ( auth_message. as_bytes ( ) ) ;
229
229
hmac. verify ( & verifier) . map_err ( |_| io:: Error :: new (
230
230
io:: ErrorKind :: InvalidInput ,
@@ -399,10 +399,6 @@ enum ServerFinalMessage<'a> {
399
399
Verifier ( & ' a str ) ,
400
400
}
401
401
402
- fn invalid_key_length_error ( ) -> io:: Error {
403
- io:: Error :: new ( io:: ErrorKind :: InvalidInput , "invalid key length" )
404
- }
405
-
406
402
#[ cfg( test) ]
407
403
mod test {
408
404
use super :: * ;
0 commit comments