Skip to content

Commit

Permalink
Types: extend extra_params to Value
Browse files Browse the repository at this point in the history
serde_json::Value is a flexible structure that could be a string and
even a nested map. This helps us to give more structured context of the
message.

confidential-containers/trustee#242 is an
example issue

Signed-off-by: Xynnn007 <[email protected]>
  • Loading branch information
Xynnn007 committed Jun 11, 2024
1 parent 9a4ff50 commit 86ca1a6
Show file tree
Hide file tree
Showing 4 changed files with 13,815 additions and 12 deletions.
7 changes: 4 additions & 3 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ extern crate alloc;

#[cfg(all(feature = "alloc", not(feature = "std")))]
use alloc::string::String;
use serde_json::Value;
#[cfg(feature = "std")]
use std::string::String;

Expand Down Expand Up @@ -45,14 +46,14 @@ pub struct Request {
pub version: String,
pub tee: Tee,
#[serde(rename = "extra-params")]
pub extra_params: String,
pub extra_params: Value,
}

#[derive(Clone, Serialize, Deserialize, Debug)]
pub struct Challenge {
pub nonce: String,
#[serde(rename = "extra-params")]
pub extra_params: String,
pub extra_params: Value,
}

#[derive(Clone, Serialize, Deserialize, Debug)]
Expand All @@ -70,7 +71,7 @@ pub struct Attestation {
#[serde(rename = "tee-pubkey")]
pub tee_pubkey: TeePubKey,
#[serde(rename = "tee-evidence")]
pub tee_evidence: String,
pub tee_evidence: Value,
}

#[derive(Clone, Serialize, Deserialize, Debug)]
Expand Down
10 changes: 5 additions & 5 deletions src/tee/sev.rs
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ mod tests {
workload_id: "fakeid".to_string(),
};

let sev_request_json = serde_json::to_string(&sev_request).unwrap();
let sev_request_json = serde_json::to_value(&sev_request).unwrap();

println!("SevRequest:\n{}", sev_request_json);

Expand All @@ -190,7 +190,7 @@ mod tests {
assert_eq!(request.version, "0.0.0");
assert_eq!(request.tee, Tee::Sev);

let sev_request: SevRequest = serde_json::from_str(&request.extra_params).unwrap();
let sev_request: SevRequest = serde_json::from_value(request.extra_params).unwrap();

assert_eq!(sev_request.build.version.major, 1);
assert_eq!(sev_request.build.version.minor, 49);
Expand All @@ -206,7 +206,7 @@ mod tests {
let data = fs::read_to_string(d).unwrap();

let request: Request = serde_json::from_str(&data).unwrap();
let sev_request: SevRequest = serde_json::from_str(&request.extra_params).unwrap();
let sev_request: SevRequest = serde_json::from_value(request.extra_params).unwrap();

let policy = Policy::default();
let session = Session::try_from(policy).unwrap();
Expand All @@ -217,7 +217,7 @@ mod tests {
start,
};

let sev_challenge_json = serde_json::to_string(&sev_challenge).unwrap();
let sev_challenge_json = serde_json::to_value(&sev_challenge).unwrap();

println!("SevChallenge:\n{}", sev_challenge_json);

Expand All @@ -242,7 +242,7 @@ mod tests {

assert_eq!(challenge.nonce, "42");

let sev_challenge: SevChallenge = serde_json::from_str(&challenge.extra_params).unwrap();
let sev_challenge: SevChallenge = serde_json::from_value(challenge.extra_params).unwrap();

assert_eq!(sev_challenge.id, "fakeid");
assert_eq!(sev_challenge.start.policy.minfw.major, 0);
Expand Down
Loading

0 comments on commit 86ca1a6

Please sign in to comment.