coraza 0.1.0

Safe Rust bindings to OWASP Coraza WAF
/*
 * Copyright 2022 OWASP Coraza contributors
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

/// Errors that can occur when using the Coraza WAF.
#[derive(Debug, thiserror::Error)]
pub enum Error {
    /// WAF creation failed with the given error message.
    #[error("WAF creation failed: {0}")]
    WafCreation(String),

    /// The WAF configuration is invalid or has already been consumed.
    #[error("WAF config is invalid or has been consumed")]
    InvalidConfig,

    /// The transaction handle is invalid or has already been closed.
    #[error("transaction is invalid or has been closed")]
    InvalidTransaction,

    /// The request was interrupted by a matching rule.
    #[error("intervention: action={action}, status={status}, data={data:?}, rule_id={rule_id}")]
    Intervention {
        /// The action taken (e.g., "deny", "redirect", "drop").
        action: String,
        /// The HTTP status code (e.g., 403, 302).
        status: i32,
        /// Additional data (e.g., redirect URL).
        data: Option<String>,
        /// The rule ID that triggered the intervention.
        rule_id: i32,
    },

    /// A body read/write operation failed.
    #[error("body operation failed: {0}")]
    BodyOperation(String),

    /// The rule engine returned an unexpected error.
    #[error("rule engine error")]
    RuleEngineError,
}