Coverage Report

Created: 2026-01-25 06:22

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/work/fu-tpm-struct.c
Line
Count
Source
1
/*
2
 * This file is auto-generated, do not modify!
3
 *
4
 * SPDX-License-Identifier: LGPL-2.1-or-later
5
 */
6
7
#include "config.h"
8
9
#include <glib.h>
10
11
#include "fu-tpm-struct.h"
12
#include "fu-byte-array.h"
13
#include "fu-mem-private.h"
14
#include "fu-string.h"
15
16
#ifdef G_LOG_DOMAIN
17
  #undef G_LOG_DOMAIN
18
#endif
19
0
#define G_LOG_DOMAIN "FuStruct"
20
21
/**
22
 * fu_tpm_alg_to_string:
23
 * @val: value, e.g. %FU_TPM_ALG_SHA1
24
 *
25
 * Converts an enumerated value to a string.
26
 *
27
 * Returns: identifier string
28
 **/
29
const gchar *
30
fu_tpm_alg_to_string(FuTpmAlg val)
31
0
{
32
0
    if (val == FU_TPM_ALG_SHA1)
33
0
        return "sha1";
34
0
    if (val == FU_TPM_ALG_SHA256)
35
0
        return "sha256";
36
0
    if (val == FU_TPM_ALG_SHA384)
37
0
        return "sha384";
38
0
    if (val == FU_TPM_ALG_SHA512)
39
0
        return "sha512";
40
0
    if (val == FU_TPM_ALG_SM3_256)
41
0
        return "sm3-256";
42
0
    if (val == FU_TPM_ALG_SHA3_256)
43
0
        return "sha3-256";
44
0
    if (val == FU_TPM_ALG_SHA3_384)
45
0
        return "sha3-384";
46
0
    if (val == FU_TPM_ALG_SHA3_512)
47
0
        return "sha3-512";
48
0
    return NULL;
49
0
}
50
/**
51
 * fu_tpm_alg_from_string:
52
 * @val: (nullable): a string, e.g. `sha1`
53
 *
54
 * Converts a string to an enumerated value.
55
 *
56
 * Returns: enumerated value
57
 **/
58
FuTpmAlg
59
fu_tpm_alg_from_string(const gchar *val)
60
0
{
61
0
    if (g_strcmp0(val, "sha1") == 0)
62
0
        return FU_TPM_ALG_SHA1;
63
0
    if (g_strcmp0(val, "sha256") == 0)
64
0
        return FU_TPM_ALG_SHA256;
65
0
    if (g_strcmp0(val, "sha384") == 0)
66
0
        return FU_TPM_ALG_SHA384;
67
0
    if (g_strcmp0(val, "sha512") == 0)
68
0
        return FU_TPM_ALG_SHA512;
69
0
    if (g_strcmp0(val, "sm3-256") == 0)
70
0
        return FU_TPM_ALG_SM3_256;
71
0
    if (g_strcmp0(val, "sha3-256") == 0)
72
0
        return FU_TPM_ALG_SHA3_256;
73
0
    if (g_strcmp0(val, "sha3-384") == 0)
74
0
        return FU_TPM_ALG_SHA3_384;
75
0
    if (g_strcmp0(val, "sha3-512") == 0)
76
0
        return FU_TPM_ALG_SHA3_512;
77
0
    return FU_TPM_ALG_UNKNOWN;
78
0
}
79
80
/**
81
 * fu_tpm_eventlog_item_kind_to_string:
82
 * @val: value, e.g. %FU_TPM_EVENTLOG_ITEM_KIND_POST_CODE
83
 *
84
 * Converts an enumerated value to a string.
85
 *
86
 * Returns: identifier string
87
 **/
88
const gchar *
89
fu_tpm_eventlog_item_kind_to_string(FuTpmEventlogItemKind val)
90
0
{
91
0
    if (val == FU_TPM_EVENTLOG_ITEM_KIND_PREBOOT_CERT)
92
0
        return "preboot-cert";
93
0
    if (val == FU_TPM_EVENTLOG_ITEM_KIND_POST_CODE)
94
0
        return "post-code";
95
0
    if (val == FU_TPM_EVENTLOG_ITEM_KIND_NO_ACTION)
96
0
        return "no-action";
97
0
    if (val == FU_TPM_EVENTLOG_ITEM_KIND_SEPARATOR)
98
0
        return "separator";
99
0
    if (val == FU_TPM_EVENTLOG_ITEM_KIND_ACTION)
100
0
        return "action";
101
0
    if (val == FU_TPM_EVENTLOG_ITEM_KIND_EVENT_TAG)
102
0
        return "event-tag";
103
0
    if (val == FU_TPM_EVENTLOG_ITEM_KIND_S_CRTM_CONTENTS)
104
0
        return "s-crtm-contents";
105
0
    if (val == FU_TPM_EVENTLOG_ITEM_KIND_S_CRTM_VERSION)
106
0
        return "s-crtm-version";
107
0
    if (val == FU_TPM_EVENTLOG_ITEM_KIND_CPU_MICROCODE)
108
0
        return "cpu-microcode";
109
0
    if (val == FU_TPM_EVENTLOG_ITEM_KIND_PLATFORM_CONFIG_FLAGS)
110
0
        return "platform-config-flags";
111
0
    if (val == FU_TPM_EVENTLOG_ITEM_KIND_TABLE_OF_DEVICES)
112
0
        return "table-of-devices";
113
0
    if (val == FU_TPM_EVENTLOG_ITEM_KIND_COMPACT_HASH)
114
0
        return "compact-hash";
115
0
    if (val == FU_TPM_EVENTLOG_ITEM_KIND_NONHOST_CODE)
116
0
        return "nonhost-code";
117
0
    if (val == FU_TPM_EVENTLOG_ITEM_KIND_NONHOST_CONFIG)
118
0
        return "nonhost-config";
119
0
    if (val == FU_TPM_EVENTLOG_ITEM_KIND_NONHOST_INFO)
120
0
        return "nonhost-info";
121
0
    if (val == FU_TPM_EVENTLOG_ITEM_KIND_OMIT_BOOT_DEVICE_EVENTS)
122
0
        return "omit-boot-device-events";
123
0
    if (val == FU_TPM_EVENTLOG_ITEM_KIND_EFI_EVENT_BASE)
124
0
        return "efi-event-base";
125
0
    if (val == FU_TPM_EVENTLOG_ITEM_KIND_EFI_VARIABLE_DRIVER_CONFIG)
126
0
        return "efi-variable-driver-config";
127
0
    if (val == FU_TPM_EVENTLOG_ITEM_KIND_EFI_VARIABLE_BOOT)
128
0
        return "efi-variable-boot";
129
0
    if (val == FU_TPM_EVENTLOG_ITEM_KIND_EFI_BOOT_SERVICES_APPLICATION)
130
0
        return "efi-boot-services-application";
131
0
    if (val == FU_TPM_EVENTLOG_ITEM_KIND_EFI_BOOT_SERVICES_DRIVER)
132
0
        return "efi-boot-services-driver";
133
0
    if (val == FU_TPM_EVENTLOG_ITEM_KIND_EFI_RUNTIME_SERVICES_DRIVER)
134
0
        return "efi-runtime-services-driver";
135
0
    if (val == FU_TPM_EVENTLOG_ITEM_KIND_EFI_GPT_EVENT)
136
0
        return "efi-gpt-event";
137
0
    if (val == FU_TPM_EVENTLOG_ITEM_KIND_EFI_ACTION)
138
0
        return "efi-action";
139
0
    if (val == FU_TPM_EVENTLOG_ITEM_KIND_EFI_PLATFORM_FIRMWARE_BLOB)
140
0
        return "efi-platform-firmware-blob";
141
0
    if (val == FU_TPM_EVENTLOG_ITEM_KIND_EFI_HANDOFF_TABLES)
142
0
        return "efi-handoff-tables";
143
0
    if (val == FU_TPM_EVENTLOG_ITEM_KIND_EFI_HCRTM_EVENT)
144
0
        return "efi-hcrtm-event";
145
0
    if (val == FU_TPM_EVENTLOG_ITEM_KIND_EFI_VARIABLE_AUTHORITY)
146
0
        return "efi-variable-authority";
147
0
    return NULL;
148
0
}
149
/**
150
 * fu_tpm_eventlog_item_kind_from_string:
151
 * @val: (nullable): a string, e.g. `post-code`
152
 *
153
 * Converts a string to an enumerated value.
154
 *
155
 * Returns: enumerated value
156
 **/
