Coverage Report

Created: 2026-02-26 06:27

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