Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 14 additions & 4 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

17 changes: 11 additions & 6 deletions attest-mock/src/corim.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use miette::{IntoDiagnostic, Result, miette};
use rats_corim::CorimBuilder;

#[derive(knuffel::Decode, Debug)]
struct Measurement {
pub struct Measurement {
#[knuffel(child, unwrap(argument))]
pub mkey: String,

Expand All @@ -18,7 +18,7 @@ struct Measurement {
}

#[derive(knuffel::Decode, Debug)]
struct Document {
pub struct Document {
#[knuffel(child, unwrap(argument))]
pub vendor: String,

Expand All @@ -32,12 +32,17 @@ struct Document {
pub measurements: Vec<Measurement>,
}

/// Parse the KDL in from string `kdl`, convert it to an `rats_corim::Corim`
/// instance. NOTE: The `name` param should be the name of the file that the
/// Parse the KDL in from string `kdl`
///
/// NOTE: The `name` param should be the name of the file that the
/// `kdl` string was read from. This is used in error reporting.
pub fn mock(name: &str, kdl: &str) -> Result<Vec<u8>> {
let doc: Document = knuffel::parse(name, kdl)?;
pub fn parse(name: &str, kdl: &str) -> Result<Document> {
let doc = knuffel::parse(name, kdl)?;
Ok(doc)
}

/// Convert `doc` to an `rats_corim::Corim` instance
pub fn mock(doc: Document) -> Result<Vec<u8>> {
let mut corim_builder = CorimBuilder::new();
corim_builder.vendor(doc.vendor);
corim_builder.tag_id(doc.tag_id);
Expand Down
6 changes: 6 additions & 0 deletions attest-mock/src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
// This Source Code Form is subject to the terms of the Mozilla Public
// License, v. 2.0. If a copy of the MPL was not distributed with this
// file, You can obtain one at https://mozilla.org/MPL/2.0/.

pub mod corim;
pub mod log;
17 changes: 11 additions & 6 deletions attest-mock/src/log.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,26 +7,31 @@ use hubpack::SerializedSize;
use miette::{IntoDiagnostic, Result, miette};

#[derive(knuffel::Decode, Debug)]
struct Document {
pub struct Document {
#[knuffel(children)]
pub measurements: Vec<Measurement>,
}

#[derive(knuffel::Decode, Debug)]
struct Measurement {
pub struct Measurement {
#[knuffel(child, unwrap(argument))]
pub algorithm: String,

#[knuffel(child, unwrap(argument))]
pub digest: String,
}

/// Parse the KDL in from string `kdl`, convert it to an `attest_data::Log`
/// instance. NOTE: The `name` param should be the name of the file that the
/// Parse the KDL in from string `kdl`
///
/// NOTE: The `name` param should be the name of the file that the
/// `kdl` string was read from. This is used in error reporting.
pub fn mock(name: &str, kdl: &str) -> Result<Vec<u8>> {
let doc: Document = knuffel::parse(name, kdl)?;
pub fn parse(name: &str, kdl: &str) -> Result<Document> {
let doc = knuffel::parse(name, kdl)?;
Ok(doc)
}

/// Convert `doc` to an `attest_data::Log` instance
pub fn mock(doc: Document) -> Result<Vec<u8>> {
let mut log = Log::default();
for measurement in doc.measurements {
let measurement = if measurement.algorithm == "sha3-256" {
Expand Down
15 changes: 11 additions & 4 deletions attest-mock/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,14 +37,21 @@ mod log;
fn main() -> Result<()> {
let args = Args::parse();

let name = args.kdl.to_string_lossy();
let kdl = fs::read_to_string(&args.kdl)
let cow_name = args.kdl.to_string_lossy();
let name = cow_name.as_ref();
let kdl = fs::read_to_string(name)
.into_diagnostic()
.map_err(|e| miette!("failed to read file {name} to string: {e}"))?;

let out = match args.cmd {
Command::Corim => corim::mock(&name, &kdl)?,
Command::Log => log::mock(&name, &kdl)?,
Command::Corim => {
let doc = corim::parse(name, &kdl)?;
corim::mock(doc)?
}
Command::Log => {
let doc = log::parse(name, &kdl)?;
log::mock(doc)?
}
};

io::stdout()
Expand Down
Loading