1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
//! # Safe Input
//! Library
//!
//! A thread-safe library for secure user input processing with support for:
//! - Multi-level validation
//! - High-performance data sanitization
//! - Customizable security rules
//! - Concurrent processing capabilities
//! - Asynchronous validation support
//!
//! ## Example: Synchronous String Validation
//!
//! This example shows how to validate a string with a maximum length synchronously:
//!
//! ```rust
//! use huginn::{SecurityConfig, sanitize_and_validate, Validator, ValidationError};
//!
//! struct LengthValidator {
//! max: usize,
//! }
//!
//! impl Validator<String> for LengthValidator {
//! fn validate(&self, input: &str) -> Result<String, ValidationError> {
//! if input.len() <= self.max {
//! Ok(input.to_string())
//! } else {
//! Err(ValidationError::custom("Input too long"))
//! }
//! }
//!
//! fn target_type(&self) -> &'static str {
//! "string"
//! }
//! }
//!
//! fn main() -> Result<(), Box<dyn std::error::Error>> {
//! let config = SecurityConfig::default();
//! let validator = LengthValidator { max: 10 };
//! let result = sanitize_and_validate("hello", &validator, &config)?;
//! println!("Sanitized input: {}", result.cleaned);
//! Ok(())
//! }
//! ```
//!
//! ## Example: Asynchronous Number Validation
//!
//! This example demonstrates custom configuration and asynchronous number validation:
//!
//! ```rust
//! use huginn::{SecurityConfig, sanitize_and_validate_async, Validator, ValidationError};
//! use async_trait::async_trait;
//!
//! struct NumberValidator;
//!
//! #[async_trait]
//! impl Validator<i32> for NumberValidator {
//! fn validate(&self, input: &str) -> Result<i32, ValidationError> {
//! input.parse().map_err(|_| ValidationError::InvalidFormat { target_type: self.target_type() })
//! }
//!
//! async fn validate_async(&self, input: &str) -> Result<i32, ValidationError> {
//! Ok(self.validate(input)?)
//! }
//!
//! fn target_type(&self) -> &'static str {
//! "i32"
//! }
//! }
//!
//! #[tokio::main]
//! async fn main() -> Result<(), Box<dyn std::error::Error>> {
//! let config = SecurityConfig::builder()
//! .add_forbidden_char('#')
//! .add_blocked_pattern(r"\d{5}")?
//! .build();
//! let validator = NumberValidator;
//! let result = sanitize_and_validate_async("42", &validator, &config).await?;
//! println!("Sanitized number: {}", result.cleaned);
//! Ok(())
//! }
//! ```
/// Module for configuring security parameters
/// Module for handling validation errors
/// Core module for validation and sanitization
// Re-exporting core types
pub use SecurityConfig;
pub use ValidationError;
pub use ;