Skip to main content

IgvmSerializer

Struct IgvmSerializer 

Source
pub struct IgvmSerializer<'a> { /* private fields */ }
Available on crate feature corim only.
Expand description

Serializer that borrows an IgvmFile and enriches the output with computed measurements and CoRIM documents.

The underlying IgvmFile is never mutated. Additional initialization headers (CoRIM documents) are accumulated in the serializer and merged into the output during serialize.

Implementations§

Source§

impl<'a> IgvmSerializer<'a>

Source

pub fn new(file: &'a IgvmFile) -> Result<Self, Error>

Create a new serializer for the given IGVM file.

During construction, the launch measurement is computed for every platform header in the file whose platform type has a measurement profile defined by this crate (currently SEV-SNP, TDX, and VBS). Platform headers with no measurement profile (e.g., IgvmPlatformType::NATIVE, IgvmPlatformType::SEV, IgvmPlatformType::SEV_ES) are silently skipped.

§Errors

Returns Error::MeasurementFailed if measurement computation fails for any of the file’s measurable platforms (e.g., SEV-SNP without a IgvmInitializationHeader::GuestPolicy header).

Source

pub fn file(&self) -> &IgvmFile

Get a reference to the underlying IGVM file.

Source

pub fn measurements(&self) -> &[IgvmPlatformMeasurement]

Get all launch measurements computed for this file.

One entry is present for every measurable platform header in the file (see new).

Source

pub fn measurement_for( &self, platform: IgvmPlatformType, ) -> Option<&IgvmPlatformMeasurement>

Get the launch measurement for a specific platform, if the file has a corresponding measurable platform header.

Source

pub fn corim_for(&self, platform: IgvmPlatformType) -> Option<&[u8]>

Get the raw CoRIM document bytes effective for the given platform.

Returns the document staged via add_corim if one exists for the platform, otherwise the document embedded in the base IGVM file (as produced at generation time). This lets a read-modify- write caller (for example, one attaching a detached signature) fetch the document a signature must be verified against without re-scanning the file’s initialization headers itself.

Returns None if the file has no platform header for platform, or if no CoRIM document is present for it in either location.

Source

pub fn add_corim( &mut self, platform: IgvmPlatformType, template: CorimTemplate, ) -> Result<&[u8], Error>

Attach a CoRIM endorsement for the given platform.

The generated CoRIM document will be included as an IgvmInitializationHeader::CorimDocument in the serialized output. On success, the raw CoRIM bytes that were attached are returned.

For CorimTemplate::LaunchMeasurement, populated measurements take their digest bytes from the launch measurement computed at construction time (see new).

§Arguments
  • platform – The target platform type. Must match a platform header in the file, and must match the platform of the LaunchMeasurement in the template.
  • template – The CoRIM template to instantiate. See CorimTemplate for the supported variants.
Source

pub fn set_corim_signature( &mut self, platform: IgvmPlatformType, signature: Vec<u8>, ) -> Result<&[u8], Error>

Set the CoRIM signature for a platform while preserving its corresponding CoRIM document.

On serialize, any in-file CoRIM document/signature pair for this platform’s compatibility mask is suppressed and replaced with exactly one CoRIM document (the existing one) and one CoRIM signature.

This keeps CoRIM document/signature ordering valid and avoids callers needing to reconstruct a full IgvmFile just to patch signatures.

Source

pub fn add_directive( &mut self, directive: IgvmDirectiveHeader, ) -> &IgvmDirectiveHeader

Attach an extra directive header that will be appended when serializing.

This allows callers to stage workflows that need the already-cached launch measurement from new, then add a directive derived from that measurement (for example, IgvmDirectiveHeader::SnpIdBlock) before the final serialize.

Added directives are not included in the measurement cache computed during new.

Source

pub fn serialize(&self, output: &mut Vec<u8>) -> Result<(), Error>

Serialize the IGVM file to binary format, including any CoRIM documents that were added via add_corim.

This produces the same binary format as IgvmFile::serialize, but with additional initialization headers and directives appended.

Trait Implementations§

Source§

impl<'a> Debug for IgvmSerializer<'a>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl<'a> Freeze for IgvmSerializer<'a>

§

impl<'a> RefUnwindSafe for IgvmSerializer<'a>

§

impl<'a> Send for IgvmSerializer<'a>

§

impl<'a> Sync for IgvmSerializer<'a>

§

impl<'a> Unpin for IgvmSerializer<'a>

§

impl<'a> UnsafeUnpin for IgvmSerializer<'a>

§

impl<'a> UnwindSafe for IgvmSerializer<'a>

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self> ⓘ

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self> ⓘ

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> ⓘ
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self> ⓘ

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more