157
FuTpmEventlogItemKind
158
fu_tpm_eventlog_item_kind_from_string(const gchar *val)
159
0
{
160
0
    if (g_strcmp0(val, "preboot-cert") == 0)
161
0
        return FU_TPM_EVENTLOG_ITEM_KIND_PREBOOT_CERT;
162
0
    if (g_strcmp0(val, "post-code") == 0)
163
0
        return FU_TPM_EVENTLOG_ITEM_KIND_POST_CODE;
164
0
    if (g_strcmp0(val, "no-action") == 0)
165
0
        return FU_TPM_EVENTLOG_ITEM_KIND_NO_ACTION;
166
0
    if (g_strcmp0(val, "separator") == 0)
167
0
        return FU_TPM_EVENTLOG_ITEM_KIND_SEPARATOR;
168
0
    if (g_strcmp0(val, "action") == 0)
169
0
        return FU_TPM_EVENTLOG_ITEM_KIND_ACTION;
170
0
    if (g_strcmp0(val, "event-tag") == 0)
171
0
        return FU_TPM_EVENTLOG_ITEM_KIND_EVENT_TAG;
172
0
    if (g_strcmp0(val, "s-crtm-contents") == 0)
173
0
        return FU_TPM_EVENTLOG_ITEM_KIND_S_CRTM_CONTENTS;
174
0
    if (g_strcmp0(val, "s-crtm-version") == 0)
175
0
        return FU_TPM_EVENTLOG_ITEM_KIND_S_CRTM_VERSION;
176
0
    if (g_strcmp0(val, "cpu-microcode") == 0)
177
0
        return FU_TPM_EVENTLOG_ITEM_KIND_CPU_MICROCODE;
178
0
    if (g_strcmp0(val, "platform-config-flags") == 0)
179
0
        return FU_TPM_EVENTLOG_ITEM_KIND_PLATFORM_CONFIG_FLAGS;
180
0
    if (g_strcmp0(val, "table-of-devices") == 0)
181
0
        return FU_TPM_EVENTLOG_ITEM_KIND_TABLE_OF_DEVICES;
182
0
    if (g_strcmp0(val, "compact-hash") == 0)
183
0
        return FU_TPM_EVENTLOG_ITEM_KIND_COMPACT_HASH;
184
0
    if (g_strcmp0(val, "nonhost-code") == 0)
185
0
        return FU_TPM_EVENTLOG_ITEM_KIND_NONHOST_CODE;
186
0
    if (g_strcmp0(val, "nonhost-config") == 0)
187
0
        return FU_TPM_EVENTLOG_ITEM_KIND_NONHOST_CONFIG;
188
0
    if (g_strcmp0(val, "nonhost-info") == 0)
189
0
        return FU_TPM_EVENTLOG_ITEM_KIND_NONHOST_INFO;
190
0
    if (g_strcmp0(val, "omit-boot-device-events") == 0)
191
0
        return FU_TPM_EVENTLOG_ITEM_KIND_OMIT_BOOT_DEVICE_EVENTS;
192
0
    if (g_strcmp0(val, "efi-event-base") == 0)
193
0
        return FU_TPM_EVENTLOG_ITEM_KIND_EFI_EVENT_BASE;
194
0
    if (g_strcmp0(val, "efi-variable-driver-config") == 0)
195
0
        return FU_TPM_EVENTLOG_ITEM_KIND_EFI_VARIABLE_DRIVER_CONFIG;
196
0
    if (g_strcmp0(val, "efi-variable-boot") == 0)
197
0
        return FU_TPM_EVENTLOG_ITEM_KIND_EFI_VARIABLE_BOOT;
198
0
    if (g_strcmp0(val, "efi-boot-services-application") == 0)
199
0
        return FU_TPM_EVENTLOG_ITEM_KIND_EFI_BOOT_SERVICES_APPLICATION;
200
0
    if (g_strcmp0(val, "efi-boot-services-driver") == 0)
201
0
        return FU_TPM_EVENTLOG_ITEM_KIND_EFI_BOOT_SERVICES_DRIVER;
202
0
    if (g_strcmp0(val, "efi-runtime-services-driver") == 0)
203
0
        return FU_TPM_EVENTLOG_ITEM_KIND_EFI_RUNTIME_SERVICES_DRIVER;
204
0
    if (g_strcmp0(val, "efi-gpt-event") == 0)
205
0
        return FU_TPM_EVENTLOG_ITEM_KIND_EFI_GPT_EVENT;
206
0
    if (g_strcmp0(val, "efi-action") == 0)
207
0
        return FU_TPM_EVENTLOG_ITEM_KIND_EFI_ACTION;
208
0
    if (g_strcmp0(val, "efi-platform-firmware-blob") == 0)
209
0
        return FU_TPM_EVENTLOG_ITEM_KIND_EFI_PLATFORM_FIRMWARE_BLOB;
210
0
    if (g_strcmp0(val, "efi-handoff-tables") == 0)
211
0
        return FU_TPM_EVENTLOG_ITEM_KIND_EFI_HANDOFF_TABLES;
212
0
    if (g_strcmp0(val, "efi-hcrtm-event") == 0)
213
0
        return FU_TPM_EVENTLOG_ITEM_KIND_EFI_HCRTM_EVENT;
214
0
    if (g_strcmp0(val, "efi-variable-authority") == 0)
215
0
        return FU_TPM_EVENTLOG_ITEM_KIND_EFI_VARIABLE_AUTHORITY;
216
0
    return FU_TPM_EVENTLOG_ITEM_KIND_PREBOOT_CERT;
217
0
}
218
/**
219
 * fu_struct_tpm_efi_startup_locality_event_ref: (skip):
220
 **/
