Skip to content

Commit f1ccb0e

Browse files
authored
Add functions to get measurements out of the log (#228)
1 parent a207669 commit f1ccb0e

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

attest-data/src/lib.rs

+15
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,14 @@ impl<const N: usize> MeasurementLog<N> {
156156
self.index as usize == N
157157
}
158158

159+
pub fn is_empty(&self) -> bool {
160+
self.index == 0
161+
}
162+
163+
pub fn len(&self) -> u32 {
164+
self.index
165+
}
166+
159167
pub fn push(&mut self, measurement: Measurement) -> bool {
160168
if !self.is_full() {
161169
self.measurements[self.index as usize] = measurement;
@@ -167,6 +175,13 @@ impl<const N: usize> MeasurementLog<N> {
167175
}
168176
}
169177

178+
impl<const N: usize> core::ops::Index<u32> for MeasurementLog<N> {
179+
type Output = Measurement;
180+
fn index(&self, i: u32) -> &Self::Output {
181+
&self.measurements[i as usize]
182+
}
183+
}
184+
170185
impl<const N: usize> Default for MeasurementLog<N> {
171186
fn default() -> Self {
172187
Self {

0 commit comments

Comments
 (0)