Skip to main content

ValidationService

ValidationService validates files and RDIndex objects.
Internally, it uses HasherService to verify file and chunk hashes.

pub trait ValidationService: Send + Sync {
...
}

Methods

MethodReturnsDescription
validate_file(entry, path)Result<bool, ValidationError>Validates a single file against its FileEntry.
validate_index(index, base_path)Result<bool, ValidationError>Validates all files described in an RDIndex.

ValidationError

Custom error enum for results of ValidationService. (Uses thiserror)

pub enum ValidationError {
#[error("IO error: {0}")]
Io(#[from] std::io::Error),

#[error("Hash verification failed")]
HashMismatch,
}

Method Details

validate_file(entry, path)

Verifies a file.

Parameters:

NameTypeDescription
entry&FileEntryMetadata of the file to validate
path&strPath to the file on disk

Returns: Result<bool, ValidationError>true if the file is valid.

Notes: Uses HasherService internally to verify the hash of the file and its chunks.


validate_index(index, base_path)

Verifies every file within a rd-index.json.

Parameters:

NameTypeDescription
index&RDIndexRDIndex object describing files to validate
base_path&strDirectory containing the files

Returns: Result<bool, ValidationError>true if all files are valid.

Notes: Internally calls validateFile for each file using HasherService.