221
FuStructTpmEfiStartupLocalityEvent *
222
fu_struct_tpm_efi_startup_locality_event_ref(FuStructTpmEfiStartupLocalityEvent *st)
223
0
{
224
0
    g_return_val_if_fail(st != NULL, NULL);
225
0
    st->refcount++;
226
0
    return st;
227
0
}
228
/**
229
 * fu_struct_tpm_efi_startup_locality_event_unref: (skip):
230
 **/
231
void
232
fu_struct_tpm_efi_startup_locality_event_unref(FuStructTpmEfiStartupLocalityEvent *st)
233
0
{
234
0
    g_return_if_fail(st != NULL);
235
0
    if (st->refcount == 0) {
236
0
        g_critical("FuStructTpmEfiStartupLocalityEvent refcount already zero");
237
0
        return;
238
0
    }
239
0
    if (--st->refcount > 0)
240
0
        return;
241
0
    if (st->buf != NULL)
242
0
        g_byte_array_unref(st->buf);
243
0
    g_free(st);
244
0
}
245
/**
246
 * fu_struct_tpm_efi_startup_locality_event_new_internal: (skip):
247
 **/
248
static FuStructTpmEfiStartupLocalityEvent *
249
fu_struct_tpm_efi_startup_locality_event_new_internal(void)
250
0
{
251
0
    FuStructTpmEfiStartupLocalityEvent *st = g_new0(FuStructTpmEfiStartupLocalityEvent, 1);
252
0
    st->refcount = 1;
253
0
    return st;
254
0
}
255
256
/* getters */
257
/**
258
 * fu_struct_tpm_efi_startup_locality_event_get_signature: (skip):
259
 **/
260
static gchar *
261
fu_struct_tpm_efi_startup_locality_event_get_signature(const FuStructTpmEfiStartupLocalityEvent *st)
262
0
{
263
0
    g_return_val_if_fail(st != NULL, NULL);
264
0
    return fu_memstrsafe(st->buf->data, st->buf->len, 0, 16, NULL);
265
0
}
266
/**
267
 * fu_struct_tpm_efi_startup_locality_event_get_locality: (skip):
268
 **/
269
guint8
270
fu_struct_tpm_efi_startup_locality_event_get_locality(const FuStructTpmEfiStartupLocalityEvent *st)
271
0
{
272
0
    g_return_val_if_fail(st != NULL, 0x0);
273
0
    return st->buf->data[16];
274
0
}
275
276
/* setters */
277
/**
278
 * fu_struct_tpm_efi_startup_locality_event_to_string: (skip):
279
 **/
280
static gchar *
281
fu_struct_tpm_efi_startup_locality_event_to_string(const FuStructTpmEfiStartupLocalityEvent *st)
282
0
{
283
0
    g_autoptr(GString) str = g_string_new("FuStructTpmEfiStartupLocalityEvent:\n");
284
0
    g_return_val_if_fail(st != NULL, NULL);
285
0
    {
286
0
        g_autofree gchar *tmp = fu_struct_tpm_efi_startup_locality_event_get_signature(st);
287
0
        if (tmp != NULL)
288
0
            g_string_append_printf(str, "  signature: %s\n", tmp);
289
0
    }
290
0
    g_string_append_printf(str, "  locality: 0x%x\n",
291
0
                           (guint) fu_struct_tpm_efi_startup_locality_event_get_locality(st));
292
0
    if (str->len > 0)
293
0
        g_string_set_size(str, str->len - 1);
294
0
    return g_string_free(g_steal_pointer(&str), FALSE);
295
0
}
296
static gboolean
297
fu_struct_tpm_efi_startup_locality_event_validate_internal(FuStructTpmEfiStartupLocalityEvent *st, GError **error)
298
0
{
299
0
    g_return_val_if_fail(st != NULL, FALSE);
300
0
    if (strncmp((const gchar *) (st->buf->data + 0), "StartupLocality", 16) != 0) {
301
0
        g_autofree gchar *str = fu_struct_tpm_efi_startup_locality_event_get_signature(st);
302
0
        g_set_error(error,
303
0
                    FWUPD_ERROR,
304
0
                    FWUPD_ERROR_INVALID_DATA,
305
0
                    "constant FuStructTpmEfiStartupLocalityEvent.signature was not valid, "
306
0
                    "expected 'StartupLocality' and got '%s'",
307
0
                    str);
308
0
        return FALSE;
309
0
    }
310
0
    return TRUE;
311
0
}
312
static gboolean
313
fu_struct_tpm_efi_startup_locality_event_parse_internal(FuStructTpmEfiStartupLocalityEvent *st, GError **error)
314
0
{
315
0
    if (g_getenv("FWUPD_VERBOSE") != NULL) {
316
0
        g_autofree gchar *str = fu_struct_tpm_efi_startup_locality_event_to_string(st);
317
0
        g_debug("%s", str);
318
0
    }
319
0
    if (!fu_struct_tpm_efi_startup_locality_event_validate_internal(st, error))
320
0
        return FALSE;
321
0
    return TRUE;
322
0
}
323
324
/**
325
 * fu_struct_tpm_efi_startup_locality_event_parse: (skip):
326
 **/
