@@ -16,99 +16,55 @@ async fn main() -> anyhow::Result<()> {
1616 // Example usage (these will fail without a running dstack service):
1717
1818 // 1. Get system info
19- match client. info ( ) . await {
20- Ok ( info) => {
21- println ! ( "System info retrieved successfully!" ) ;
22- println ! ( " App ID: {}" , info. app_id) ;
23- println ! ( " Instance ID: {}" , info. instance_id) ;
24- println ! ( " App Name: {}" , info. app_name) ;
25- println ! ( " Device ID: {}" , info. device_id) ;
26- println ! ( " Compose Hash: {}" , info. compose_hash) ;
27- println ! ( " TCB Info - MRTD: {}" , info. tcb_info. mrtd) ;
28- println ! ( " TCB Info - RTMR0: {}" , info. tcb_info. rtmr0) ;
29- }
30- Err ( e) => {
31- println ! ( "Failed to get system info: {}" , e) ;
32- }
33- }
19+ let info = client. info ( ) . await ?;
20+ println ! ( "System info retrieved successfully!" ) ;
21+ println ! ( " App ID: {}" , info. app_id) ;
22+ println ! ( " Instance ID: {}" , info. instance_id) ;
23+ println ! ( " App Name: {}" , info. app_name) ;
24+ println ! ( " Device ID: {}" , info. device_id) ;
25+ println ! ( " Compose Hash: {}" , info. compose_hash) ;
26+ println ! ( " TCB Info - MRTD: {}" , info. tcb_info. mrtd) ;
27+ println ! ( " TCB Info - RTMR0: {}" , info. tcb_info. rtmr0) ;
3428
3529 // 2. Derive a key
36- match client
30+ let response = client
3731 . get_key ( Some ( "my-app" . to_string ( ) ) , Some ( "encryption" . to_string ( ) ) )
38- . await
39- {
40- Ok ( response) => {
41- println ! ( "Key derived successfully!" ) ;
42- println ! ( " Key length: {}" , response. key. len( ) ) ;
43- println ! (
44- " Signature chain length: {}" ,
45- response. signature_chain. len( )
46- ) ;
47-
48- // Decode the key
49- match response. decode_key ( ) {
50- Ok ( key_bytes) => {
51- println ! ( " Decoded key bytes length: {}" , key_bytes. len( ) ) ;
52- }
53- Err ( e) => {
54- println ! ( " Key decode error: {}" , e) ;
55- }
56- }
57- }
58- Err ( e) => {
59- println ! ( "Failed to derive key: {}" , e) ;
60- }
61- }
32+ . await ?;
33+ println ! ( "Key derived successfully!" ) ;
34+ println ! ( " Key length: {}" , response. key. len( ) ) ;
35+ println ! (
36+ " Signature chain length: {}" ,
37+ response. signature_chain. len( )
38+ ) ;
39+
40+ // Decode the key
41+ let key_bytes = response. decode_key ( ) ?;
42+ println ! ( " Decoded key bytes length: {}" , key_bytes. len( ) ) ;
6243
6344 // 3. Generate TDX quote
6445 let report_data = b"Hello, dstack world!" . to_vec ( ) ;
65- match client. get_quote ( report_data) . await {
66- Ok ( response) => {
67- println ! ( "TDX quote generated successfully!" ) ;
68- println ! ( " Quote length: {}" , response. quote. len( ) ) ;
69- println ! ( " Event log length: {}" , response. event_log. len( ) ) ;
70-
71- // Decode the quote
72- match response. decode_quote ( ) {
73- Ok ( quote_bytes) => {
74- println ! ( " Decoded quote bytes length: {}" , quote_bytes. len( ) ) ;
75- }
76- Err ( e) => {
77- println ! ( " Quote decode error: {}" , e) ;
78- }
79- }
80-
81- // Replay RTMRs from event log
82- match response. replay_rtmrs ( ) {
83- Ok ( rtmrs) => {
84- println ! ( " Replayed RTMRs: {} entries" , rtmrs. len( ) ) ;
85- for ( idx, rtmr) in rtmrs. iter ( ) {
86- println ! ( " RTMR{}: {}" , idx, rtmr) ;
87- }
88- }
89- Err ( e) => {
90- println ! ( " RTMR replay error: {}" , e) ;
91- }
92- }
93- }
94- Err ( e) => {
95- println ! ( "Failed to get TDX quote: {}" , e) ;
96- }
46+ let response = client. get_quote ( report_data) . await ?;
47+ println ! ( "TDX quote generated successfully!" ) ;
48+ println ! ( " Quote length: {}" , response. quote. len( ) ) ;
49+ println ! ( " Event log length: {}" , response. event_log. len( ) ) ;
50+
51+ // Decode the quote
52+ let quote_bytes = response. decode_quote ( ) ?;
53+ println ! ( " Decoded quote bytes length: {}" , quote_bytes. len( ) ) ;
54+
55+ // Replay RTMRs from event log
56+ let rtmrs = response. replay_rtmrs ( ) ?;
57+ println ! ( " Replayed RTMRs: {} entries" , rtmrs. len( ) ) ;
58+ for ( idx, rtmr) in rtmrs. iter ( ) {
59+ println ! ( " RTMR{}: {}" , idx, rtmr) ;
9760 }
9861
9962 // 4. Emit an event
10063 let event_payload = b"Application started successfully" . to_vec ( ) ;
101- match client
64+ client
10265 . emit_event ( "AppStart" . to_string ( ) , event_payload)
103- . await
104- {
105- Ok ( ( ) ) => {
106- println ! ( "Event emitted successfully!" ) ;
107- }
108- Err ( e) => {
109- println ! ( "Failed to emit event: {}" , e) ;
110- }
111- }
66+ . await ?;
67+ println ! ( "Event emitted successfully!" ) ;
11268
11369 // 5. Get TLS key for server authentication
11470 let tls_config = TlsKeyConfig :: builder ( )
@@ -122,57 +78,35 @@ async fn main() -> anyhow::Result<()> {
12278 . usage_ra_tls ( true )
12379 . build ( ) ;
12480
125- match client. get_tls_key ( tls_config) . await {
126- Ok ( response) => {
127- println ! ( "TLS key generated successfully!" ) ;
128- println ! ( " Key length: {}" , response. key. len( ) ) ;
129- println ! (
130- " Certificate chain length: {}" ,
131- response. certificate_chain. len( )
132- ) ;
133- }
134- Err ( e) => {
135- println ! ( "Failed to get TLS key: {}" , e) ;
136- }
137- }
81+ let response = client. get_tls_key ( tls_config) . await ?;
82+ println ! ( "TLS key generated successfully!" ) ;
83+ println ! ( " Key length: {}" , response. key. len( ) ) ;
84+ println ! (
85+ " Certificate chain length: {}" ,
86+ response. certificate_chain. len( )
87+ ) ;
13888
13989 // 6. Get a simple key without purpose
140- match client. get_key ( Some ( "simple-key" . to_string ( ) ) , None ) . await {
141- Ok ( response) => {
142- println ! ( "Simple key derived successfully!" ) ;
143- println ! ( " Key: {}" , response. key) ;
144- }
145- Err ( e) => {
146- println ! ( "Failed to derive simple key: {}" , e) ;
147- }
148- }
90+ let response = client. get_key ( Some ( "simple-key" . to_string ( ) ) , None ) . await ?;
91+ println ! ( "Simple key derived successfully!" ) ;
92+ println ! ( " Key: {}" , response. key) ;
14993
15094 // 7. Generate quote with minimal report data
15195 let minimal_data = vec ! [ 0x01 , 0x02 , 0x03 , 0x04 ] ;
152- match client. get_quote ( minimal_data) . await {
153- Ok ( response) => {
154- println ! ( "Minimal quote generated successfully!" ) ;
155-
156- // Parse and display event log
157- match response. decode_event_log ( ) {
158- Ok ( events) => {
159- println ! ( " Event log contains {} events" , events. len( ) ) ;
160- for ( i, event) in events. iter ( ) . enumerate ( ) . take ( 3 ) {
161- // Show first 3 events
162- println ! (
163- " Event {}: IMR={}, Type={}, Event='{}'" ,
164- i, event. imr, event. event_type, event. event
165- ) ;
166- }
167- }
168- Err ( e) => {
169- println ! ( " Failed to parse event log: {}" , e) ;
170- }
171- }
172- }
173- Err ( e) => {
174- println ! ( "Failed to get minimal quote: {}" , e) ;
175- }
96+ let response = client. get_quote ( minimal_data) . await ?;
97+ println ! ( "Minimal quote generated successfully!" ) ;
98+ println ! ( " Quote length: {}" , response. quote. len( ) ) ;
99+ println ! ( " Event log length: {}" , response. event_log. len( ) ) ;
100+
101+ // Parse and display event log
102+ let events = response. decode_event_log ( ) ?;
103+ println ! ( " Event log contains {} events" , events. len( ) ) ;
104+ for ( i, event) in events. iter ( ) . enumerate ( ) . take ( 3 ) {
105+ // Show first 3 events
106+ println ! (
107+ " Event {}: IMR={}, Type={}, Event='{}'" ,
108+ i, event. imr, event. event_type, event. event
109+ ) ;
176110 }
177111
178112 Ok ( ( ) )
0 commit comments