Skip to content

Commit

Permalink
Fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
pbeza committed Sep 5, 2024
1 parent d7e938f commit 955590e
Showing 1 changed file with 5 additions and 29 deletions.
34 changes: 5 additions & 29 deletions core/lib/basic_types/src/tee_types.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
use std::{fmt, str::FromStr};

use serde::{Deserialize, Serialize};

#[derive(Debug, Clone, Copy, PartialEq, Serialize, Deserialize)]
Expand All @@ -9,31 +7,14 @@ pub enum TeeType {
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() {
fn test_serialize_teetype() {
let json_str = "\"sgx\"";
let tee_type: TeeType = serde_json::from_str(json_str).unwrap();
assert_eq!(tee_type, TeeType::Sgx);
Expand All @@ -45,14 +26,9 @@ mod tests {
}

#[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");
fn test_deserialize_teetype() {
let tee_type = TeeType::Sgx;
let json_str = serde_json::to_string(&tee_type).unwrap();
assert_eq!(json_str, "\"sgx\"");
}
}

0 comments on commit 955590e

Please sign in to comment.