327
static FuStructTpmEfiStartupLocalityEvent *
328
fu_struct_tpm_efi_startup_locality_event_parse(const guint8 *buf, gsize bufsz, gsize offset, GError **error)
329
0
{
330
0
    g_autoptr(FuStructTpmEfiStartupLocalityEvent) st = fu_struct_tpm_efi_startup_locality_event_new_internal();
331
0
    g_return_val_if_fail(buf != NULL, NULL);
332
0
    g_return_val_if_fail(error == NULL || *error == NULL, NULL);
333
0
    if (!fu_memchk_read(bufsz, offset, 17, error)) {
334
0
        g_prefix_error_literal(error, "invalid struct FuStructTpmEfiStartupLocalityEvent: ");
335
0
        return NULL;
336
0
    }
337
0
    st->buf = g_byte_array_new();
338
0
    g_byte_array_append(st->buf, buf + offset, 17);
339
0
    if (!fu_struct_tpm_efi_startup_locality_event_parse_internal(st, error))
340
0
        return NULL;
341
0
    return g_steal_pointer(&st);
342
0
}
343
/**
344
 * fu_struct_tpm_efi_startup_locality_event_parse_bytes: (skip):
345
 **/
346
FuStructTpmEfiStartupLocalityEvent *
347
fu_struct_tpm_efi_startup_locality_event_parse_bytes(GBytes *blob, gsize offset, GError **error)
348
0
{
349
0
    gsize bufsz = 0;
350
0
    const guint8 *buf = g_bytes_get_data(blob, &bufsz);
351
0
    return fu_struct_tpm_efi_startup_locality_event_parse(buf, bufsz, offset, error);
352
0
}
353
/**
354
 * fu_struct_tpm_event_log1_item_ref: (skip):
355
 **/
356
FuStructTpmEventLog1Item *
357
fu_struct_tpm_event_log1_item_ref(FuStructTpmEventLog1Item *st)
358
0
{
359
0
    g_return_val_if_fail(st != NULL, NULL);
360
0
    st->refcount++;
361
0
    return st;
362
0
}
363
/**
364
 * fu_struct_tpm_event_log1_item_unref: (skip):
365
 **/
366
void
367
fu_struct_tpm_event_log1_item_unref(FuStructTpmEventLog1Item *st)
368
0
{
369
0
    g_return_if_fail(st != NULL);
370
0
    if (st->refcount == 0) {
371
0
        g_critical("FuStructTpmEventLog1Item refcount already zero");
372
0
        return;
373
0
    }
374
0
    if (--st->refcount > 0)
375
0
        return;
376
0
    if (st->buf != NULL)
377
0
        g_byte_array_unref(st->buf);
378
0
    g_free(st);
379
0
}
380
/**
381
 * fu_struct_tpm_event_log1_item_new_internal: (skip):
382
 **/
383
static FuStructTpmEventLog1Item *
384
fu_struct_tpm_event_log1_item_new_internal(void)
385
0
{
386
0
    FuStructTpmEventLog1Item *st = g_new0(FuStructTpmEventLog1Item, 1);
387
0
    st->refcount = 1;
388
0
    return st;
389
0
}
390
391
/* getters */
392
/**
393
 * fu_struct_tpm_event_log1_item_get_pcr: (skip):
394
 **/
395
guint32
396
fu_struct_tpm_event_log1_item_get_pcr(const FuStructTpmEventLog1Item *st)
397
0
{
398
0
    g_return_val_if_fail(st != NULL, 0x0);
399
0
    return fu_memread_uint32(st->buf->data + 0, G_LITTLE_ENDIAN);
400
0
}
401
/**
402
 * fu_struct_tpm_event_log1_item_get_type: (skip):
403
 **/
404
FuTpmEventlogItemKind
405
fu_struct_tpm_event_log1_item_get_type(const FuStructTpmEventLog1Item *st)
406
0
{
407
0
    g_return_val_if_fail(st != NULL, 0x0);
408
0
    return fu_memread_uint32(st->buf->data + 4, G_LITTLE_ENDIAN);
409
0
}
410
/**
411
 * fu_struct_tpm_event_log1_item_get_digest: (skip):
412
 **/
413
const guint8 *
414
fu_struct_tpm_event_log1_item_get_digest(const FuStructTpmEventLog1Item *st, gsize *bufsz)
415
0
{
416
0
    g_return_val_if_fail(st != NULL, NULL);
417
0
    if (bufsz != NULL)
418
0
        *bufsz = 20;
419
0
    return st->buf->data + 8;
420
0
}
421
/**
422
 * fu_struct_tpm_event_log1_item_get_datasz: (skip):
423
 **/
424
guint32
425
fu_struct_tpm_event_log1_item_get_datasz(const FuStructTpmEventLog1Item *st)
426
0
{
427
0
    g_return_val_if_fail(st != NULL, 0x0);
428
0
    return fu_memread_uint32(st->buf->data + 28, G_LITTLE_ENDIAN);
429
0
}
430
431
/* setters */
432
/**
433
 * fu_struct_tpm_event_log1_item_set_pcr: (skip):
434
 **/
435
void
436
fu_struct_tpm_event_log1_item_set_pcr(FuStructTpmEventLog1Item *st, guint32 value)
437
0
{
438
0
    g_return_if_fail(st != NULL);
439
0
    fu_memwrite_uint32(st->buf->data + 0, value, G_LITTLE_ENDIAN);
440
0
}
441
/**
442
 * fu_struct_tpm_event_log1_item_set_type: (skip):
443
 **/
444
void
445
fu_struct_tpm_event_log1_item_set_type(FuStructTpmEventLog1Item *st, FuTpmEventlogItemKind value)
446
0
{
447
0
    g_return_if_fail(st != NULL);
448
0
    fu_memwrite_uint32(st->buf->data + 4, value, G_LITTLE_ENDIAN);
449
0
}
450
/**
451
 * fu_struct_tpm_event_log1_item_set_digest: (skip):
452
 **/
453
gboolean
454
fu_struct_tpm_event_log1_item_set_digest(FuStructTpmEventLog1Item *st, const guint8 *buf, gsize bufsz, GError **error)
455
0
{
456
0
    g_return_val_if_fail(st != NULL, FALSE);
457
0
    g_return_val_if_fail(buf != NULL, FALSE);
458
0
    g_return_val_if_fail(error == NULL || *error == NULL, FALSE);
459
0
    return fu_memcpy_safe(st->buf->data, st->buf->len, 8, buf, bufsz, 0x0, bufsz, error);
460
0
}
461
/**
462
 * fu_struct_tpm_event_log1_item_set_datasz: (skip):
463
 **/
