pub struct Lattice { /* private fields */ }Expand description
The active lattice policy: the closed compartment vocabulary (name↔bit) and the version. Levels and assurances are fixed by their enums (TCB), so only the open dimension — compartments — needs a registry.
Built once at startup from the schema $scope annotations + site policy
(S3, #569) and treated as immutable thereafter (a change is a version bump).
Bit assignments are stable within a version (S4’s compiled TE matrix is keyed
to them via the shared generation).
§Canonical serialization (S1↔S4, #570)
A signed CompiledPolicy must carry the lattice so the PDP and every
distributed AVC reconstruct the identical name↔bit map — otherwise
CompartmentSet bits desync from genesis across processes. The wire form
is deliberately minimal: just the LatticeVersion and the compartment
names in bit-index order. Decoding re-interns those names in that exact
order via Lattice::new, so bit assignments are derived, never trusted
from the wire — a tampered reverse map cannot exist. Use Lattice::to_bytes
/ Lattice::from_bytes for the deterministic (CBOR) byte form, or the
Serialize/Deserialize impls to embed in a larger signed structure.
Implementations§
Source§impl Lattice
impl Lattice
Sourcepub fn new(
version: LatticeVersion,
known_compartments: impl IntoIterator<Item = Compartment>,
) -> Self
pub fn new( version: LatticeVersion, known_compartments: impl IntoIterator<Item = Compartment>, ) -> Self
Construct a lattice policy from a compartment vocabulary, assigning each
name a stable bit index in iteration order (0, 1, 2, …). Duplicate names
collapse to the first index. Names beyond MAX_COMPARTMENTS are
rejected by truncation (they simply never get a bit — fail-closed).
pub fn version(&self) -> LatticeVersion
Sourcepub fn compartment_count(&self) -> u32
pub fn compartment_count(&self) -> u32
Number of compartments in the vocabulary.
Sourcepub fn compartment_names(&self) -> &[Compartment]
pub fn compartment_names(&self) -> &[Compartment]
The compartment vocabulary in canonical construction (bit-index)
order: compartment_names()[i] is the name interned at bit i. This
is the order Lattice::new assigned and the order the wire form
preserves — S4’s PDP can iterate it to align its TE matrix columns with
the exact bits a SecurityLabel carries.
Sourcepub fn to_bytes(&self) -> Vec<u8> ⓘ
pub fn to_bytes(&self) -> Vec<u8> ⓘ
Canonical, deterministic byte form (CBOR) — the same codec the COSE
signing path uses — so a signed CompiledPolicy can carry the lattice
verbatim. Round-trips through Lattice::from_bytes preserving every
name↔bit assignment exactly. Serialization of an in-memory lattice is
infallible.
Sourcepub fn from_bytes(bytes: &[u8]) -> Result<Self, LatticeCodecError>
pub fn from_bytes(bytes: &[u8]) -> Result<Self, LatticeCodecError>
Reconstruct a lattice from its canonical byte form. Fails closed on a
malformed encoding or a vocabulary TryFrom would have to alter
(duplicate names / over-width) — never silently yields a different
lattice than the issuer signed.
Sourcepub fn bit_of(&self, c: &Compartment) -> Option<u32>
pub fn bit_of(&self, c: &Compartment) -> Option<u32>
The bit index assigned to a compartment name, if known.
Sourcepub fn name_of(&self, bit: u32) -> Option<&Compartment>
pub fn name_of(&self, bit: u32) -> Option<&Compartment>
The compartment name for a bit index, if registered.
Sourcepub fn knows(&self, c: &Compartment) -> bool
pub fn knows(&self, c: &Compartment) -> bool
Is c a recognized compartment under this policy?
Sourcepub fn intern<'a>(
&self,
names: impl IntoIterator<Item = &'a Compartment>,
) -> Result<CompartmentSet, LabelError>
pub fn intern<'a>( &self, names: impl IntoIterator<Item = &'a Compartment>, ) -> Result<CompartmentSet, LabelError>
Intern a set of compartment names into a CompartmentSet bitset.
This is the genesis/enrollment seam that turns the human-facing vocabulary
into the packed representation a SecurityLabel carries. An unknown name
is an error (fail-closed) — it never silently becomes “no compartment”.
Sourcepub fn label(
&self,
level: Level,
assurance: Assurance,
names: impl IntoIterator<Item = Compartment>,
) -> Result<SecurityLabel, LabelError>
pub fn label( &self, level: Level, assurance: Assurance, names: impl IntoIterator<Item = Compartment>, ) -> Result<SecurityLabel, LabelError>
Build a SecurityLabel from names, interning compartments through this
policy. The ergonomic genesis constructor: (level, assurance, names) → label. Fails closed on any unknown compartment name.
Sourcepub fn validate(&self, label: &SecurityLabel) -> Result<(), LabelError>
pub fn validate(&self, label: &SecurityLabel) -> Result<(), LabelError>
Validate that a label is well-formed under this policy: every compartment bit it carries maps to a registered name. Use at genesis / enrollment / seal time before a label is allowed to exist. Does NOT touch dominance.
Sourcepub fn top(&self) -> SecurityLabel
pub fn top(&self) -> SecurityLabel
The lattice top ⊤ under this policy = max level, max assurance, all known compartments. The only clearance that dominates every well-formed label. (Useful for genesis-labeling the policy authority itself, and for tests.)
Sourcepub fn bottom(&self) -> SecurityLabel
pub fn bottom(&self) -> SecurityLabel
The lattice bottom ⊥ = (Public, Unverified, {}). Same as
SecurityLabel::bottom; provided here for symmetry with top.
Sourcepub fn can_access(
&self,
subject: &SecurityLabel,
object: &SecurityLabel,
) -> bool
pub fn can_access( &self, subject: &SecurityLabel, object: &SecurityLabel, ) -> bool
Dominance, re-exposed at the policy object for callers that hold a
Lattice. Identical to SecurityLabel::can_access — the policy does
NOT change the order; this is purely an ergonomic forwarder. Debug
builds assert both labels are well-formed (a mis-labeled object reaching
the monitor is a genesis bug).
Sourcepub fn join(&self, a: &SecurityLabel, b: &SecurityLabel) -> SecurityLabel
pub fn join(&self, a: &SecurityLabel, b: &SecurityLabel) -> SecurityLabel
IFC join, re-exposed at the policy object. Identical algebra to
SecurityLabel::join; the result is always well-formed if both inputs
are (union of known compartments is known).
Trait Implementations§
Source§impl<'de> Deserialize<'de> for Lattice
impl<'de> Deserialize<'de> for Lattice
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
Auto Trait Implementations§
impl Freeze for Lattice
impl RefUnwindSafe for Lattice
impl Send for Lattice
impl Sync for Lattice
impl Unpin for Lattice
impl UnsafeUnpin for Lattice
impl UnwindSafe for Lattice
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more