qualia_core_db/identity/
anvil_policy.rs1#[derive(Copy, Clone, Debug, PartialEq, Eq)]
10pub struct HardwareIsolationFacts {
11 pub iommu_present: bool,
12 pub gpu_device_uuid: [u8; 16],
13 pub sealed_anchor_matches: bool,
14 pub attestation_tier: u8,
15}
16
17impl HardwareIsolationFacts {
18 pub fn hardware_isolated(self) -> bool {
20 let mut has_uuid = false;
21 let mut i = 0;
22 while i < 16 {
23 if self.gpu_device_uuid[i] != 0 {
24 has_uuid = true;
25 break;
26 }
27 i += 1;
28 }
29 self.iommu_present && self.sealed_anchor_matches && self.attestation_tier <= 1 && has_uuid
30 }
31}
32
33#[derive(Copy, Clone, Debug, PartialEq, Eq)]
35pub struct HumanAgencyConsent {
36 pub granted: bool,
37}
38
39pub fn grant_sanctuary_mode(facts: HardwareIsolationFacts, consent: HumanAgencyConsent) -> bool {
42 facts.hardware_isolated() && consent.granted
43}
44
45#[cfg(test)]
46mod tests {
47 use super::*;
48
49 fn isolated_device_001() -> HardwareIsolationFacts {
50 HardwareIsolationFacts {
51 iommu_present: true,
52 gpu_device_uuid: [0xAA; 16],
53 sealed_anchor_matches: true,
54 attestation_tier: 1,
55 }
56 }
57
58 #[test]
59 fn hardware_alone_does_not_unlock() {
60 assert!(!grant_sanctuary_mode(
61 isolated_device_001(),
62 HumanAgencyConsent { granted: false }
63 ));
64 }
65
66 #[test]
67 fn hardware_and_agency_unlock() {
68 assert!(grant_sanctuary_mode(
69 isolated_device_001(),
70 HumanAgencyConsent { granted: true }
71 ));
72 }
73
74 #[test]
75 fn spoofed_empty_uuid_stays_locked() {
76 let mut facts = isolated_device_001();
77 facts.gpu_device_uuid = [0; 16];
78 assert!(!grant_sanctuary_mode(
79 facts,
80 HumanAgencyConsent { granted: true }
81 ));
82 }
83}