464
void
465
fu_struct_tpm_event_log1_item_set_datasz(FuStructTpmEventLog1Item *st, guint32 value)
466
0
{
467
0
    g_return_if_fail(st != NULL);
468
0
    fu_memwrite_uint32(st->buf->data + 28, value, G_LITTLE_ENDIAN);
469
0
}
470
/**
471
 * fu_struct_tpm_event_log1_item_new: (skip):
472
 **/
473
FuStructTpmEventLog1Item *
474
fu_struct_tpm_event_log1_item_new(void)
475
0
{
476
0
    FuStructTpmEventLog1Item *st = fu_struct_tpm_event_log1_item_new_internal();
477
0
    st->buf = g_byte_array_sized_new(32);
478
0
    fu_byte_array_set_size(st->buf, 32, 0x0);
479
0
    return st;
480
0
}
481
/**
482
 * fu_struct_tpm_event_log1_item_to_string: (skip):
483
 **/
484
static gchar *
485
fu_struct_tpm_event_log1_item_to_string(const FuStructTpmEventLog1Item *st)
486
0
{
487
0
    g_autoptr(GString) str = g_string_new("FuStructTpmEventLog1Item:\n");
488
0
    g_return_val_if_fail(st != NULL, NULL);
489
0
    g_string_append_printf(str, "  pcr: 0x%x\n",
490
0
                           (guint) fu_struct_tpm_event_log1_item_get_pcr(st));
491
0
    {
492
0
        const gchar *tmp = fu_tpm_eventlog_item_kind_to_string(fu_struct_tpm_event_log1_item_get_type(st));
493
0
        if (tmp != NULL) {
494
0
            g_string_append_printf(str, "  type: 0x%x [%s]\n", (guint) fu_struct_tpm_event_log1_item_get_type(st), tmp);
495
0
        } else {
496
0
            g_string_append_printf(str, "  type: 0x%x\n", (guint) fu_struct_tpm_event_log1_item_get_type(st));
497
0
        }
498
0
    }
499
0
    {
500
0
        gsize bufsz = 0;
501
0
        const guint8 *buf = fu_struct_tpm_event_log1_item_get_digest(st, &bufsz);
502
0
        g_autoptr(GString) tmp = g_string_new(NULL);
503
0
        for (gsize i = 0; i < bufsz; i++)
504
0
            g_string_append_printf(tmp, "%02X", buf[i]);
505
0
        g_string_append_printf(str, "  digest: 0x%s\n", tmp->str);
506
0
    }
507
0
    g_string_append_printf(str, "  datasz: 0x%x\n",
508
0
                           (guint) fu_struct_tpm_event_log1_item_get_datasz(st));
509
0
    if (str->len > 0)
510
0
        g_string_set_size(str, str->len - 1);
511
0
    return g_string_free(g_steal_pointer(&str), FALSE);
512
0
}
513
static gboolean
514
fu_struct_tpm_event_log1_item_validate_internal(FuStructTpmEventLog1Item *st, GError **error)
515
0
{
516
0
    g_return_val_if_fail(st != NULL, FALSE);
517
0
    return TRUE;
518
0
}
519
static gboolean
520
fu_struct_tpm_event_log1_item_parse_internal(FuStructTpmEventLog1Item *st, GError **error)
521
0
{
522
0
    if (g_getenv("FWUPD_VERBOSE") != NULL) {
523
0
        g_autofree gchar *str = fu_struct_tpm_event_log1_item_to_string(st);
524
0
        g_debug("%s", str);
525
0
    }
526
0
    if (!fu_struct_tpm_event_log1_item_validate_internal(st, error))
527
0
        return FALSE;
528
0
    return TRUE;
529
0
}
530
/**
531
 * fu_struct_tpm_event_log1_item_parse_stream: (skip):
532
 **/
533
FuStructTpmEventLog1Item *
534
fu_struct_tpm_event_log1_item_parse_stream(GInputStream *stream, gsize offset, GError **error)
535
0
{
536
0
    g_autoptr(FuStructTpmEventLog1Item) st = fu_struct_tpm_event_log1_item_new_internal();
537
0
    st->buf = fu_input_stream_read_byte_array(stream, offset, 32, NULL, error);
538
0
    if (st->buf == NULL) {
539
0
        g_prefix_error(error, "FuStructTpmEventLog1Item failed read of 0x%x: ", (guint) 32);
540
0
        return NULL;
541
0
    }
542
0
    if (st->buf->len != 32) {
543
0
        g_set_error(error,
544
0
                    FWUPD_ERROR,
545
0
                    FWUPD_ERROR_INVALID_DATA,
546
0
                    "FuStructTpmEventLog1Item requested 0x%x and got 0x%x",
547
0
                    (guint) 32,
548
0
                    (guint) st->buf->len);
549
0
        return NULL;
550
0
    }
551
0
    if (!fu_struct_tpm_event_log1_item_parse_internal(st, error))
552
0
        return NULL;
553
0
    return g_steal_pointer(&st);
554
0
}
555
/**
556
 * fu_struct_tpm_event_log2_hdr_ref: (skip):
557
 **/
558
FuStructTpmEventLog2Hdr *
559
fu_struct_tpm_event_log2_hdr_ref(FuStructTpmEventLog2Hdr *st)
560
0
{
561
0
    g_return_val_if_fail(st != NULL, NULL);
562
0
    st->refcount++;
563
0
    return st;
564
0
}
565
/**
566
 * fu_struct_tpm_event_log2_hdr_unref: (skip):
567
 **/
568
void
569
fu_struct_tpm_event_log2_hdr_unref(FuStructTpmEventLog2Hdr *st)
570
0
{
571
0
    g_return_if_fail(st != NULL);
572
0
    if (st->refcount == 0) {
573
0
        g_critical("FuStructTpmEventLog2Hdr refcount already zero");
574
0
        return;
575
0
    }
576
0
    if (--st->refcount > 0)
577
0
        return;
578
0
    if (st->buf != NULL)
579
0
        g_byte_array_unref(st->buf);
580
0
    g_free(st);
581
0
}
582
/**
583
 * fu_struct_tpm_event_log2_hdr_new_internal: (skip):
584
 **/
585
static FuStructTpmEventLog2Hdr *
586
fu_struct_tpm_event_log2_hdr_new_internal(void)
587
0
{
588
0
    FuStructTpmEventLog2Hdr *st = g_new0(FuStructTpmEventLog2Hdr, 1);
589
0
    st->refcount = 1;
590
0
    return st;
591
0
}
592
593
/* getters */
594
/**
595
 * fu_struct_tpm_event_log2_hdr_get_pcr: (skip):
596
 **/
