11// Copyright (c) Microsoft Corporation.
22// Licensed under the MIT License.
33
4+ #[ cfg( windows) ]
45use authenticode:: check_authenticode;
5- use std:: { path:: Path , sync:: LazyLock } ;
6+ use std:: path:: Path ;
7+ #[ cfg( windows) ]
8+ use std:: sync:: LazyLock ;
69
710use crate :: dscerror:: DscError ;
811
912#[ cfg( windows) ]
1013mod authenticode;
1114
15+ #[ cfg( windows) ]
1216static CHECKED_FILES : LazyLock < std:: sync:: Mutex < Vec < String > > > = LazyLock :: new ( || std:: sync:: Mutex :: new ( vec ! [ ] ) ) ;
1317
18+ #[ cfg( windows) ]
1419fn add_file_as_checked ( file_path : & Path ) {
1520 let file_str = file_path. to_string_lossy ( ) . to_string ( ) ;
1621 let mut checked_files = CHECKED_FILES . lock ( ) . unwrap ( ) ;
@@ -19,6 +24,7 @@ fn add_file_as_checked(file_path: &Path) {
1924 }
2025}
2126
27+ #[ cfg( windows) ]
2228fn is_file_checked ( file_path : & Path ) -> bool {
2329 let file_str = file_path. to_string_lossy ( ) . to_string ( ) ;
2430 let checked_files = CHECKED_FILES . lock ( ) . unwrap ( ) ;
@@ -28,26 +34,25 @@ fn is_file_checked(file_path: &Path) -> bool {
2834/// Check the security of a file.
2935///
3036/// # Arguments
31- ///
37+ ///
3238/// * `file_path` - The path to the file to check.
33- ///
39+ ///
3440/// # Returns
35- ///
41+ ///
3642/// * `Ok(())` if the file passes the security checks.
3743/// * `Err(DscError)` if the file fails the security checks.
38- ///
44+ ///
3945/// # Errors
40- ///
46+ ///
4147/// This function will return an error if the Authenticode check fails on Windows.
48+ #[ cfg( windows) ]
4249pub fn check_file_security ( file_path : & Path ) -> Result < ( ) , DscError > {
43- #[ cfg( windows) ]
44- {
45- check_authenticode ( file_path) ?;
46- Ok ( ( ) )
47- }
48- #[ cfg( not( windows) ) ]
49- {
50- // On non-Windows platforms, we skip the Authenticode check.
51- Ok ( ( ) )
52- }
50+ check_authenticode ( file_path) ?;
51+ Ok ( ( ) )
52+ }
53+
54+ /// On non-Windows platforms, this function is a no-op.
55+ #[ cfg( not( windows) ) ]
56+ pub fn check_file_security ( _file_path : & Path ) -> Result < ( ) , DscError > {
57+ Ok ( ( ) )
5358}
0 commit comments