pub struct PathPolicy { /* private fields */ }Expand description
Policy controlling how input paths are resolved and opened.
Construct with PathPolicy::new (or Default) and refine with the
builder-style methods.
Implementations§
Source§impl PathPolicy
impl PathPolicy
Sourcepub const fn new() -> Self
pub const fn new() -> Self
Create a policy with safe defaults: no base-directory confinement,
symlinks allowed (but resolved and re-checked), and a
DEFAULT_MAX_FILE_SIZE byte cap.
Sourcepub fn base_dir(self, base: impl Into<PathBuf>) -> Self
pub fn base_dir(self, base: impl Into<PathBuf>) -> Self
Confine all inputs to base: resolved paths must stay within it.
Sourcepub const fn allow_symlinks(self, allow: bool) -> Self
pub const fn allow_symlinks(self, allow: bool) -> Self
Allow (true, the default) or deny (false) symbolic links.
Sourcepub const fn max_file_size(self, limit: u64) -> Self
pub const fn max_file_size(self, limit: u64) -> Self
Set the maximum number of bytes that may be read from a single input.
Sourcepub fn open(&self, requested: &Path) -> Result<OpenedFile, PathSecurityError>
pub fn open(&self, requested: &Path) -> Result<OpenedFile, PathSecurityError>
Resolve, validate and open requested, returning an OpenedFile.
§Errors
Returns a PathSecurityError if the path is empty, contains an
interior NUL, traverses outside the configured base directory, is a
disallowed symlink, is not a regular file, exceeds the size limit, or
cannot be accessed.
Sourcepub fn read(&self, requested: &Path) -> Result<Vec<u8>, PathSecurityError>
pub fn read(&self, requested: &Path) -> Result<Vec<u8>, PathSecurityError>
Open requested and read its contents, hard-capped at the byte limit.
§Errors
As for PathPolicy::open, plus PathSecurityError::TooLarge if the
file streams more than the configured limit.
Trait Implementations§
Source§impl Clone for PathPolicy
impl Clone for PathPolicy
Source§fn clone(&self) -> PathPolicy
fn clone(&self) -> PathPolicy
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more