qualia_core_db/net/qdnf/policy_labels/
projection.rs1use super::flow::JobLabelContext;
4use super::types::{Confidentiality, LabelFields};
5use crate::net::qdnf::errors::QdnfError;
6
7#[repr(u8)]
9#[derive(Clone, Copy, Debug, PartialEq, Eq)]
10pub enum DerivedSink {
11 Reply = 1,
12 Summary = 2,
13 Translation = 3,
14 Embedding = 4,
15 ModelContext = 5,
16 QueryResult = 6,
17 Export = 7,
18 Log = 8,
19 Receipt = 9,
20 Backup = 10,
21}
22
23pub fn project_sensitivity(fields: &LabelFields) -> Result<u8, QdnfError> {
26 fields.confidentiality.lattice_rank()
27}
28
29pub fn require_labelled(fields: &LabelFields) -> Result<(), QdnfError> {
31 if fields.confidentiality == Confidentiality::Unknown {
32 return Err(QdnfError::Denied);
33 }
34 if fields.issuer.is_zero() {
35 return Err(QdnfError::Unauthorized);
36 }
37 Ok(())
38}
39
40pub fn require_labelled_content(
42 protected_content: bool,
43 fields: Option<&LabelFields>,
44) -> Result<Confidentiality, QdnfError> {
45 match (protected_content, fields) {
46 (true, None) => Err(QdnfError::Incomplete),
47 (false, None) => Ok(Confidentiality::C0Public),
48 (_, Some(fields)) => {
49 if fields.confidentiality.is_unknown() {
50 return Err(QdnfError::Denied);
51 }
52 Ok(fields.confidentiality)
53 }
54 }
55}
56
57pub fn project_sink(ctx: &JobLabelContext, _sink: DerivedSink) -> Result<LabelFields, QdnfError> {
59 let current = *ctx.current();
60 if current.confidentiality.is_unknown() {
61 return Err(QdnfError::Incomplete);
62 }
63 Ok(current)
64}