MCPcopy Create free account
hub / github.com/Dstack-TEE/dstack / decompress_ext_value

Function decompress_ext_value

ra-tls/src/cert.rs:503–528  ·  view source on GitHub ↗

Decompress a certificate extension value

(data: &[u8])

Source from the content-addressed store, hash-verified

501
502/// Decompress a certificate extension value
503pub fn decompress_ext_value(data: &[u8]) -> Result<Vec<u8>> {
504 use flate2::read::GzDecoder;
505 use std::io::Read;
506
507 if data.starts_with(EVENTLOG_GZIP_MAGIC) {
508 // Compressed format
509 let compressed = &data[EVENTLOG_GZIP_MAGIC.len()..];
510 let decoder = GzDecoder::new(compressed);
511 // Limit the total amount of decompressed data to avoid gzip bombs.
512 let mut limited = decoder.take(MAX_EVENTLOG_EXT_SIZE + 1);
513 let mut decompressed = Vec::new();
514 limited
515 .read_to_end(&mut decompressed)
516 .context("failed to decompress event log")?;
517 if decompressed.len() as u64 > MAX_EVENTLOG_EXT_SIZE {
518 bail!(
519 "event log extension too large (>{} bytes)",
520 MAX_EVENTLOG_EXT_SIZE
521 );
522 }
523 Ok(decompressed)
524 } else {
525 // Uncompressed format (backwards compatibility)
526 Ok(data.to_vec())
527 }
528}
529
530/// Generate a certificate with RA-TLS quote and event log.
531#[cfg(feature = "quote")]

Callers 2

Calls 2

to_vecMethod · 0.80
lenMethod · 0.45

Tested by 2