Coverage Report

Created: 2026-09-14 07:00

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
6.12k
{
33
6.12k
    if (val == FU_TPM_ALG_SHA1)
34
1.93k
        return "sha1";
35
4.19k
    if (val == FU_TPM_ALG_SHA256)
36
2.19k
        return "sha256";
37
1.99k
    if (val == FU_TPM_ALG_SHA384)
38
1.99k
        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
128
{
92
128
    if (val == FU_TPM_EVENTLOG_ITEM_KIND_PREBOOT_CERT)
93
1
        return "preboot-cert";
94
127
    if (val == FU_TPM_EVENTLOG_ITEM_KIND_POST_CODE)
95
1
        return "post-code";
96
126
    if (val == FU_TPM_EVENTLOG_ITEM_KIND_NO_ACTION)
97
0
        return "no-action";
98
126
    if (val == FU_TPM_EVENTLOG_ITEM_KIND_SEPARATOR)
99
1
        return "separator";
100
125
    if (val == FU_TPM_EVENTLOG_ITEM_KIND_ACTION)
101
1
        return "action";
102
124
    if (val == FU_TPM_EVENTLOG_ITEM_KIND_EVENT_TAG)
103
1
        return "event-tag";
104
123
    if (val == FU_TPM_EVENTLOG_ITEM_KIND_S_CRTM_CONTENTS)
105
1
        return "s-crtm-contents";
106
122
    if (val == FU_TPM_EVENTLOG_ITEM_KIND_S_CRTM_VERSION)
107
1
        return "s-crtm-version";
108
121
    if (val == FU_TPM_EVENTLOG_ITEM_KIND_CPU_MICROCODE)
109
1
        return "cpu-microcode";
110
120
    if (val == FU_TPM_EVENTLOG_ITEM_KIND_PLATFORM_CONFIG_FLAGS)
111
1
        return "platform-config-flags";
112
119
    if (val == FU_TPM_EVENTLOG_ITEM_KIND_TABLE_OF_DEVICES)
113
1
        return "table-of-devices";
114
118
    if (val == FU_TPM_EVENTLOG_ITEM_KIND_COMPACT_HASH)
115
1
        return "compact-hash";
116
117
    if (val == FU_TPM_EVENTLOG_ITEM_KIND_NONHOST_CODE)
117
1
        return "nonhost-code";
118
116
    if (val == FU_TPM_EVENTLOG_ITEM_KIND_NONHOST_CONFIG)
119
1
        return "nonhost-config";
120
115
    if (val == FU_TPM_EVENTLOG_ITEM_KIND_NONHOST_INFO)
121
1
        return "nonhost-info";
122
114
    if (val == FU_TPM_EVENTLOG_ITEM_KIND_OMIT_BOOT_DEVICE_EVENTS)
123
1
        return "omit-boot-device-events";
124
113
    if (val == FU_TPM_EVENTLOG_ITEM_KIND_EFI_EVENT_BASE)
125
1
        return "efi-event-base";
126
112
    if (val == FU_TPM_EVENTLOG_ITEM_KIND_EFI_VARIABLE_DRIVER_CONFIG)
127
1
        return "efi-variable-driver-config";
128
111
    if (val == FU_TPM_EVENTLOG_ITEM_KIND_EFI_VARIABLE_BOOT)
129
1
        return "efi-variable-boot";
130
110
    if (val == FU_TPM_EVENTLOG_ITEM_KIND_EFI_BOOT_SERVICES_APPLICATION)
131
1
        return "efi-boot-services-application";
132
109
    if (val == FU_TPM_EVENTLOG_ITEM_KIND_EFI_BOOT_SERVICES_DRIVER)
133
1
        return "efi-boot-services-driver";
134
108
    if (val == FU_TPM_EVENTLOG_ITEM_KIND_EFI_RUNTIME_SERVICES_DRIVER)
135
1
        return "efi-runtime-services-driver";
136
107
    if (val == FU_TPM_EVENTLOG_ITEM_KIND_EFI_GPT_EVENT)
137
1
        return "efi-gpt-event";
138
106
    if (val == FU_TPM_EVENTLOG_ITEM_KIND_EFI_ACTION)
139
1
        return "efi-action";
140
105
    if (val == FU_TPM_EVENTLOG_ITEM_KIND_EFI_PLATFORM_FIRMWARE_BLOB)
141
1
        return "efi-platform-firmware-blob";
142
104
    if (val == FU_TPM_EVENTLOG_ITEM_KIND_EFI_HANDOFF_TABLES)
143
1
        return "efi-handoff-tables";
144
103
    if (val == FU_TPM_EVENTLOG_ITEM_KIND_EFI_HCRTM_EVENT)
145
1
        return "efi-hcrtm-event";
146
102
    if (val == FU_TPM_EVENTLOG_ITEM_KIND_EFI_VARIABLE_AUTHORITY)
147
1
        return "efi-variable-authority";
148
101
    return NULL;
149
102
}
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_log_get_debug_enabled()) {
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
582k
{
372
582k
    g_return_if_fail(st != NULL);
373
582k
    if (st->refcount == 0) {
374
0
        g_critical("FuStructTpmEventLog1Item refcount already zero");
375
0
        return;
376
0
    }
377
582k
    if (--st->refcount > 0)
378
0
        return;
379
582k
    if (st->buf != NULL)
380
582k
        g_byte_array_unref(st->buf);
381
582k
    g_free(st);
382
582k
}
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
582k
{
389
582k
    FuStructTpmEventLog1Item *st = g_new0(FuStructTpmEventLog1Item, 1);
390
582k
    st->refcount = 1;
391
582k
    return st;
392
582k
}
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
580k
{
401
580k
    g_return_val_if_fail(st != NULL, 0x0);
402
580k
    return fu_memread_uint32(st->buf->data + 0, G_LITTLE_ENDIAN);
403
580k
}
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
580k
{
410
580k
    g_return_val_if_fail(st != NULL, 0x0);
411
580k
    return fu_memread_uint32(st->buf->data + 4, G_LITTLE_ENDIAN);
412
580k
}
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
580k
{
419
580k
    g_return_val_if_fail(st != NULL, NULL);
420
580k
    if (bufsz != NULL)
421
580k
        *bufsz = 20;
422
580k
    return st->buf->data + 8;
423
580k
}
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
580k
{
430
580k
    g_return_val_if_fail(st != NULL, 0x0);
431
580k
    return fu_memread_uint32(st->buf->data + 28, G_LITTLE_ENDIAN);
432
580k
}
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
2.09k
{
441
2.09k
    g_return_if_fail(st != NULL);
442
2.09k
    fu_memwrite_uint32(st->buf->data + 0, value, G_LITTLE_ENDIAN);
443
2.09k
}
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
2.09k
{
450
2.09k
    g_return_if_fail(st != NULL);
451
2.09k
    fu_memwrite_uint32(st->buf->data + 4, value, G_LITTLE_ENDIAN);
452
2.09k
}
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
2.09k
{
459
2.09k
    g_return_val_if_fail(st != NULL, FALSE);
460
2.09k
    g_return_val_if_fail(buf != NULL, FALSE);
461
2.09k
    g_return_val_if_fail(error == NULL || *error == NULL, FALSE);
462
2.09k
    return fu_memcpy_safe(st->buf->data, st->buf->len, 8, buf, bufsz, 0x0, bufsz, error);
463
2.09k
}
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
1.98k
{
470
1.98k
    g_return_if_fail(st != NULL);
471
1.98k
    fu_memwrite_uint32(st->buf->data + 28, value, G_LITTLE_ENDIAN);
472
1.98k
}
473
/**
474
 * fu_struct_tpm_event_log1_item_new: (skip):
475
 **/
476
FuStructTpmEventLog1Item *
477
fu_struct_tpm_event_log1_item_new(void)
478
2.09k
{
479
2.09k
    FuStructTpmEventLog1Item *st = fu_struct_tpm_event_log1_item_new_internal();
480
2.09k
    st->buf = g_byte_array_sized_new(32);
481
2.09k
    fu_byte_array_set_size(st->buf, 32, 0x0);
482
2.09k
    return st;
483
2.09k
}
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_parse_internal(FuStructTpmEventLog1Item *st, GError **error)
518
580k
{
519
580k
    if (g_log_get_debug_enabled()) {
520
0
        g_autofree gchar *str = fu_struct_tpm_event_log1_item_to_string(st);
521
0
        g_debug("%s", str);
522
0
    }
523
580k
    return TRUE;
524
580k
}
525
/**
526
 * fu_struct_tpm_event_log1_item_parse_stream: (skip):
527
 **/
528
FuStructTpmEventLog1Item *
529
fu_struct_tpm_event_log1_item_parse_stream(FuInputStream *stream, gsize offset, GError **error)
530
580k
{
531
580k
    g_autoptr(FuStructTpmEventLog1Item) st = fu_struct_tpm_event_log1_item_new_internal();
532
580k
    st->buf = fu_input_stream_read_byte_array(stream, offset, 32, NULL, error);
533
580k
    if (st->buf == NULL) {
534
0
        g_prefix_error(error, "FuStructTpmEventLog1Item failed read of 0x%x: ", (guint) 32);
535
0
        return NULL;
536
0
    }
537
580k
    if (st->buf->len != 32) {
538
113
        g_set_error(error,
539
113
                    FWUPD_ERROR,
540
113
                    FWUPD_ERROR_INVALID_DATA,
541
113
                    "FuStructTpmEventLog1Item requested 0x%x and got 0x%x",
542
113
                    (guint) 32,
543
113
                    (guint) st->buf->len);
544
113
        return NULL;
545
113
    }
546
580k
    if (!fu_struct_tpm_event_log1_item_parse_internal(st, error))
547
0
        return NULL;
548
580k
    return g_steal_pointer(&st);
549
580k
}
550
/**
551
 * fu_struct_tpm_event_log2_hdr_ref: (skip):
552
 **/
553
FuStructTpmEventLog2Hdr *
554
fu_struct_tpm_event_log2_hdr_ref(FuStructTpmEventLog2Hdr *st)
555
0
{
556
0
    g_return_val_if_fail(st != NULL, NULL);
557
0
    st->refcount++;
558
0
    return st;
559
0
}
560
/**
561
 * fu_struct_tpm_event_log2_hdr_unref: (skip):
562
 **/
563
void
564
fu_struct_tpm_event_log2_hdr_unref(FuStructTpmEventLog2Hdr *st)
565
1.17k
{
566
1.17k
    g_return_if_fail(st != NULL);
567
1.17k
    if (st->refcount == 0) {
568
0
        g_critical("FuStructTpmEventLog2Hdr refcount already zero");
569
0
        return;
570
0
    }
571
1.17k
    if (--st->refcount > 0)
572
0
        return;
573
1.17k
    if (st->buf != NULL)
574
1.17k
        g_byte_array_unref(st->buf);
575
1.17k
    g_free(st);
576
1.17k
}
577
/**
578
 * fu_struct_tpm_event_log2_hdr_new_internal: (skip):
579
 **/
580
static FuStructTpmEventLog2Hdr *
581
fu_struct_tpm_event_log2_hdr_new_internal(void)
582
1.17k
{
583
1.17k
    FuStructTpmEventLog2Hdr *st = g_new0(FuStructTpmEventLog2Hdr, 1);
584
1.17k
    st->refcount = 1;
585
1.17k
    return st;
586
1.17k
}
587
588
/* getters */
589
/**
590
 * fu_struct_tpm_event_log2_hdr_get_pcr: (skip):
591
 **/
592
static guint32
593
fu_struct_tpm_event_log2_hdr_get_pcr(const FuStructTpmEventLog2Hdr *st)
594
902
{
595
902
    g_return_val_if_fail(st != NULL, 0x0);
596
902
    return fu_memread_uint32(st->buf->data + 0, G_LITTLE_ENDIAN);
597
902
}
598
/**
599
 * fu_struct_tpm_event_log2_hdr_get_type: (skip):
600
 **/
601
static FuTpmEventlogItemKind
602
fu_struct_tpm_event_log2_hdr_get_type(const FuStructTpmEventLog2Hdr *st)
603
1.08k
{
604
1.08k
    g_return_val_if_fail(st != NULL, 0x0);
605
1.08k
    return fu_memread_uint32(st->buf->data + 4, G_LITTLE_ENDIAN);
606
1.08k
}
607
/**
608
 * fu_struct_tpm_event_log2_hdr_get_datasz: (skip):
609
 **/
610
guint32
611
fu_struct_tpm_event_log2_hdr_get_datasz(const FuStructTpmEventLog2Hdr *st)
612
569
{
613
569
    g_return_val_if_fail(st != NULL, 0x0);
614
569
    return fu_memread_uint32(st->buf->data + 28, G_LITTLE_ENDIAN);
615
569
}
616
/**
617
 * fu_struct_tpm_event_log2_hdr_get_data: (skip):
618
 **/
619
static gchar *
620
fu_struct_tpm_event_log2_hdr_get_data(const FuStructTpmEventLog2Hdr *st)
621
129
{
622
129
    g_return_val_if_fail(st != NULL, NULL);
623
129
    return fu_memstrsafe(st->buf->data, st->buf->len, 32, 15, NULL);
624
129
}
625
626
/* setters */
627
/**
628
 * fu_struct_tpm_event_log2_hdr_set_pcr: (skip):
629
 **/
630
static void
631
fu_struct_tpm_event_log2_hdr_set_pcr(FuStructTpmEventLog2Hdr *st, guint32 value)
632
299
{
633
299
    g_return_if_fail(st != NULL);
634
299
    fu_memwrite_uint32(st->buf->data + 0, value, G_LITTLE_ENDIAN);
635
299
}
636
/**
637
 * fu_struct_tpm_event_log2_hdr_set_type: (skip):
638
 **/
639
static void
640
fu_struct_tpm_event_log2_hdr_set_type(FuStructTpmEventLog2Hdr *st, FuTpmEventlogItemKind value)
641
299
{
642
299
    g_return_if_fail(st != NULL);
643
299
    fu_memwrite_uint32(st->buf->data + 4, value, G_LITTLE_ENDIAN);
644
299
}
645
/**
646
 * fu_struct_tpm_event_log2_hdr_set_datasz: (skip):
647
 **/
648
void
649
fu_struct_tpm_event_log2_hdr_set_datasz(FuStructTpmEventLog2Hdr *st, guint32 value)
650
299
{
651
299
    g_return_if_fail(st != NULL);
652
299
    fu_memwrite_uint32(st->buf->data + 28, value, G_LITTLE_ENDIAN);
653
299
}
654
/**
655
 * fu_struct_tpm_event_log2_hdr_set_data: (skip):
656
 **/
657
static gboolean
658
fu_struct_tpm_event_log2_hdr_set_data(FuStructTpmEventLog2Hdr *st, const gchar *value, GError **error)
659
299
{
660
299
    gsize len;
661
299
    g_return_val_if_fail(st != NULL, FALSE);
662
299
    g_return_val_if_fail(error == NULL || *error == NULL, FALSE);
663
299
    if (value == NULL) {
664
0
        memset(st->buf->data + 32, 0x0, 15);
665
0
        return TRUE;
666
0
    }
667
299
    len = strlen(value);
668
299
    if (len > 15) {
669
0
        g_set_error(error,
670
0
                    FWUPD_ERROR,
671
0
                    FWUPD_ERROR_INVALID_DATA,
672
0
                    "string '%s' (0x%x bytes) does not fit in FuStructTpmEventLog2Hdr.data (0x%x bytes)",
673
0
                    value, (guint) len, (guint) 15);
674
0
        return FALSE;
675
0
    }
676
299
    return fu_memcpy_safe(st->buf->data, st->buf->len, 32, (const guint8 *)value, len, 0x0, len, error);
677
299
}
678
/**
679
 * fu_struct_tpm_event_log2_hdr_new: (skip):
680
 **/
681
FuStructTpmEventLog2Hdr *
682
fu_struct_tpm_event_log2_hdr_new(void)
683
299
{
684
299
    FuStructTpmEventLog2Hdr *st = fu_struct_tpm_event_log2_hdr_new_internal();
685
299
    st->buf = g_byte_array_sized_new(47);
686
299
    fu_byte_array_set_size(st->buf, 47, 0x0);
687
299
    fu_struct_tpm_event_log2_hdr_set_pcr(st, 0x0);
688
299
    fu_struct_tpm_event_log2_hdr_set_type(st, FU_TPM_EVENTLOG_ITEM_KIND_NO_ACTION);
689
299
    fu_struct_tpm_event_log2_hdr_set_datasz(st, 15);
690
299
    fu_struct_tpm_event_log2_hdr_set_data(st, "Spec ID Event03", NULL);
691
299
    return st;
692
299
}
693
/**
694
 * fu_struct_tpm_event_log2_hdr_to_string: (skip):
695
 **/
696
static gchar *
697
fu_struct_tpm_event_log2_hdr_to_string(const FuStructTpmEventLog2Hdr *st)
698
0
{
699
0
    g_autoptr(GString) str = g_string_new("FuStructTpmEventLog2Hdr:\n");
700
0
    g_return_val_if_fail(st != NULL, NULL);
701
0
    g_string_append_printf(str, "  pcr: 0x%x\n",
702
0
                           (guint) fu_struct_tpm_event_log2_hdr_get_pcr(st));
703
0
    {
704
0
        const gchar *tmp = fu_tpm_eventlog_item_kind_to_string(fu_struct_tpm_event_log2_hdr_get_type(st));
705
0
        if (tmp != NULL) {
706
0
            g_string_append_printf(str, "  type: 0x%x [%s]\n", (guint) fu_struct_tpm_event_log2_hdr_get_type(st), tmp);
707
0
        } else {
708
0
            g_string_append_printf(str, "  type: 0x%x\n", (guint) fu_struct_tpm_event_log2_hdr_get_type(st));
709
0
        }
710
0
    }
711
0
    g_string_append_printf(str, "  datasz: 0x%x\n",
712
0
                           (guint) fu_struct_tpm_event_log2_hdr_get_datasz(st));
713
0
    {
714
0
        g_autofree gchar *tmp = fu_struct_tpm_event_log2_hdr_get_data(st);
715
0
        if (tmp != NULL)
716
0
            g_string_append_printf(str, "  data: %s\n", tmp);
717
0
    }
718
0
    if (str->len > 0)
719
0
        g_string_set_size(str, str->len - 1);
720
0
    return g_string_free(g_steal_pointer(&str), FALSE);
721
0
}
722
static gboolean
723
fu_struct_tpm_event_log2_hdr_validate_internal(FuStructTpmEventLog2Hdr *st, GError **error)
724
864
{
725
864
    g_return_val_if_fail(st != NULL, FALSE);
726
864
    if (fu_struct_tpm_event_log2_hdr_get_pcr(st) != 0x0) {
727
38
        g_set_error(error,
728
38
                    FWUPD_ERROR,
729
38
                    FWUPD_ERROR_INVALID_DATA,
730
38
                    "constant FuStructTpmEventLog2Hdr.pcr was not valid, "
731
38
                    "expected 0x%x and got 0x%x",
732
38
                    (guint) 0x0,
733
38
                    (guint) fu_struct_tpm_event_log2_hdr_get_pcr(st));
734
38
        return FALSE;
735
38
    }
736
826
    if (fu_struct_tpm_event_log2_hdr_get_type(st) != FU_TPM_EVENTLOG_ITEM_KIND_NO_ACTION) {
737
128
        g_set_error(error,
738
128
                    FWUPD_ERROR,
739
128
                    FWUPD_ERROR_INVALID_DATA,
740
128
                    "constant FuStructTpmEventLog2Hdr.type was not valid, "
741
128
                    "expected 'FU_TPM_EVENTLOG_ITEM_KIND_NO_ACTION' and got 0x%x '%s'",
742
128
                    fu_struct_tpm_event_log2_hdr_get_type(st),
743
128
                    fu_tpm_eventlog_item_kind_to_string(fu_struct_tpm_event_log2_hdr_get_type(st)));
744
128
        return FALSE;
745
128
    }
746
698
    if (strncmp((const gchar *) (st->buf->data + 32), "Spec ID Event03", 15) != 0) {
747
129
        g_autofree gchar *str = fu_struct_tpm_event_log2_hdr_get_data(st);
748
129
        g_set_error(error,
749
129
                    FWUPD_ERROR,
750
129
                    FWUPD_ERROR_INVALID_DATA,
751
129
                    "constant FuStructTpmEventLog2Hdr.data was not valid, "
752
129
                    "expected 'Spec ID Event03' and got '%s'",
753
129
                    str);
754
129
        return FALSE;
755
129
    }
756
569
    return TRUE;
757
698
}
758
static gboolean
759
fu_struct_tpm_event_log2_hdr_parse_internal(FuStructTpmEventLog2Hdr *st, GError **error)
760
864
{
761
864
    if (g_log_get_debug_enabled()) {
762
0
        g_autofree gchar *str = fu_struct_tpm_event_log2_hdr_to_string(st);
763
0
        g_debug("%s", str);
764
0
    }
765
864
    if (!fu_struct_tpm_event_log2_hdr_validate_internal(st, error))
766
295
        return FALSE;
767
569
    return TRUE;
768
864
}
769
/**
770
 * fu_struct_tpm_event_log2_hdr_parse_stream: (skip):
771
 **/
772
FuStructTpmEventLog2Hdr *
773
fu_struct_tpm_event_log2_hdr_parse_stream(FuInputStream *stream, gsize offset, GError **error)
774
880
{
775
880
    g_autoptr(FuStructTpmEventLog2Hdr) st = fu_struct_tpm_event_log2_hdr_new_internal();
776
880
    st->buf = fu_input_stream_read_byte_array(stream, offset, 47, NULL, error);
777
880
    if (st->buf == NULL) {
778
0
        g_prefix_error(error, "FuStructTpmEventLog2Hdr failed read of 0x%x: ", (guint) 47);
779
0
        return NULL;
780
0
    }
781
880
    if (st->buf->len != 47) {
782
16
        g_set_error(error,
783
16
                    FWUPD_ERROR,
784
16
                    FWUPD_ERROR_INVALID_DATA,
785
16
                    "FuStructTpmEventLog2Hdr requested 0x%x and got 0x%x",
786
16
                    (guint) 47,
787
16
                    (guint) st->buf->len);
788
16
        return NULL;
789
16
    }
790
864
    if (!fu_struct_tpm_event_log2_hdr_parse_internal(st, error))
791
295
        return NULL;
792
569
    return g_steal_pointer(&st);
793
864
}
794
/**
795
 * fu_struct_tpm_event_log2_ref: (skip):
796
 **/
797
FuStructTpmEventLog2 *
798
fu_struct_tpm_event_log2_ref(FuStructTpmEventLog2 *st)
799
0
{
800
0
    g_return_val_if_fail(st != NULL, NULL);
801
0
    st->refcount++;
802
0
    return st;
803
0
}
804
/**
805
 * fu_struct_tpm_event_log2_unref: (skip):
806
 **/
807
void
808
fu_struct_tpm_event_log2_unref(FuStructTpmEventLog2 *st)
809
122k
{
810
122k
    g_return_if_fail(st != NULL);
811
122k
    if (st->refcount == 0) {
812
0
        g_critical("FuStructTpmEventLog2 refcount already zero");
813
0
        return;
814
0
    }
815
122k
    if (--st->refcount > 0)
816
0
        return;
817
122k
    if (st->buf != NULL)
818
120k
        g_byte_array_unref(st->buf);
819
122k
    g_free(st);
820
122k
}
821
/**
822
 * fu_struct_tpm_event_log2_new_internal: (skip):
823
 **/
824
static FuStructTpmEventLog2 *
825
fu_struct_tpm_event_log2_new_internal(void)
826
122k
{
827
122k
    FuStructTpmEventLog2 *st = g_new0(FuStructTpmEventLog2, 1);
828
122k
    st->refcount = 1;
829
122k
    return st;
830
122k
}
831
832
/* getters */
833
/**
834
 * fu_struct_tpm_event_log2_get_pcr: (skip):
835
 **/
836
guint32
837
fu_struct_tpm_event_log2_get_pcr(const FuStructTpmEventLog2 *st)
838
119k
{
839
119k
    g_return_val_if_fail(st != NULL, 0x0);
840
119k
    return fu_memread_uint32(st->buf->data + 0, G_LITTLE_ENDIAN);
841
119k
}
842
/**
843
 * fu_struct_tpm_event_log2_get_type: (skip):
844
 **/
845
FuTpmEventlogItemKind
846
fu_struct_tpm_event_log2_get_type(const FuStructTpmEventLog2 *st)
847
119k
{
848
119k
    g_return_val_if_fail(st != NULL, 0x0);
849
119k
    return fu_memread_uint32(st->buf->data + 4, G_LITTLE_ENDIAN);
850
119k
}
851
/**
852
 * fu_struct_tpm_event_log2_get_digest_count: (skip):
853
 **/
854
guint32
855
fu_struct_tpm_event_log2_get_digest_count(const FuStructTpmEventLog2 *st)
856
120k
{
857
120k
    g_return_val_if_fail(st != NULL, 0x0);
858
120k
    return fu_memread_uint32(st->buf->data + 8, G_LITTLE_ENDIAN);
859
120k
}
860
861
/* setters */
862
/**
863
 * fu_struct_tpm_event_log2_set_pcr: (skip):
864
 **/
865
void
866
fu_struct_tpm_event_log2_set_pcr(FuStructTpmEventLog2 *st, guint32 value)
867
2.27k
{
868
2.27k
    g_return_if_fail(st != NULL);
869
2.27k
    fu_memwrite_uint32(st->buf->data + 0, value, G_LITTLE_ENDIAN);
870
2.27k
}
871
/**
872
 * fu_struct_tpm_event_log2_set_type: (skip):
873
 **/
874
void
875
fu_struct_tpm_event_log2_set_type(FuStructTpmEventLog2 *st, FuTpmEventlogItemKind value)
876
2.27k
{
877
2.27k
    g_return_if_fail(st != NULL);
878
2.27k
    fu_memwrite_uint32(st->buf->data + 4, value, G_LITTLE_ENDIAN);
879
2.27k
}
880
/**
881
 * fu_struct_tpm_event_log2_set_digest_count: (skip):
882
 **/
883
void
884
fu_struct_tpm_event_log2_set_digest_count(FuStructTpmEventLog2 *st, guint32 value)
885
2.27k
{
886
2.27k
    g_return_if_fail(st != NULL);
887
2.27k
    fu_memwrite_uint32(st->buf->data + 8, value, G_LITTLE_ENDIAN);
888
2.27k
}
889
/**
890
 * fu_struct_tpm_event_log2_new: (skip):
891
 **/
892
FuStructTpmEventLog2 *
893
fu_struct_tpm_event_log2_new(void)
894
2.27k
{
895
2.27k
    FuStructTpmEventLog2 *st = fu_struct_tpm_event_log2_new_internal();
896
2.27k
    st->buf = g_byte_array_sized_new(12);
897
2.27k
    fu_byte_array_set_size(st->buf, 12, 0x0);
898
2.27k
    return st;
899
2.27k
}
900
/**
901
 * fu_struct_tpm_event_log2_to_string: (skip):
902
 **/
903
static gchar *
904
fu_struct_tpm_event_log2_to_string(const FuStructTpmEventLog2 *st)
905
0
{
906
0
    g_autoptr(GString) str = g_string_new("FuStructTpmEventLog2:\n");
907
0
    g_return_val_if_fail(st != NULL, NULL);
908
0
    g_string_append_printf(str, "  pcr: 0x%x\n",
909
0
                           (guint) fu_struct_tpm_event_log2_get_pcr(st));
910
0
    {
911
0
        const gchar *tmp = fu_tpm_eventlog_item_kind_to_string(fu_struct_tpm_event_log2_get_type(st));
912
0
        if (tmp != NULL) {
913
0
            g_string_append_printf(str, "  type: 0x%x [%s]\n", (guint) fu_struct_tpm_event_log2_get_type(st), tmp);
914
0
        } else {
915
0
            g_string_append_printf(str, "  type: 0x%x\n", (guint) fu_struct_tpm_event_log2_get_type(st));
916
0
        }
917
0
    }
918
0
    g_string_append_printf(str, "  digest_count: 0x%x\n",
919
0
                           (guint) fu_struct_tpm_event_log2_get_digest_count(st));
920
0
    if (str->len > 0)
921
0
        g_string_set_size(str, str->len - 1);
922
0
    return g_string_free(g_steal_pointer(&str), FALSE);
923
0
}
924
static gboolean
925
fu_struct_tpm_event_log2_parse_internal(FuStructTpmEventLog2 *st, GError **error)
926
120k
{
927
120k
    if (g_log_get_debug_enabled()) {
928
0
        g_autofree gchar *str = fu_struct_tpm_event_log2_to_string(st);
929
0
        g_debug("%s", str);
930
0
    }
931
120k
    return TRUE;
932
120k
}
933
/**
934
 * fu_struct_tpm_event_log2_parse_stream: (skip):
935
 **/
936
FuStructTpmEventLog2 *
937
fu_struct_tpm_event_log2_parse_stream(FuInputStream *stream, gsize offset, GError **error)
938
120k
{
939
120k
    g_autoptr(FuStructTpmEventLog2) st = fu_struct_tpm_event_log2_new_internal();
940
120k
    st->buf = fu_input_stream_read_byte_array(stream, offset, 12, NULL, error);
941
120k
    if (st->buf == NULL) {
942
0
        g_prefix_error(error, "FuStructTpmEventLog2 failed read of 0x%x: ", (guint) 12);
943
0
        return NULL;
944
0
    }
945
120k
    if (st->buf->len != 12) {
946
40
        g_set_error(error,
947
40
                    FWUPD_ERROR,
948
40
                    FWUPD_ERROR_INVALID_DATA,
949
40
                    "FuStructTpmEventLog2 requested 0x%x and got 0x%x",
950
40
                    (guint) 12,
951
40
                    (guint) st->buf->len);
952
40
        return NULL;
953
40
    }
954
120k
    if (!fu_struct_tpm_event_log2_parse_internal(st, error))
955
0
        return NULL;
956
120k
    return g_steal_pointer(&st);
957
120k
}