Skip to content
Merged
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
45 changes: 43 additions & 2 deletions verifier/src/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,15 @@ use serde_human_bytes as serde_bytes;

#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct VerificationRequest {
#[serde(with = "serde_bytes")]
#[serde(with = "serde_bytes", default)]
pub quote: Option<Vec<u8>>,
#[serde(default)]
pub event_log: Option<String>,
#[serde(default)]
pub vm_config: Option<String>,
#[serde(with = "serde_bytes")]
#[serde(with = "serde_bytes", default)]
pub attestation: Option<Vec<u8>>,
#[serde(default)]
pub debug: Option<bool>,
}

Expand Down Expand Up @@ -84,3 +87,41 @@ pub enum RtmrEventStatus {
Extra,
Missing,
}

#[cfg(test)]
mod tests {
use super::*;

// the README documents sending either `attestation` or
// (`quote` + `event_log` + `vm_config`); every field is optional, so any
// documented subset must deserialize without a "missing field" error.

#[test]
fn deserializes_quote_subset_without_attestation() {
let json = r#"{"quote":"00","event_log":"[]","vm_config":"{}"}"#;
let req: VerificationRequest = serde_json::from_str(json).unwrap();
assert_eq!(req.quote, Some(vec![0u8]));
assert_eq!(req.event_log.as_deref(), Some("[]"));
assert_eq!(req.vm_config.as_deref(), Some("{}"));
assert_eq!(req.attestation, None);
assert_eq!(req.debug, None);
}

#[test]
fn deserializes_attestation_subset_without_quote() {
let json = r#"{"attestation":"00"}"#;
let req: VerificationRequest = serde_json::from_str(json).unwrap();
assert_eq!(req.attestation, Some(vec![0u8]));
assert_eq!(req.quote, None);
assert_eq!(req.event_log, None);
assert_eq!(req.vm_config, None);
}

#[test]
fn deserializes_empty_object() {
let req: VerificationRequest = serde_json::from_str("{}").unwrap();
assert_eq!(req.quote, None);
assert_eq!(req.attestation, None);
assert_eq!(req.debug, None);
}
}
Loading