/*
 * FpiSdcpClaim - SDCP claim structure and lifecycle functions
 * Copyright (C) 2020 Benjamin Berg <bberg@redhat.com>
 * Copyright (C) 2025 Joshua Grisham <josh@joshuagrisham.com>
 * Copyright (C) 2026 Marco Trevisan (Treviño) <mail@3v1n0.net>
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
 */

#pragma once

#include <glib-object.h>
#include "tod/tod-macros.h"

/**
 * FpiSdcpClaim:
 * @master_secret_label: HMAC label for master secret derivation, or %NULL to
 *   use %FPI_SDCP_DEFAULT_LABEL_MASTER_SECRET
 * @application_keys_label: HMAC label for application keys derivation, or %NULL
 *   to use %FPI_SDCP_DEFAULT_LABEL_APPLICATION_KEYS
 * @connect_label: HMAC label for connect operations, or %NULL to use
 *   %FPI_SDCP_DEFAULT_LABEL_CONNECT
 * @reconnect_label: HMAC label for reconnect operations, or %NULL to use
 *   %FPI_SDCP_DEFAULT_LABEL_RECONNECT
 * @enroll_label: HMAC label for enroll operations, or %NULL to use
 *   %FPI_SDCP_DEFAULT_LABEL_ENROLL
 * @identify_label: HMAC label for identify operations, or %NULL to use
 *   %FPI_SDCP_DEFAULT_LABEL_IDENTIFY
 * @sample_label: HMAC label for sample operations, or %NULL to use
 *   %FPI_SDCP_DEFAULT_LABEL_SAMPLE
 * @model_certificate: Microsoft-issued per-model certificate encoded in x509
 *   ASN.1 DER format (`cert_m`)
 * @device_public_key: The per-device ECDSA public key (`pk_d`)
 * @firmware_public_key: The ephemeral public key generated by the device
 *   firmware (`pk_f`)
 * @firmware_hash: Hash of the firmware and firmware public key (`h_f`)
 * @model_signature: Device public key signed by the model key (`s_m`)
 * @device_signature: Firmware hash and public key signed by the device private
 *   key (`s_d`)
 *
 * Structure to hold the claim as produced by the device during a secure
 * connect. See the SDCP specification for more details.
 *
 * Note all of these may simply be memory views into a larger #GBytes created
 * using g_bytes_new_from_bytes().
 */
typedef struct _FpiSdcpClaim FpiSdcpClaim;

struct _FpiSdcpClaim
{
  /*< public >*/
  const char *master_secret_label;
  const char *application_keys_label;
  const char *connect_label;
  const char *reconnect_label;
  const char *enroll_label;
  const char *identify_label;
  const char *sample_label;

  GBytes     *model_certificate;   /* cert_m */
  GBytes     *device_public_key;   /* pk_d   */
  GBytes     *firmware_public_key; /* pk_f   */
  GBytes     *firmware_hash;       /* h_f    */
  GBytes     *model_signature;     /* s_m    */
  GBytes     *device_signature;    /* s_d    */

  /*< private >*/
  /* padding for future expansion */
  TOD_PADDING_ALIGNED (16, 0);
};

GType          fpi_sdcp_claim_get_type (void) G_GNUC_CONST;

FpiSdcpClaim  *fpi_sdcp_claim_new (void);
FpiSdcpClaim  *fpi_sdcp_claim_copy (FpiSdcpClaim *other);
void           fpi_sdcp_claim_free (FpiSdcpClaim *claim);

GBytes        *fpi_sdcp_claim_hash (FpiSdcpClaim *claim,
                                    GError      **error);

G_DEFINE_AUTOPTR_CLEANUP_FUNC (FpiSdcpClaim, fpi_sdcp_claim_free)