597
static guint32
598
fu_struct_tpm_event_log2_hdr_get_pcr(const FuStructTpmEventLog2Hdr *st)
599
0
{
600
0
    g_return_val_if_fail(st != NULL, 0x0);
601
0
    return fu_memread_uint32(st->buf->data + 0, G_LITTLE_ENDIAN);
602
0
}
603
/**
604
 * fu_struct_tpm_event_log2_hdr_get_type: (skip):
605
 **/
606
static FuTpmEventlogItemKind
607
fu_struct_tpm_event_log2_hdr_get_type(const FuStructTpmEventLog2Hdr *st)
608
0
{
609
0
    g_return_val_if_fail(st != NULL, 0x0);
610
0
    return fu_memread_uint32(st->buf->data + 4, G_LITTLE_ENDIAN);
611
0
}
612
/**
613
 * fu_struct_tpm_event_log2_hdr_get_datasz: (skip):
614
 **/
615
guint32
616
fu_struct_tpm_event_log2_hdr_get_datasz(const FuStructTpmEventLog2Hdr *st)
617
0
{
618
0
    g_return_val_if_fail(st != NULL, 0x0);
619
0
    return fu_memread_uint32(st->buf->data + 28, G_LITTLE_ENDIAN);
620
0
}
621
/**
622
 * fu_struct_tpm_event_log2_hdr_get_data: (skip):
623
 **/
624
static gchar *
625
fu_struct_tpm_event_log2_hdr_get_data(const FuStructTpmEventLog2Hdr *st)
626
0
{
627
0
    g_return_val_if_fail(st != NULL, NULL);
628
0
    return fu_memstrsafe(st->buf->data, st->buf->len, 32, 15, NULL);
629
0
}
630
631
/* setters */
632
/**
633
 * fu_struct_tpm_event_log2_hdr_set_pcr: (skip):
634
 **/
635
static void
636
fu_struct_tpm_event_log2_hdr_set_pcr(FuStructTpmEventLog2Hdr *st, guint32 value)
637
0
{
638
0
    g_return_if_fail(st != NULL);
639
0
    fu_memwrite_uint32(st->buf->data + 0, value, G_LITTLE_ENDIAN);
640
0
}
641
/**
642
 * fu_struct_tpm_event_log2_hdr_set_type: (skip):
643
 **/
644
static void
645
fu_struct_tpm_event_log2_hdr_set_type(FuStructTpmEventLog2Hdr *st, FuTpmEventlogItemKind value)
646
0
{
647
0
    g_return_if_fail(st != NULL);
648
0
    fu_memwrite_uint32(st->buf->data + 4, value, G_LITTLE_ENDIAN);
649
0
}
650
/**
651
 * fu_struct_tpm_event_log2_hdr_set_datasz: (skip):
652
 **/
653
void
654
fu_struct_tpm_event_log2_hdr_set_datasz(FuStructTpmEventLog2Hdr *st, guint32 value)
655
0
{
656
0
    g_return_if_fail(st != NULL);
657
0
    fu_memwrite_uint32(st->buf->data + 28, value, G_LITTLE_ENDIAN);
658
0
}
659
/**
660
 * fu_struct_tpm_event_log2_hdr_set_data: (skip):
661
 **/
662
static gboolean
663
fu_struct_tpm_event_log2_hdr_set_data(FuStructTpmEventLog2Hdr *st, const gchar *value, GError **error)
664
0
{
665
0
    gsize len;
666
0
    g_return_val_if_fail(st != NULL, FALSE);
667
0
    g_return_val_if_fail(error == NULL || *error == NULL, FALSE);
668
0
    if (value == NULL) {
669
0
        memset(st->buf->data + 32, 0x0, 15);
670
0
        return TRUE;
671
0
    }
672
0
    len = strlen(value);
673
0
    if (len > 15) {
674
0
        g_set_error(error,
675
0
                    FWUPD_ERROR,
676
0
                    FWUPD_ERROR_INVALID_DATA,
677
0
                    "string '%s' (0x%x bytes) does not fit in FuStructTpmEventLog2Hdr.data (0x%x bytes)",
678
0
                    value, (guint) len, (guint) 15);
679
0
        return FALSE;
680
0
    }
681
0
    return fu_memcpy_safe(st->buf->data, st->buf->len, 32, (const guint8 *)value, len, 0x0, len, error);
682
0
}
683
/**
684
 * fu_struct_tpm_event_log2_hdr_new: (skip):
685
 **/
686
FuStructTpmEventLog2Hdr *
687
fu_struct_tpm_event_log2_hdr_new(void)
688
0
{
689
0
    FuStructTpmEventLog2Hdr *st = fu_struct_tpm_event_log2_hdr_new_internal();
690
0
    st->buf = g_byte_array_sized_new(47);
691
0
    fu_byte_array_set_size(st->buf, 47, 0x0);
692
0
    fu_struct_tpm_event_log2_hdr_set_pcr(st, 0x0);
693
0
    fu_struct_tpm_event_log2_hdr_set_type(st, FU_TPM_EVENTLOG_ITEM_KIND_NO_ACTION);
694
0
    fu_struct_tpm_event_log2_hdr_set_datasz(st, 15);
695
0
    fu_struct_tpm_event_log2_hdr_set_data(st, "Spec ID Event03", NULL);
696
0
    return st;
697
0
}
698
/**
699
 * fu_struct_tpm_event_log2_hdr_to_string: (skip):
700
 **/
