Skip to content

Commit

Permalink
Fix: Use strum string to parse AA token type string
Browse files Browse the repository at this point in the history
Signed-off-by: Jiale Zhang <zhangjiale@linux.alibaba.com>
  • Loading branch information
jialez0 authored and fitzthum committed Jan 29, 2024
1 parent 14c9661 commit fc89b71
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 5 deletions.
3 changes: 2 additions & 1 deletion attestation-agent/lib/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ use attester::{detect_tee_type, BoxedAttester};
use kbc::{AnnotationPacket, KbcCheckInfo, KbcInstance, KbcModuleList};
use resource_uri::ResourceUri;
use std::collections::HashMap;
use std::str::FromStr;

pub mod config;
mod token;
Expand Down Expand Up @@ -198,7 +199,7 @@ impl AttestationAPIs for AttestationAgent {
}
};

let _token = match serde_json::from_str::<TokenType>(_token_type)
let _token = match TokenType::from_str(_token_type)
.map_err(|e| anyhow!("Unsupported token type: {e}"))?
{
#[cfg(feature = "kbs")]
Expand Down
8 changes: 4 additions & 4 deletions attestation-agent/lib/src/token/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,22 +5,22 @@

use anyhow::Result;
use async_trait::async_trait;
use serde::{Deserialize, Serialize};
use strum::EnumString;

#[cfg(feature = "kbs")]
pub mod kbs;

#[cfg(feature = "coco_as")]
pub mod coco_as;

#[derive(Serialize, Deserialize, Clone, Copy)]
#[derive(EnumString, Clone, Copy)]
pub enum TokenType {
#[cfg(feature = "kbs")]
#[serde(rename = "kbs")]
#[strum(serialize = "kbs")]
Kbs,

#[cfg(feature = "coco_as")]
#[serde(rename = "coco_as")]
#[strum(serialize = "coco_as")]
CoCoAS,
}

Expand Down

0 comments on commit fc89b71

Please sign in to comment.