<commit_before>/*
 * Copyright (C) 2019 <NAME> <<EMAIL>>
 *
 * SPDX-License-Identifier: LGPL-2.1+
 */

#include "config.h"

#include <tss2/tss2_esys.h>

#include "fu-common.h"

#include "fu-tpm-eventlog-device.h"
#include "fu-tpm-eventlog-parser.h"

struct _FuTpmEventlogDevice {
	FuDevice		 parent_instance;
	GPtrArray		*items;
};

G_DEFINE_TYPE (FuTpmEventlogDevice, fu_tpm_eventlog_device, FU_TYPE_DEVICE)

GPtrArray *
fu_tpm_eventlog_device_get_checksums (FuTpmEventlogDevice *self, guint8 pcr, GError **error)
{
	return fu_tpm_eventlog_calc_checksums (self->items, pcr, error);
}

static void
fu_tpm_eventlog_device_to_string (FuDevice *device, guint idt, GString *str)
{
	FuTpmEventlogDevice *self = FU_TPM_EVENTLOG_DEVICE (device);
	if (self->items->len > 0) {
		fu_common_string_append_kv (str, idt, "Items", NULL);
		for (guint i = 0; i < self->items->len; i++) {
			FuTpmEventlogItem *item = g_ptr_array_index (self->items, i);
			fu_tpm_eventlog_item_to_string (item, idt + 1, str);
		}
	}
}

gchar *
fu_tpm_eventlog_device_report_metadata (FuTpmEventlogDevice *self)
{
	GString *str = g_string_new ("");<commit_msg>tpm-eventlog: Fix a possible crash if not using _new()<commit_after>/*
 * Copyright (C) 2019 <NAME> <<EMAIL>>
 *
 * SPDX-License-Identifier: LGPL-2.1+
 */

#include "config.h"

#include <tss2/tss2_esys.h>

#include "fu-common.h"

#include "fu-tpm-eventlog-device.h"
#include "fu-tpm-eventlog-parser.h"

struct _FuTpmEventlogDevice {
	FuDevice		 parent_instance;
	GPtrArray		*items;
};

G_DEFINE_TYPE (FuTpmEventlogDevice, fu_tpm_eventlog_device, FU_TYPE_DEVICE)

GPtrArray *
fu_tpm_eventlog_device_get_checksums (FuTpmEventlogDevice *self, guint8 pcr, GError **error)
{
	return fu_tpm_eventlog_calc_checksums (self->items, pcr, error);
}

static void
fu_tpm_eventlog_device_to_string (FuDevice *device, guint idt, GString *str)
{
	FuTpmEventlogDevice *self = FU_TPM_EVENTLOG_DEVICE (device);
	if (self->items != NULL && self->items->len > 0) {
		fu_common_string_append_kv (str, idt, "Items", NULL);
		for (guint i = 0; i < self->items->len; i++) {
			FuTpmEventlogItem *item = g_ptr_array_index (self->items, i);
			fu_tpm_eventlog_item_to_string (item, idt + 1, str);
		}
	}
}

gchar *
fu_tpm_eventlog_device_report_metadata (FuTpmEventlogDevice *self)
{
	GString *str = g_string_new ("");
{'fraction_non_alphanumeric': 0.13287316652286454, 'fraction_numerical': 0.010353753235547885, 'mean_word_length': 5.532394366197183, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 26, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5207931', 'n_tokens_mistral': 1010, 'n_tokens_neox': 957, 'n_words': 182}