701
static gchar *
702
fu_struct_tpm_event_log2_hdr_to_string(const FuStructTpmEventLog2Hdr *st)
703
0
{
704
0
    g_autoptr(GString) str = g_string_new("FuStructTpmEventLog2Hdr:\n");
705
0
    g_return_val_if_fail(st != NULL, NULL);
706
0
    g_string_append_printf(str, "  pcr: 0x%x\n",
707
0
                           (guint) fu_struct_tpm_event_log2_hdr_get_pcr(st));
708
0
    {
709
0
        const gchar *tmp = fu_tpm_eventlog_item_kind_to_string(fu_struct_tpm_event_log2_hdr_get_type(st));
710
0
        if (tmp != NULL) {
711
0
            g_string_append_printf(str, "  type: 0x%x [%s]\n", (guint) fu_struct_tpm_event_log2_hdr_get_type(st), tmp);
712
0
        } else {
713
0
            g_string_append_printf(str, "  type: 0x%x\n", (guint) fu_struct_tpm_event_log2_hdr_get_type(st));
714
0
        }
715
0
    }
716
0
    g_string_append_printf(str, "  datasz: 0x%x\n",
717
0
                           (guint) fu_struct_tpm_event_log2_hdr_get_datasz(st));
718
0
    {
719
0
        g_autofree gchar *tmp = fu_struct_tpm_event_log2_hdr_get_data(st);
720
0
        if (tmp != NULL)
721
0
            g_string_append_printf(str, "  data: %s\n", tmp);
722
0
    }
723
0
    if (str->len > 0)
724
0
        g_string_set_size(str, str->len - 1);
725
0
    return g_string_free(g_steal_pointer(&str), FALSE);
726
0
}
727
static gboolean
728
fu_struct_tpm_event_log2_hdr_validate_internal(FuStructTpmEventLog2Hdr *st, GError **error)
729
0
{
730
0
    g_return_val_if_fail(st != NULL, FALSE);
731
0
    if (fu_struct_tpm_event_log2_hdr_get_pcr(st) != 0x0) {
732
0
        g_set_error(error,
733
0
                    FWUPD_ERROR,
734
0
                    FWUPD_ERROR_INVALID_DATA,
735
0
                    "constant FuStructTpmEventLog2Hdr.pcr was not valid, "
736
0
                    "expected 0x%x and got 0x%x",
737
0
                    (guint) 0x0,
738
0
                    (guint) fu_struct_tpm_event_log2_hdr_get_pcr(st));
739
0
        return FALSE;
740
0
    }
741
0
    if (fu_struct_tpm_event_log2_hdr_get_type(st) != FU_TPM_EVENTLOG_ITEM_KIND_NO_ACTION) {
742
0
        g_set_error(error,
743
0
                    FWUPD_ERROR,
744
0
                    FWUPD_ERROR_INVALID_DATA,
745
0
                    "constant FuStructTpmEventLog2Hdr.type was not valid, "
746
0
                    "expected 'FU_TPM_EVENTLOG_ITEM_KIND_NO_ACTION' and got 0x%x '%s'",
747
0
                    fu_struct_tpm_event_log2_hdr_get_type(st),
748
0
                    fu_tpm_eventlog_item_kind_to_string(fu_struct_tpm_event_log2_hdr_get_type(st)));
749
0
        return FALSE;
750
0
    }
751
0
    if (strncmp((const gchar *) (st->buf->data + 32), "Spec ID Event03", 15) != 0) {
752
0
        g_autofree gchar *str = fu_struct_tpm_event_log2_hdr_get_data(st);
753
0
        g_set_error(error,
754
0
                    FWUPD_ERROR,
755
0
                    FWUPD_ERROR_INVALID_DATA,
756
0
                    "constant FuStructTpmEventLog2Hdr.data was not valid, "
757
0
                    "expected 'Spec ID Event03' and got '%s'",
758
0
                    str);
759
0
        return FALSE;
760
0
    }
761
0
    return TRUE;
762
0
}
763
static gboolean
764
fu_struct_tpm_event_log2_hdr_parse_internal(FuStructTpmEventLog2Hdr *st, GError **error)
765
0
{
766
0
    if (g_getenv("FWUPD_VERBOSE") != NULL) {
767
0
        g_autofree gchar *str = fu_struct_tpm_event_log2_hdr_to_string(st);
768
0
        g_debug("%s", str);
769
0
    }
770
0
    if (!fu_struct_tpm_event_log2_hdr_validate_internal(st, error))
771
0
        return FALSE;
772
0
    return TRUE;
773
0
}
774
/**
775
 * fu_struct_tpm_event_log2_hdr_parse_stream: (skip):
776
 **/
777
FuStructTpmEventLog2Hdr *
778
fu_struct_tpm_event_log2_hdr_parse_stream(GInputStream *stream, gsize offset, GError **error)
779
0
{
780
0
    g_autoptr(FuStructTpmEventLog2Hdr) st = fu_struct_tpm_event_log2_hdr_new_internal();
781
0
    st->buf = fu_input_stream_read_byte_array(stream, offset, 47, NULL, error);
782
0
    if (st->buf == NULL) {
783
0
        g_prefix_error(error, "FuStructTpmEventLog2Hdr failed read of 0x%x: ", (guint) 47);
784
0
        return NULL;
785
0
    }
786
0
    if (st->buf->len != 47) {
787
0
        g_set_error(error,
788
0
                    FWUPD_ERROR,
789
0
                    FWUPD_ERROR_INVALID_DATA,
790
0
                    "FuStructTpmEventLog2Hdr requested 0x%x and got 0x%x",
791
0
                    (guint) 47,
792
0
                    (guint) st->buf->len);
793
0
        return NULL;
794
0
    }
795
0
    if (!fu_struct_tpm_event_log2_hdr_parse_internal(st, error))
796
0
        return NULL;
797
0
    return g_steal_pointer(&st);
798
0
}
799
/**
800
 * fu_struct_tpm_event_log2_ref: (skip):
801
 **/
802
FuStructTpmEventLog2 *
803
fu_struct_tpm_event_log2_ref(FuStructTpmEventLog2 *st)
804
0
{
805
0
    g_return_val_if_fail(st != NULL, NULL);
806
0
    st->refcount++;
807
0
    return st;
808
0
}
809
/**
810
 * fu_struct_tpm_event_log2_unref: (skip):
811
 **/
812
void
813
fu_struct_tpm_event_log2_unref(FuStructTpmEventLog2 *st)
814
0
{
815
0
    g_return_if_fail(st != NULL);
816
0
    if (st->refcount == 0) {
817
0
        g_critical("FuStructTpmEventLog2 refcount already zero");
818
0
        return;
819
0
    }
820
0
    if (--st->refcount > 0)
821
0
        return;
822
0
    if (st->buf != NULL)
823
0
        g_byte_array_unref(st->buf);
824
0
    g_free(st);
825
0
}
826
/**
827
 * fu_struct_tpm_event_log2_new_internal: (skip):
828
 **/
829
static FuStructTpmEventLog2 *
830
fu_struct_tpm_event_log2_new_internal(void)
831
0
{
832
0
    FuStructTpmEventLog2 *st = g_new0(FuStructTpmEventLog2, 1);
833
0
    st->refcount = 1;
834
0
    return st;
835
0
}
836
837
/* getters */
838
/**
839
 * fu_struct_tpm_event_log2_get_pcr: (skip):
840
 **/
