Skip to main content

macroonz_compiler/expansion/
encode.rs

1//! The canonical bytes one binding disagreement is named by.
2
3use super::BindError;
4use crate::identity::encode_bytes;
5
6impl BindError {
7    /// This disagreement's complete canonical material: which pair disagreed, then the identity that was BOUND and the identity the value handed in turned out to name, each at full width.
8    ///
9    /// The pair's position leads, so two pairs holding identities that happened to coincide still derive two related identities.
10    /// The bound identity rides ahead of the carried one, so a reader of the two knows which is which without the diagnostic saying so twice.
11    #[must_use]
12    pub fn canonical_bytes(&self) -> Vec<u8> {
13        let (bound, carried): (&[u8; 32], &[u8; 32]) = match self {
14            Self::ClosureProvedAgainstAnotherPlan { planned, proved } => {
15                (planned.as_bytes(), proved.as_bytes())
16            }
17            Self::ExplanationAnsweredOverAnotherPlan { planned, answered } => {
18                (planned.as_bytes(), answered.as_bytes())
19            }
20            Self::ExplanationAnsweredOverAnotherClosure { proved, answered } => {
21                (proved.as_bytes(), answered.as_bytes())
22            }
23        };
24        let mut material = vec![self.slot()];
25        encode_bytes(bound, &mut material);
26        encode_bytes(carried, &mut material);
27        material
28    }
29}