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

Method from_bytes

dstack-attest/src/attestation.rs:395–418  ·  view source on GitHub ↗

Decode versioned attestation bytes.

(bytes: &[u8])

Source from the content-addressed store, hash-verified

393impl VersionedAttestation {
394 /// Decode versioned attestation bytes.
395 pub fn from_bytes(bytes: &[u8]) -> Result<Self> {
396 if bytes.len() > MAX_ATTESTATION_BYTES {
397 bail!(
398 "attestation bytes too large: {} > {}",
399 bytes.len(),
400 MAX_ATTESTATION_BYTES
401 );
402 }
403 let Some(first) = bytes.first().copied() else {
404 bail!("Empty attestation bytes");
405 };
406 if first == 0x00 {
407 let legacy = LegacyVersionedAttestation::decode(&mut &bytes[..])
408 .context("Failed to decode legacy VersionedAttestation")?;
409 return match legacy {
410 LegacyVersionedAttestation::V0 { attestation } => Ok(Self::V0 { attestation }),
411 };
412 }
413 if is_msgpack_map_prefix(first) {
414 let attestation = AttestationV1::from_msgpack(bytes)?;
415 return Ok(Self::V1 { attestation });
416 }
417 bail!("Unknown attestation wire format");
418 }
419
420 /// Encode versioned attestation bytes.
421 pub fn to_bytes(&self) -> Result<Vec<u8>> {

Callers

nothing calls this directly

Calls 3

decodeFunction · 0.85
is_msgpack_map_prefixFunction · 0.85
lenMethod · 0.45

Tested by

no test coverage detected