@@ -13,18 +13,19 @@ use super::Authenticate;
13
13
use log:: error;
14
14
use parsec_interface:: requests:: request:: RequestAuth ;
15
15
use parsec_interface:: requests:: { ResponseStatus , Result } ;
16
+ use parsec_interface:: secrecy:: ExposeSecret ;
16
17
use std:: str;
17
18
18
19
#[ derive( Copy , Clone , Debug ) ]
19
20
pub struct DirectAuthenticator ;
20
21
21
22
impl Authenticate for DirectAuthenticator {
22
23
fn authenticate ( & self , auth : & RequestAuth ) -> Result < ApplicationName > {
23
- if auth. is_empty ( ) {
24
+ if auth. buffer . expose_secret ( ) . is_empty ( ) {
24
25
error ! ( "The direct authenticator does not expect empty authentication values." ) ;
25
26
Err ( ResponseStatus :: AuthenticationError )
26
27
} else {
27
- match str:: from_utf8 ( auth. bytes ( ) ) {
28
+ match str:: from_utf8 ( auth. buffer . expose_secret ( ) ) {
28
29
Ok ( str) => Ok ( ApplicationName ( String :: from ( str) ) ) ,
29
30
Err ( _) => {
30
31
error ! ( "Error parsing the authentication value as a UTF-8 string." ) ;
@@ -47,7 +48,7 @@ mod test {
47
48
let authenticator = DirectAuthenticator { } ;
48
49
49
50
let app_name = "app_name" . to_string ( ) ;
50
- let req_auth = RequestAuth :: from_bytes ( app_name. clone ( ) . into_bytes ( ) ) ;
51
+ let req_auth = RequestAuth :: new ( app_name. clone ( ) . into_bytes ( ) ) ;
51
52
52
53
let auth_name = authenticator
53
54
. authenticate ( & req_auth)
@@ -60,7 +61,7 @@ mod test {
60
61
fn failed_authentication ( ) {
61
62
let authenticator = DirectAuthenticator { } ;
62
63
let status = authenticator
63
- . authenticate ( & RequestAuth :: from_bytes ( vec ! [ 0xff ; 5 ] ) )
64
+ . authenticate ( & RequestAuth :: new ( vec ! [ 0xff ; 5 ] ) )
64
65
. expect_err ( "Authentication should have failed" ) ;
65
66
66
67
assert_eq ! ( status, ResponseStatus :: AuthenticationError ) ;
@@ -70,7 +71,7 @@ mod test {
70
71
fn empty_auth ( ) {
71
72
let authenticator = DirectAuthenticator { } ;
72
73
let status = authenticator
73
- . authenticate ( & RequestAuth :: from_bytes ( Vec :: new ( ) ) )
74
+ . authenticate ( & RequestAuth :: new ( Vec :: new ( ) ) )
74
75
. expect_err ( "Empty auth should have failed" ) ;
75
76
76
77
assert_eq ! ( status, ResponseStatus :: AuthenticationError ) ;
0 commit comments