File tree Expand file tree Collapse file tree 1 file changed +8
-9
lines changed
Expand file tree Collapse file tree 1 file changed +8
-9
lines changed Original file line number Diff line number Diff line change 1- use once_cell:: sync:: Lazy ;
21use rand:: { distributions:: Alphanumeric , Rng } ;
32
4- use regex:: Regex ;
53use rocket:: {
64 http:: Status ,
75 request:: { FromRequest , Outcome , Request } ,
@@ -34,14 +32,15 @@ impl<'r> FromRequest<'r> for PasswordHeader<'r> {
3432 None => return Outcome :: Error ( ( Status :: Unauthorized , "Missing Authorization header." ) ) ,
3533 } ;
3634
37- static PATTERN : Lazy < Regex > = Lazy :: new ( || Regex :: new ( r"(?i:password) .+" ) . unwrap ( ) ) ;
35+ let ( prefix, suffix) = match value. split_once ( " " ) {
36+ Some ( values) => values,
37+ None => return Outcome :: Error ( ( Status :: Unauthorized , "Invalid Authorization header." ) ) ,
38+ } ;
3839
39- if !PATTERN . is_match ( value) {
40- return Outcome :: Error ( ( Status :: Unauthorized , "Invalid Authorization header." ) ) ;
40+ if prefix. to_lowercase ( ) == "password" {
41+ Outcome :: Success ( PasswordHeader { value : suffix } )
42+ } else {
43+ Outcome :: Error ( ( Status :: Unauthorized , "Invalid Authorization header." ) )
4144 }
42-
43- Outcome :: Success ( PasswordHeader {
44- value : value. split_once ( " " ) . unwrap ( ) . 1 ,
45- } )
4645 }
4746}
You can’t perform that action at this time.
0 commit comments