validate_page_number

Function validate_page_number 

Source
pub fn validate_page_number(
    page: Option<u32>,
) -> Result<Option<u32>, ValidationError>
Expand description

Validates and normalizes a page number parameter.

This function ensures that page numbers are within safe bounds to prevent resource exhaustion attacks.

§Behavior

  • Returns None if None is provided (use API default, typically 0)
  • Caps page number at MAX_PAGE_NUMBER with warning log
  • Returns the validated page number

§Returns

A Result containing the validated page number 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_number, MAX_PAGE_NUMBER};

// None passes through
assert_eq!(validate_page_number(None).unwrap(), None);

// Normal value passes through
assert_eq!(validate_page_number(Some(10)).unwrap(), Some(10));

// Too large is capped (with warning log)
assert_eq!(validate_page_number(Some(99999)).unwrap(), Some(MAX_PAGE_NUMBER));

§Errors

Returns an error if validation fails due to invalid input parameters.