-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathtool.rs
44 lines (35 loc) · 1.03 KB
/
tool.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
use fallible_iterator::FallibleIterator;
use serde::Serialize;
use std::{env, fs::File};
use thiserror::Error;
use ima_measurements::{Event, Parser, PcrValues};
#[derive(Debug, Error)]
enum ToolError {
#[error("IO Error: {0}")]
Io(#[from] std::io::Error),
#[error("Error parsing measurement log: {0}")]
EventLog(#[from] ima_measurements::Error),
#[error("YAML Error: {0}")]
Yaml(#[from] serde_yaml::Error),
}
#[derive(Debug, Serialize)]
struct Results {
events: Vec<Event>,
pcr_values: PcrValues,
}
fn main() -> Result<(), ToolError> {
let mut args = env::args();
// Ignore our binary name
args.next();
for filename in args {
let file = File::open(&filename)?;
let mut parser = Parser::new(file);
let mut events: Vec<Event> = Vec::new();
while let Some(event) = parser.next()? {
events.push(event);
}
let pcr_values = parser.pcr_values();
serde_yaml::to_writer(std::io::stdout(), &Results { events, pcr_values })?;
}
Ok(())
}