pub fn check_dir_has_required_permissions(dir: &Path) -> Result<(), String> {
        if !dir.exists() {
            return Err(format!(
                "Crypto state directory does not exist: {}",
                dir.display()
            ));
        }
        let metadata = fs::metadata(&dir).map_err(|err| {
            format!(
                "Cannot get the metadata of the crypto state directory {}: {:?}",
                dir.display(),
                err
            )
        })?;
        if !metadata.is_dir() {
            return Err(format!(
                "Crypto state directory should be a directory, not a file: {}",
                dir.display()
            ));
        }
        let permissions = metadata.permissions();
        let unix_permission_bits = permissions.mode();
        let permissions_owner = unix_permission_bits & 0o700;
        if permissions_owner != 0o700 {
            return Err(format!(
                "Crypto state directory {} has permissions {:#o}, disallowing owner access",
                &dir.display(),
                unix_permission_bits
            ));
        }
        let permissions_all = unix_permission_bits & 0o007;
        if permissions_all != 0 {
            return Err(format!(
                "Crypto state directory {} has permissions {:#o}, allowing general access",
                &dir.display(),
                unix_permission_bits
            ));
        }
        Ok(())
    }
/// Checks that directory `dir` has permissions required for storing crypto
/// states, i.e. the owner can read/write files in the directly, but the
/// directory should not be world-accessible.  (Group permissions are
/// not checked, as these are up to the system setup.) Returns an error
/// if it fails. NOTE: this is only a basic sanity check; the exact
/// permissions depend on the system setup and are out of scope of
/// Crypto Component.
Checks that directory `dir` has permissions required for storing crypto
states, i.e. the owner can read/write files in the directly, but the
directory should not be world-accessible.  (Group permissions are
not checked, as these are up to the system setup.) Returns an error
if it fails. NOTE: this is only a basic sanity check; the exact
permissions depend on the system setup and are out of scope of
Crypto Component.
Checks that directory ` dir ` has permissions required for storing crypto states i . e . the owner can read / write files in the directly but the directory should not be world - accessible . ( Group permissions are not checked as these are up to the system setup . ) Returns an error if it fails . NOTE : this is only a basic sanity check ; the exact permissions depend on the system setup and are out of scope of Crypto Component .
pub fn check_dir_has_required_permissions(dir: &Path) -> Result<(), String> {
        if !dir.exists() {
            return Err(format!(
                "Crypto state directory does not exist: {}",
                dir.display()
            ));
        }
        let metadata = fs::metadata(&dir).map_err(|err| {
            format!(
                "Cannot get the metadata of the crypto state directory {}: {:?}",
                dir.display(),
                err
            )
        })?;
        if !metadata.is_dir() {
            return Err(format!(
                "Crypto state directory should be a directory, not a file: {}",
                dir.display()
            ));
        }
        let permissions = metadata.permissions();
        let unix_permission_bits = permissions.mode();
        let permissions_owner = unix_permission_bits & 0o700;
        if permissions_owner != 0o700 {
            return Err(format!(
                "Crypto state directory {} has permissions {:#o}, disallowing owner access",
                &dir.display(),
                unix_permission_bits
            ));
        }
        let permissions_all = unix_permission_bits & 0o007;
        if permissions_all != 0 {
            return Err(format!(
                "Crypto state directory {} has permissions {:#o}, allowing general access",
                &dir.display(),
                unix_permission_bits
            ));
        }
        Ok(())
    }
pub fn check_dir_has_required_permissions ( dir : & Path ) -> Result < ( ) , String > { if ! dir . exists ( ) { return Err ( format ! ( " " dir display ( ) ) ) ; } let metadata = fs :: metadata ( & dir ) . map_err ( | err | { format ! ( " " dir display ( ) err ) } ) ? ; if ! metadata . is_dir ( ) { return Err ( format ! ( " " dir display ( ) ) ) ; } let permissions = metadata . permissions ( ) ; let unix_permission_bits = permissions . mode ( ) ; let permissions_owner = unix_permission_bits & 0o700 ; if permissions_owner != 0o700 { return Err ( format ! ( " " dir display ( ) unix_permission_bits ) ) ; } let permissions_all = unix_permission_bits & 0o007 ; if permissions_all != 0 { return Err ( format ! ( " " dir display ( ) unix_permission_bits ) ) ; } Ok ( ( ) ) }
Checks that directory `dir` has permissions required for storing crypto
states, i.e.
Checks that directory ` dir ` has permissions required for storing crypto states i . e .
dir
&Path
dir
&Path