Skip to content
Merged
Show file tree
Hide file tree
Changes from 8 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
55 changes: 52 additions & 3 deletions core/lib/basic_types/src/tee_types.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,58 @@
use std::{fmt, str::FromStr};

use serde::{Deserialize, Serialize};
use strum::{Display, EnumString};

#[derive(Debug, Clone, Copy, PartialEq, EnumString, Display, Serialize, Deserialize)]
#[derive(Debug, Clone, Copy, PartialEq, Serialize, Deserialize)]
#[serde(rename_all = "lowercase")]
#[non_exhaustive]
pub enum TeeType {
#[strum(serialize = "sgx")]
Sgx,
}

impl fmt::Display for TeeType {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
TeeType::Sgx => write!(f, "sgx"),
}
}
}

impl FromStr for TeeType {
type Err = String;

fn from_str(s: &str) -> Result<Self, Self::Err> {
serde_json::from_str(&format!("\"{}\"", s.to_lowercase()))
.map_err(|_| format!("Invalid value for TeeType: {}", s))
}
}

#[cfg(test)]
mod tests {
use serde_json;

use super::*;

#[test]
fn test_deserialize_teetype() {
let json_str = "\"sgx\"";
let tee_type: TeeType = serde_json::from_str(json_str).unwrap();
assert_eq!(tee_type, TeeType::Sgx);

for json_str in &["\"Sgx\"", "\"SGX\""] {
let result: Result<TeeType, _> = serde_json::from_str(json_str);
assert!(result.is_err());
}
}

#[test]
fn test_enumstring_teetype() {
assert_eq!(TeeType::from_str("sgx").unwrap(), TeeType::Sgx);
assert_eq!(TeeType::from_str("Sgx").unwrap(), TeeType::Sgx);
assert_eq!(TeeType::from_str("SGX").unwrap(), TeeType::Sgx);
}

#[test]
fn test_display_teetype() {
assert_eq!(TeeType::Sgx.to_string(), "sgx");
}
}
2 changes: 1 addition & 1 deletion core/lib/prover_interface/tests/job_serialization.rs
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ fn test_tee_proof_request_serialization() {
"signature": [ 0, 1, 2, 3, 4 ],
"pubkey": [ 5, 6, 7, 8, 9 ],
"proof": [ 10, 11, 12, 13, 14 ],
"tee_type": "Sgx"
"tee_type": "sgx"
}"#;
let tee_proof_result = serde_json::from_str::<SubmitTeeProofRequest>(tee_proof_str).unwrap();
let tee_proof_expected = SubmitTeeProofRequest(Box::new(L1BatchTeeProofForL1 {
Expand Down
4 changes: 2 additions & 2 deletions core/node/proof_data_handler/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ async fn request_tee_proof_inputs() {
},
L1BatchCommitmentMode::Rollup,
);
let req_body = Body::from(serde_json::to_vec(&json!({ "tee_type": "Sgx" })).unwrap());
let req_body = Body::from(serde_json::to_vec(&json!({ "tee_type": "sgx" })).unwrap());
let response = app
.oneshot(
Request::builder()
Expand Down Expand Up @@ -134,7 +134,7 @@ async fn submit_tee_proof() {
"signature": [ 0, 1, 2, 3, 4 ],
"pubkey": [ 5, 6, 7, 8, 9 ],
"proof": [ 10, 11, 12, 13, 14 ],
"tee_type": "Sgx"
"tee_type": "sgx"
}"#;
let tee_proof_request =
serde_json::from_str::<SubmitTeeProofRequest>(tee_proof_request_str).unwrap();
Expand Down
Loading