Skip to main content

qualia_core_db/net/qdnf/session/
policy.rs

1//! QPolicy admission for session channels.
2
3use crate::net::qdnf::authority::{admit_service, ContactState, PolicyOutcome};
4use crate::net::qdnf::errors::QdnfError;
5
6/// Gates the channel by policy.
7pub fn gate_channel(
8    outcome: PolicyOutcome,
9    grant_current: bool,
10    contact: ContactState,
11) -> Result<(), QdnfError> {
12    if matches!(contact, ContactState::Blocked | ContactState::Suspended) {
13        return Err(QdnfError::Denied);
14    }
15    admit_service(outcome, grant_current)
16}
17
18#[cfg(test)]
19mod tests {
20    use super::*;
21
22    #[test]
23    fn blocked_contact_cannot_pay_to_bypass() {
24        assert_eq!(
25            gate_channel(PolicyOutcome::Allow, true, ContactState::Blocked),
26            Err(QdnfError::Denied)
27        );
28    }
29}