def deserialize_td_quotev5()

in cvm-attestation/deserialize_tdx_v5.py [0:0]


def deserialize_td_quotev5(tq_quote):
    """
    Parses the given TD quote object and returns the structured data.
    """
    TDQuoteHeaderv5 = Struct(
        "version" / Int16ul,
        "attestation_key_type" / Int16ul,
        "tee_type" / Int32ul,
        "reserved_1" / Bytes(2),
        "reserved_2" / Bytes(2),
        "qe_vendor_id" / Bytes(16),
        "user_data" / Bytes(20)
    )
    

    TDQuoteBodyv5 = Struct(
        "tee_tcb_svn" / Bytes(16),
        "mrseam" / Bytes(48),
        "mrsignerseam" / Bytes(48),
        "seam_attributes" / Bytes(8),
        "td_attributes" / Bytes(8),
        "xfam" / Int64ul,
        "mr_td" / Bytes(48),
        "mr_config_id" / Bytes(48),
        "mr_owner" / Bytes(48),
        "mr_owner_config" / Bytes(48),
        "rtmr" / Array(4, Bytes(48)),
        "report_data" / Bytes(64),
        "tee_tcb_svn_2" / Bytes(16),
        "mr_service_td" / Bytes(48)
    )

    TDQuoteBodyDescriptorv5 = Struct(
        "quote_body_type" / Bytes(2),
        "size" / Int32ul,
        "body" / TDQuoteBodyv5
    )
    
    TDQuotev5 = Struct(
        "header" / TDQuoteHeaderv5,
        "body" / TDQuoteBodyDescriptorv5,
        "quote_signature_data_len" / Int32ul,
        "quote_signature_data" / Bytes(this.quote_signature_data_len)
    )
    
    try:
        return TDQuotev5.parse(tq_quote)
    except Exception as e:
        print(f"Error parsing TD Quote: {e}", file=sys.stderr)
        return None