pub fn validate_page_size(size: Option<u32>) -> Result<u32, ValidationError>Expand description
Validates and normalizes a page size parameter.
This function ensures that page sizes are within safe bounds to prevent resource exhaustion attacks.
§Behavior
- Returns
DEFAULT_PAGE_SIZEifNoneis provided - Rejects page size of 0
- Caps page size at
MAX_PAGE_SIZEwith warning log - Returns the validated page size
§Returns
A Result containing the validated page size or a ValidationError.
§Security
§Errors
Returns an error if the API request fails, the resource is not found,
or authentication/authorization fails.
This function prevents DoS attacks from unbounded pagination requests.
§Examples
use veracode_platform::validation::{validate_page_size, DEFAULT_PAGE_SIZE, MAX_PAGE_SIZE};
// Default when None
assert_eq!(validate_page_size(None).unwrap(), DEFAULT_PAGE_SIZE);
// Normal value passes through
assert_eq!(validate_page_size(Some(100)).unwrap(), 100);
// Zero is rejected
assert!(validate_page_size(Some(0)).is_err());
// Too large is capped (with warning log)
assert_eq!(validate_page_size(Some(10000)).unwrap(), MAX_PAGE_SIZE);§Errors
Returns an error if validation fails due to invalid input parameters.