Skip to content

Commit 9856b3d

Browse files
committed
added borsh serialize to public sdk types
1 parent d61cdef commit 9856b3d

File tree

5 files changed

+45
-2
lines changed

5 files changed

+45
-2
lines changed

Cargo.lock

Lines changed: 24 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,7 @@ sd-notify = "0.4.5"
9595
jemallocator = "0.5.4"
9696

9797
# Serialization/Parsing
98+
borsh = { version = "1.5.7", features = ["derive"] }
9899
bon = { version = "3.4.0", default-features = false }
99100
base64 = "0.22.1"
100101
hex = { version = "0.4.3", default-features = false }

sdk/rust/types/Cargo.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ authors = ["Encifher <[email protected]>"]
99
[dependencies]
1010
anyhow.workspace = true
1111
bon.workspace = true
12+
borsh = { workspace = true, optional = true }
1213
hex = { workspace = true, features = ["alloc"] }
1314
pkcs8 = { workspace = true, features = ["pem"] }
1415
serde.workspace = true
@@ -21,6 +22,7 @@ tokio = { workspace = true, features = ["full"] }
2122

2223
[features]
2324
default = ["std"]
25+
borsh = ["dep:borsh"]
2426
std = [
2527
"anyhow/std",
2628
"bon/std",

sdk/rust/types/src/dstack.rs

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,9 @@ use serde::{Deserialize, Serialize};
99
use serde_json::{from_str, Value};
1010
use sha2::Digest;
1111

12+
#[cfg(feature = "borsh")]
13+
use borsh::{BorshDeserialize, BorshSerialize};
14+
1215
const INIT_MR: &str = "000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000";
1316

1417
fn replay_rtmr(history: Vec<String>) -> Result<String, FromHexError> {
@@ -29,6 +32,7 @@ fn replay_rtmr(history: Vec<String>) -> Result<String, FromHexError> {
2932

3033
/// Represents an event log entry in the system
3134
#[derive(Debug, Serialize, Deserialize)]
35+
#[cfg_attr(feature = "borsh", derive(BorshSerialize, BorshDeserialize))]
3236
pub struct EventLog {
3337
/// The index of the IMR (Integrity Measurement Register)
3438
pub imr: u32,
@@ -43,7 +47,8 @@ pub struct EventLog {
4347
}
4448

4549
/// Configuration for TLS key generation
46-
#[derive(Debug, bon::Builder, Serialize)]
50+
#[derive(Debug, bon::Builder, Serialize, Deserialize)]
51+
#[cfg_attr(feature = "borsh", derive(BorshSerialize, BorshDeserialize))]
4752
pub struct TlsKeyConfig {
4853
/// The subject name for the certificate
4954
#[builder(into, default = String::new())]
@@ -64,6 +69,7 @@ pub struct TlsKeyConfig {
6469

6570
/// Response containing a key and its signature chain
6671
#[derive(Debug, Serialize, Deserialize)]
72+
#[cfg_attr(feature = "borsh", derive(BorshSerialize, BorshDeserialize))]
6773
pub struct GetKeyResponse {
6874
/// The key in hexadecimal format
6975
pub key: String,
@@ -83,6 +89,7 @@ impl GetKeyResponse {
8389

8490
/// Response containing a quote and associated event log
8591
#[derive(Debug, Serialize, Deserialize)]
92+
#[cfg_attr(feature = "borsh", derive(BorshSerialize, BorshDeserialize))]
8693
pub struct GetQuoteResponse {
8794
/// The attestation quote in hexadecimal format
8895
pub quote: String,
@@ -122,6 +129,7 @@ impl GetQuoteResponse {
122129

123130
/// Response containing instance information and attestation data
124131
#[derive(Debug, Serialize, Deserialize)]
132+
#[cfg_attr(feature = "borsh", derive(BorshSerialize, BorshDeserialize))]
125133
pub struct InfoResponse {
126134
/// The application identifier
127135
pub app_id: String,
@@ -157,6 +165,7 @@ impl InfoResponse {
157165

158166
/// Trusted Computing Base information structure
159167
#[derive(Debug, Serialize, Deserialize)]
168+
#[cfg_attr(feature = "borsh", derive(BorshSerialize, BorshDeserialize))]
160169
pub struct TcbInfo {
161170
/// The measurement root of trust
162171
pub mrtd: String,
@@ -183,6 +192,7 @@ pub struct TcbInfo {
183192

184193
/// Response containing TLS key and certificate chain
185194
#[derive(Debug, Serialize, Deserialize)]
195+
#[cfg_attr(feature = "borsh", derive(BorshSerialize, BorshDeserialize))]
186196
pub struct GetTlsKeyResponse {
187197
/// The TLS key in hexadecimal format
188198
pub key: String,

sdk/rust/types/src/tappd.rs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ use alloc::{
44
vec::Vec,
55
};
66
use anyhow::{bail, Context as _, Result};
7+
use borsh::{BorshDeserialize, BorshSerialize};
78
use hex::{encode as hex_encode, FromHexError};
89
use serde::{Deserialize, Serialize};
910
use sha2::Digest;
@@ -13,7 +14,8 @@ use crate::dstack::EventLog;
1314
const INIT_MR: &str = "000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000";
1415

1516
/// Hash algorithms supported by the TDX quote generation
16-
#[derive(Debug, Clone)]
17+
#[derive(Debug, Clone, Serialize, Deserialize)]
18+
#[cfg_attr(feature = "borsh", derive(BorshSerialize, BorshDeserialize))]
1719
pub enum QuoteHashAlgorithm {
1820
Sha256,
1921
Sha384,
@@ -62,6 +64,7 @@ fn replay_rtmr(history: Vec<String>) -> Result<String, FromHexError> {
6264

6365
/// Response from a key derivation request
6466
#[derive(Debug, Serialize, Deserialize)]
67+
#[cfg_attr(feature = "borsh", derive(BorshSerialize, BorshDeserialize))]
6568
pub struct DeriveKeyResponse {
6669
/// The derived key (PEM format for certificates, hex for raw keys)
6770
pub key: String,
@@ -132,6 +135,7 @@ impl DeriveKeyResponse {
132135

133136
/// Response from a TDX quote request
134137
#[derive(Debug, Serialize, Deserialize)]
138+
#[cfg_attr(feature = "borsh", derive(BorshSerialize, BorshDeserialize))]
135139
pub struct TdxQuoteResponse {
136140
/// The TDX quote in hexadecimal format
137141
pub quote: String,
@@ -178,6 +182,7 @@ impl TdxQuoteResponse {
178182

179183
/// TCB (Trusted Computing Base) information
180184
#[derive(Debug, Serialize, Deserialize)]
185+
#[cfg_attr(feature = "borsh", derive(BorshSerialize, BorshDeserialize))]
181186
pub struct TappdTcbInfo {
182187
/// The measurement root of trust
183188
pub mrtd: String,
@@ -197,6 +202,7 @@ pub struct TappdTcbInfo {
197202

198203
/// Response from a Tappd info request
199204
#[derive(Debug, Serialize, Deserialize)]
205+
#[cfg_attr(feature = "borsh", derive(BorshSerialize, BorshDeserialize))]
200206
pub struct TappdInfoResponse {
201207
/// The application identifier
202208
pub app_id: String,

0 commit comments

Comments
 (0)