@@ -5,7 +5,7 @@ use std::{
5
5
time:: Duration ,
6
6
} ;
7
7
8
- use crate :: { directory:: watch_directory, ssh :: Authentication } ;
8
+ use crate :: directory:: watch_directory;
9
9
use log:: { error, warn} ;
10
10
use notify:: RecommendedWatcher ;
11
11
use ssh_key:: { HashAlg , PublicKey } ;
@@ -15,6 +15,16 @@ use tokio::{
15
15
task:: JoinHandle ,
16
16
} ;
17
17
18
+ #[ derive( Debug , Clone , Copy , PartialEq , Eq , PartialOrd , Ord ) ]
19
+ pub ( crate ) enum AuthenticationType {
20
+ /// Not authenticated.
21
+ None ,
22
+ /// Authenticated as a valid user.
23
+ User ,
24
+ /// Authenticated as an admin.
25
+ Admin ,
26
+ }
27
+
18
28
#[ derive( Debug ) ]
19
29
pub ( crate ) struct FingerprintsValidator {
20
30
user_fingerprints : Arc < RwLock < HashSet < String > > > ,
@@ -146,18 +156,18 @@ impl FingerprintsValidator {
146
156
} )
147
157
}
148
158
149
- pub ( crate ) fn authenticate_fingerprint ( & self , fingerprint : & str ) -> Authentication {
159
+ pub ( crate ) fn authenticate_fingerprint ( & self , fingerprint : & str ) -> AuthenticationType {
150
160
if self
151
161
. admin_fingerprints
152
162
. read ( )
153
163
. unwrap ( )
154
164
. contains ( fingerprint)
155
165
{
156
- Authentication :: Admin
166
+ AuthenticationType :: Admin
157
167
} else if self . user_fingerprints . read ( ) . unwrap ( ) . contains ( fingerprint) {
158
- Authentication :: User
168
+ AuthenticationType :: User
159
169
} else {
160
- Authentication :: None
170
+ AuthenticationType :: None
161
171
}
162
172
}
163
173
}
@@ -172,9 +182,7 @@ impl Drop for FingerprintsValidator {
172
182
mod fingerprints_validator_tests {
173
183
use std:: sync:: LazyLock ;
174
184
175
- use crate :: ssh:: Authentication ;
176
-
177
- use super :: FingerprintsValidator ;
185
+ use super :: { AuthenticationType , FingerprintsValidator } ;
178
186
use russh_keys:: { key:: PublicKey , parse_public_key_base64} ;
179
187
180
188
static USER_KEYS_DIRECTORY : & str = concat ! ( env!( "CARGO_MANIFEST_DIR" ) , "/tests/data/user_keys" ) ;
@@ -214,19 +222,19 @@ mod fingerprints_validator_tests {
214
222
. unwrap ( ) ;
215
223
assert_eq ! (
216
224
validator. authenticate_fingerprint( & ADMIN_KEY . fingerprint( ) ) ,
217
- Authentication :: Admin
225
+ AuthenticationType :: Admin
218
226
) ;
219
227
assert_eq ! (
220
228
validator. authenticate_fingerprint( & KEY_ONE . fingerprint( ) ) ,
221
- Authentication :: User
229
+ AuthenticationType :: User
222
230
) ;
223
231
assert_eq ! (
224
232
validator. authenticate_fingerprint( & KEY_TWO . fingerprint( ) ) ,
225
- Authentication :: User
233
+ AuthenticationType :: User
226
234
) ;
227
235
assert_eq ! (
228
236
validator. authenticate_fingerprint( & UNKNOWN_KEY . fingerprint( ) ) ,
229
- Authentication :: None
237
+ AuthenticationType :: None
230
238
) ;
231
239
}
232
240
}
0 commit comments