intel_dcap_api/client/
fmspc.rs

1// SPDX-License-Identifier: Apache-2.0
2// Copyright (c) 2025 Matter Labs
3
4//! FMSPCs & TCB Evaluation Data Numbers
5
6use super::ApiClient; // Import from parent module
7use crate::{
8    error::{check_status, IntelApiError},
9    responses::TcbEvaluationDataNumbersResponse,
10    types::{ApiVersion, PlatformFilter},
11    FmspcJsonResponse,
12};
13use reqwest::StatusCode;
14
15impl ApiClient {
16    /// GET /sgx/certification/{v3,v4}/fmspcs
17    /// Retrieves a list of FMSPC values for SGX and TDX platforms (API v4 only).
18    ///
19    /// # Arguments
20    ///
21    /// * `platform_filter` - An optional filter specifying SGX or TDX platforms.
22    ///
23    /// # Returns
24    ///
25    /// Optional 'platform' filter.
26    /// A `String` containing the JSON array of objects, each containing `fmspc` and `platform`.
27    ///
28    /// # Errors
29    ///
30    /// Returns an `IntelApiError` if an unsupported API version is used or if the request fails.
31    pub async fn get_fmspcs(
32        &self,
33        platform_filter: Option<PlatformFilter>,
34    ) -> Result<FmspcJsonResponse, IntelApiError> {
35        if self.api_version == ApiVersion::V3 {
36            return Err(IntelApiError::UnsupportedApiVersion(
37                "API v4 only function".to_string(),
38            ));
39        }
40        let path = self.build_api_path("sgx", "", "fmspcs")?;
41        let mut url = self.base_url.join(&path)?;
42
43        if let Some(pf) = platform_filter {
44            url.query_pairs_mut()
45                .append_pair("platform", &pf.to_string());
46        }
47
48        let request_builder = self.client.get(url);
49        let response = self.execute_with_retry(request_builder).await?;
50        let response = check_status(response, &[StatusCode::OK]).await?;
51
52        let fmspcs_json = response.text().await?;
53
54        Ok(fmspcs_json)
55    }
56
57    /// GET /sgx/certification/v4/tcbevaluationdatanumbers - V4 ONLY
58    /// Retrieves the currently supported SGX TCB Evaluation Data Numbers (API v4 only).
59    ///
60    /// # Returns
61    ///
62    /// A [`TcbEvaluationDataNumbersResponse`] containing the JSON structure of TCB Evaluation
63    /// Data Numbers and an issuer chain header.
64    ///
65    /// # Errors
66    ///
67    /// Returns an `IntelApiError` if an unsupported API version is used or if the request fails.
68    pub async fn get_sgx_tcb_evaluation_data_numbers(
69        &self,
70    ) -> Result<TcbEvaluationDataNumbersResponse, IntelApiError> {
71        // Endpoint requires V4
72        if self.api_version != ApiVersion::V4 {
73            return Err(IntelApiError::UnsupportedApiVersion(
74                "SGX TCB Evaluation Data Numbers endpoint requires API v4".to_string(),
75            ));
76        }
77
78        let path = self.build_api_path("sgx", "", "tcbevaluationdatanumbers")?;
79        let url = self.base_url.join(&path)?;
80        let request_builder = self.client.get(url);
81
82        let (tcb_evaluation_data_numbers_json, issuer_chain) = self
83            .fetch_json_with_issuer_chain(
84                request_builder,
85                "TCB-Evaluation-Data-Numbers-Issuer-Chain",
86                None,
87            )
88            .await?;
89
90        Ok(TcbEvaluationDataNumbersResponse {
91            tcb_evaluation_data_numbers_json,
92            issuer_chain,
93        })
94    }
95
96    /// GET /tdx/certification/v4/tcbevaluationdatanumbers - V4 ONLY
97    /// Retrieves the currently supported TDX TCB Evaluation Data Numbers (API v4 only).
98    ///
99    /// # Returns
100    ///
101    /// A [`TcbEvaluationDataNumbersResponse`] containing the JSON structure of TCB Evaluation
102    /// Data Numbers and an issuer chain header.
103    ///
104    /// # Errors
105    ///
106    /// Returns an `IntelApiError` if an unsupported API version is used or if the request fails.
107    pub async fn get_tdx_tcb_evaluation_data_numbers(
108        &self,
109    ) -> Result<TcbEvaluationDataNumbersResponse, IntelApiError> {
110        // Endpoint requires V4
111        if self.api_version != ApiVersion::V4 {
112            return Err(IntelApiError::UnsupportedApiVersion(
113                "TDX TCB Evaluation Data Numbers endpoint requires API v4".to_string(),
114            ));
115        }
116
117        let path = self.build_api_path("tdx", "", "tcbevaluationdatanumbers")?;
118        let url = self.base_url.join(&path)?;
119        let request_builder = self.client.get(url);
120
121        let (tcb_evaluation_data_numbers_json, issuer_chain) = self
122            .fetch_json_with_issuer_chain(
123                request_builder,
124                "TCB-Evaluation-Data-Numbers-Issuer-Chain",
125                None,
126            )
127            .await?;
128
129        Ok(TcbEvaluationDataNumbersResponse {
130            tcb_evaluation_data_numbers_json,
131            issuer_chain,
132        })
133    }
134}