ruvector_security/
error.rs

1//! Security error types
2
3use std::path::PathBuf;
4
5/// Result type for security operations
6pub type SecurityResult<T> = std::result::Result<T, SecurityError>;
7
8/// Security-related errors
9#[derive(Debug, thiserror::Error)]
10pub enum SecurityError {
11    /// Invalid path provided
12    #[error("Invalid path: {0}")]
13    InvalidPath(PathBuf),
14
15    /// Path traversal attempt detected
16    #[error("Path traversal attempt detected: {0}")]
17    PathTraversal(PathBuf),
18
19    /// Path is outside allowed directories
20    #[error("Path {path} is outside allowed directories")]
21    PathOutsideAllowed {
22        path: PathBuf,
23        allowed: Vec<PathBuf>,
24    },
25
26    /// Path contains invalid characters
27    #[error("Path contains invalid characters: {0}")]
28    InvalidPathCharacters(PathBuf),
29
30    /// Symlink detected when not allowed
31    #[error("Symlink detected: {0}")]
32    SymlinkDetected(PathBuf),
33
34    /// Authentication required but not provided
35    #[error("Authentication required")]
36    AuthenticationRequired,
37
38    /// Invalid authentication token
39    #[error("Invalid authentication token")]
40    InvalidToken,
41
42    /// Token has expired
43    #[error("Token has expired")]
44    TokenExpired,
45
46    /// Rate limit exceeded
47    #[error("Rate limit exceeded, retry after {retry_after_secs} seconds")]
48    RateLimitExceeded { retry_after_secs: u64 },
49
50    /// FFI null pointer
51    #[error("Null pointer passed to FFI function")]
52    NullPointer,
53
54    /// FFI misaligned pointer
55    #[error("Misaligned pointer: address {ptr:#x} requires {required_alignment}-byte alignment")]
56    MisalignedPointer { ptr: usize, required_alignment: usize },
57
58    /// FFI size overflow
59    #[error("Size overflow in FFI operation")]
60    SizeOverflow,
61
62    /// FFI buffer too large
63    #[error("Buffer too large: {0} bytes exceeds maximum")]
64    BufferTooLarge(usize),
65
66    /// Allocation failure
67    #[error("Memory allocation failed")]
68    AllocationFailed,
69
70    /// IO error
71    #[error("IO error: {0}")]
72    Io(#[from] std::io::Error),
73
74    /// Configuration error
75    #[error("Configuration error: {0}")]
76    Config(String),
77}