Decode versioned attestation bytes.
(bytes: &[u8])
| 393 | impl 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>> { |
nothing calls this directly
no test coverage detected