Skip to content

Commit

Permalink
Add functions to get measurements out of the log (#228)
Browse files Browse the repository at this point in the history
  • Loading branch information
mkeeter authored Feb 28, 2025
1 parent a207669 commit f1ccb0e
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions attest-data/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,14 @@ impl<const N: usize> MeasurementLog<N> {
self.index as usize == N
}

pub fn is_empty(&self) -> bool {
self.index == 0
}

pub fn len(&self) -> u32 {
self.index
}

pub fn push(&mut self, measurement: Measurement) -> bool {
if !self.is_full() {
self.measurements[self.index as usize] = measurement;
Expand All @@ -167,6 +175,13 @@ impl<const N: usize> MeasurementLog<N> {
}
}

impl<const N: usize> core::ops::Index<u32> for MeasurementLog<N> {
type Output = Measurement;
fn index(&self, i: u32) -> &Self::Output {
&self.measurements[i as usize]
}
}

impl<const N: usize> Default for MeasurementLog<N> {
fn default() -> Self {
Self {
Expand Down

0 comments on commit f1ccb0e

Please sign in to comment.