use crate::attestation::report::AttestationReport;
use crate::attestation::verifier::{AttestationVerifier, VerifiedAttestation};
use crate::config::TeeProvider;
use crate::errors::TeeError;
use super::native::NativeVerifier;
pub struct TdxVerifier {
pub expected_mrtd: Option<String>,
pub allow_debug: bool,
}
impl TdxVerifier {
pub fn new() -> Self {
Self {
expected_mrtd: None,
allow_debug: false,
}
}
pub fn with_expected_mrtd(mut self, mrtd: impl Into<String>) -> Self {
self.expected_mrtd = Some(mrtd.into());
self
}
pub fn allow_debug(mut self, allow: bool) -> Self {
self.allow_debug = allow;
self
}
fn to_native(&self) -> NativeVerifier {
let mut v = NativeVerifier::tdx().with_allow_debug(self.allow_debug);
if let Some(mrtd) = &self.expected_mrtd {
v = v.with_expected_measurement(mrtd.clone());
}
v
}
}
impl Default for TdxVerifier {
fn default() -> Self {
Self::new()
}
}
impl AttestationVerifier for TdxVerifier {
fn verify(&self, report: &AttestationReport) -> Result<VerifiedAttestation, TeeError> {
self.to_native().verify(report)
}
fn supported_provider(&self) -> TeeProvider {
TeeProvider::IntelTdx
}
}