pdk-jwt-lib 1.10.0

PDK JWT Library
Documentation
// Copyright (c) 2026, Salesforce, Inc.,
// All rights reserved.
// For full license text, see the LICENSE.txt file

//! # Claim Validation Rules
//!
//! This module provides structures for defining custom claim validation rules
//! using PDK scripts for flexible JWT claim validation.

use pdk_script::{Evaluator, Script};

/// Stores the name of the claim involved in the rule, and the [`Script`]
/// which will evaluate the claim value.
#[derive(Debug, Clone)]
pub struct ScriptClaimRule {
    claim_name: String,

    rule: Script,
}

impl ScriptClaimRule {
    /// Create a new [`ScriptClaimRule`].
    pub fn new(claim_name: String, rule: &Script) -> Self {
        Self::new_owned(claim_name, rule.clone())
    }

    /// Create a new [`ScriptClaimRule`] from a claim name and a rule.
    pub fn new_owned(claim_name: String, rule: Script) -> Self {
        Self { claim_name, rule }
    }

    /// Get the claim name.
    pub fn claim_name(&self) -> &str {
        &self.claim_name
    }

    /// Get the evaluator for the rule.
    pub fn evaluator(&self) -> Evaluator {
        self.rule.evaluator()
    }
}