841
guint32
842
fu_struct_tpm_event_log2_get_pcr(const FuStructTpmEventLog2 *st)
843
0
{
844
0
    g_return_val_if_fail(st != NULL, 0x0);
845
0
    return fu_memread_uint32(st->buf->data + 0, G_LITTLE_ENDIAN);
846
0
}
847
/**
848
 * fu_struct_tpm_event_log2_get_type: (skip):
849
 **/
850
FuTpmEventlogItemKind
851
fu_struct_tpm_event_log2_get_type(const FuStructTpmEventLog2 *st)
852
0
{
853
0
    g_return_val_if_fail(st != NULL, 0x0);
854
0
    return fu_memread_uint32(st->buf->data + 4, G_LITTLE_ENDIAN);
855
0
}
856
/**
857
 * fu_struct_tpm_event_log2_get_digest_count: (skip):
858
 **/
859
guint32
860
fu_struct_tpm_event_log2_get_digest_count(const FuStructTpmEventLog2 *st)
861
0
{
862
0
    g_return_val_if_fail(st != NULL, 0x0);
863
0
    return fu_memread_uint32(st->buf->data + 8, G_LITTLE_ENDIAN);
864
0
}
865
866
/* setters */
867
/**
868
 * fu_struct_tpm_event_log2_set_pcr: (skip):
869
 **/
870
void
871
fu_struct_tpm_event_log2_set_pcr(FuStructTpmEventLog2 *st, guint32 value)
872
0
{
873
0
    g_return_if_fail(st != NULL);
874
0
    fu_memwrite_uint32(st->buf->data + 0, value, G_LITTLE_ENDIAN);
875
0
}
876
/**
877
 * fu_struct_tpm_event_log2_set_type: (skip):
878
 **/
879
void
880
fu_struct_tpm_event_log2_set_type(FuStructTpmEventLog2 *st, FuTpmEventlogItemKind value)
881
0
{
882
0
    g_return_if_fail(st != NULL);
883
0
    fu_memwrite_uint32(st->buf->data + 4, value, G_LITTLE_ENDIAN);
884
0
}
885
/**
886
 * fu_struct_tpm_event_log2_set_digest_count: (skip):
887
 **/
888
void
889
fu_struct_tpm_event_log2_set_digest_count(FuStructTpmEventLog2 *st, guint32 value)
890
0
{
891
0
    g_return_if_fail(st != NULL);
892
0
    fu_memwrite_uint32(st->buf->data + 8, value, G_LITTLE_ENDIAN);
893
0
}
894
/**
895
 * fu_struct_tpm_event_log2_new: (skip):
896
 **/
897
FuStructTpmEventLog2 *
898
fu_struct_tpm_event_log2_new(void)
899
0
{
900
0
    FuStructTpmEventLog2 *st = fu_struct_tpm_event_log2_new_internal();
901
0
    st->buf = g_byte_array_sized_new(12);
902
0
    fu_byte_array_set_size(st->buf, 12, 0x0);
903
0
    return st;
904
0
}
905
/**
906
 * fu_struct_tpm_event_log2_to_string: (skip):
907
 **/
908
static gchar *
909
fu_struct_tpm_event_log2_to_string(const FuStructTpmEventLog2 *st)
910
0
{
911
0
    g_autoptr(GString) str = g_string_new("FuStructTpmEventLog2:\n");
912
0
    g_return_val_if_fail(st != NULL, NULL);
913
0
    g_string_append_printf(str, "  pcr: 0x%x\n",
914
0
                           (guint) fu_struct_tpm_event_log2_get_pcr(st));
915
0
    {
916
0
        const gchar *tmp = fu_tpm_eventlog_item_kind_to_string(fu_struct_tpm_event_log2_get_type(st));
917
0
        if (tmp != NULL) {
918
0
            g_string_append_printf(str, "  type: 0x%x [%s]\n", (guint) fu_struct_tpm_event_log2_get_type(st), tmp);
919
0
        } else {
920
0
            g_string_append_printf(str, "  type: 0x%x\n", (guint) fu_struct_tpm_event_log2_get_type(st));
921
0
        }
922
0
    }
923
0
    g_string_append_printf(str, "  digest_count: 0x%x\n",
924
0
                           (guint) fu_struct_tpm_event_log2_get_digest_count(st));
925
0
    if (str->len > 0)
926
0
        g_string_set_size(str, str->len - 1);
927
0
    return g_string_free(g_steal_pointer(&str), FALSE);
928
0
}
929
static gboolean
930
fu_struct_tpm_event_log2_validate_internal(FuStructTpmEventLog2 *st, GError **error)
931
0
{
932
0
    g_return_val_if_fail(st != NULL, FALSE);
933
0
    return TRUE;
934
0
}
935
static gboolean
936
fu_struct_tpm_event_log2_parse_internal(FuStructTpmEventLog2 *st, GError **error)
937
0
{
938
0
    if (g_getenv("FWUPD_VERBOSE") != NULL) {
939
0
        g_autofree gchar *str = fu_struct_tpm_event_log2_to_string(st);
940
0
        g_debug("%s", str);
941
0
    }
942
0
    if (!fu_struct_tpm_event_log2_validate_internal(st, error))
943
0
        return FALSE;
944
0
    return TRUE;
945
0
}
946
/**
947
 * fu_struct_tpm_event_log2_parse_stream: (skip):
948
 **/
949
FuStructTpmEventLog2 *
950
fu_struct_tpm_event_log2_parse_stream(GInputStream *stream, gsize offset, GError **error)
951
0
{
952
0
    g_autoptr(FuStructTpmEventLog2) st = fu_struct_tpm_event_log2_new_internal();
953
0
    st->buf = fu_input_stream_read_byte_array(stream, offset, 12, NULL, error);
954
0
    if (st->buf == NULL) {
955
0
        g_prefix_error(error, "FuStructTpmEventLog2 failed read of 0x%x: ", (guint) 12);
956
0
        return NULL;
957
0
    }
958
0
    if (st->buf->len != 12) {
959
0
        g_set_error(error,
960
0
                    FWUPD_ERROR,
961
0
                    FWUPD_ERROR_INVALID_DATA,
962
0
                    "FuStructTpmEventLog2 requested 0x%x and got 0x%x",
963
0
                    (guint) 12,
964
0
                    (guint) st->buf->len);
965
0
        return NULL;
966
0
    }
967
0
    if (!fu_struct_tpm_event_log2_parse_internal(st, error))
968
0
        return NULL;
969
0
    return g_steal_pointer(&st);
970
0
}