Line | Count | Source (jump to first uncovered line) |
1 | | /* auto-generated, do not modify */ |
2 | | #include "config.h" |
3 | | |
4 | | #include "fu-uswid-struct.h" |
5 | | #include "fu-byte-array.h" |
6 | | #include "fu-mem-private.h" |
7 | | #include "fu-string.h" |
8 | | |
9 | | #ifdef G_LOG_DOMAIN |
10 | | #undef G_LOG_DOMAIN |
11 | | #endif |
12 | 0 | #define G_LOG_DOMAIN "FuStruct" |
13 | | |
14 | | |
15 | | const gchar * |
16 | | fu_uswid_payload_compression_to_string(FuUswidPayloadCompression val) |
17 | 0 | { |
18 | 0 | if (val == FU_USWID_PAYLOAD_COMPRESSION_NONE) |
19 | 0 | return "none"; |
20 | 0 | if (val == FU_USWID_PAYLOAD_COMPRESSION_ZLIB) |
21 | 0 | return "zlib"; |
22 | 0 | if (val == FU_USWID_PAYLOAD_COMPRESSION_LZMA) |
23 | 0 | return "lzma"; |
24 | 0 | return NULL; |
25 | 0 | } |
26 | | FuUswidPayloadCompression |
27 | | fu_uswid_payload_compression_from_string(const gchar *val) |
28 | 0 | { |
29 | 0 | if (g_strcmp0(val, "none") == 0) |
30 | 0 | return FU_USWID_PAYLOAD_COMPRESSION_NONE; |
31 | 0 | if (g_strcmp0(val, "zlib") == 0) |
32 | 0 | return FU_USWID_PAYLOAD_COMPRESSION_ZLIB; |
33 | 0 | if (g_strcmp0(val, "lzma") == 0) |
34 | 0 | return FU_USWID_PAYLOAD_COMPRESSION_LZMA; |
35 | 0 | return FU_USWID_PAYLOAD_COMPRESSION_NONE; |
36 | 0 | } |
37 | | /* getters */ |
38 | | /** |
39 | | * fu_struct_uswid_get_magic: (skip): |
40 | | **/ |
41 | | static const fwupd_guid_t * |
42 | | fu_struct_uswid_get_magic(const FuStructUswid *st) |
43 | 0 | { |
44 | 0 | g_return_val_if_fail(st != NULL, NULL); |
45 | 0 | return (const fwupd_guid_t *) (st->data + 0); |
46 | 0 | } |
47 | | /** |
48 | | * fu_struct_uswid_get_hdrver: (skip): |
49 | | **/ |
50 | | guint8 |
51 | | fu_struct_uswid_get_hdrver(const FuStructUswid *st) |
52 | 0 | { |
53 | 0 | g_return_val_if_fail(st != NULL, 0x0); |
54 | 0 | return st->data[16]; |
55 | 0 | } |
56 | | /** |
57 | | * fu_struct_uswid_get_hdrsz: (skip): |
58 | | **/ |
59 | | guint16 |
60 | | fu_struct_uswid_get_hdrsz(const FuStructUswid *st) |
61 | 0 | { |
62 | 0 | g_return_val_if_fail(st != NULL, 0x0); |
63 | 0 | return fu_memread_uint16(st->data + 17, G_LITTLE_ENDIAN); |
64 | 0 | } |
65 | | /** |
66 | | * fu_struct_uswid_get_payloadsz: (skip): |
67 | | **/ |
68 | | guint32 |
69 | | fu_struct_uswid_get_payloadsz(const FuStructUswid *st) |
70 | 0 | { |
71 | 0 | g_return_val_if_fail(st != NULL, 0x0); |
72 | 0 | return fu_memread_uint32(st->data + 19, G_LITTLE_ENDIAN); |
73 | 0 | } |
74 | | /** |
75 | | * fu_struct_uswid_get_flags: (skip): |
76 | | **/ |
77 | | guint8 |
78 | | fu_struct_uswid_get_flags(const FuStructUswid *st) |
79 | 0 | { |
80 | 0 | g_return_val_if_fail(st != NULL, 0x0); |
81 | 0 | return st->data[23]; |
82 | 0 | } |
83 | | /** |
84 | | * fu_struct_uswid_get_compression: (skip): |
85 | | **/ |
86 | | guint8 |
87 | | fu_struct_uswid_get_compression(const FuStructUswid *st) |
88 | 0 | { |
89 | 0 | g_return_val_if_fail(st != NULL, 0x0); |
90 | 0 | return st->data[24]; |
91 | 0 | } |
92 | | |
93 | | /* setters */ |
94 | | /** |
95 | | * fu_struct_uswid_set_magic: (skip): |
96 | | **/ |
97 | | static void |
98 | | fu_struct_uswid_set_magic(FuStructUswid *st, const fwupd_guid_t *value) |
99 | 0 | { |
100 | 0 | g_return_if_fail(st != NULL); |
101 | 0 | g_return_if_fail(value != NULL); |
102 | 0 | memcpy(st->data + 0, value, sizeof(*value)); /* nocheck:blocked */ |
103 | 0 | } |
104 | | /** |
105 | | * fu_struct_uswid_set_hdrver: (skip): |
106 | | **/ |
107 | | void |
108 | | fu_struct_uswid_set_hdrver(FuStructUswid *st, guint8 value) |
109 | 0 | { |
110 | 0 | g_return_if_fail(st != NULL); |
111 | 0 | st->data[16] = value; |
112 | 0 | } |
113 | | /** |
114 | | * fu_struct_uswid_set_hdrsz: (skip): |
115 | | **/ |
116 | | void |
117 | | fu_struct_uswid_set_hdrsz(FuStructUswid *st, guint16 value) |
118 | 0 | { |
119 | 0 | g_return_if_fail(st != NULL); |
120 | 0 | fu_memwrite_uint16(st->data + 17, value, G_LITTLE_ENDIAN); |
121 | 0 | } |
122 | | /** |
123 | | * fu_struct_uswid_set_payloadsz: (skip): |
124 | | **/ |
125 | | void |
126 | | fu_struct_uswid_set_payloadsz(FuStructUswid *st, guint32 value) |
127 | 0 | { |
128 | 0 | g_return_if_fail(st != NULL); |
129 | 0 | fu_memwrite_uint32(st->data + 19, value, G_LITTLE_ENDIAN); |
130 | 0 | } |
131 | | /** |
132 | | * fu_struct_uswid_set_flags: (skip): |
133 | | **/ |
134 | | void |
135 | | fu_struct_uswid_set_flags(FuStructUswid *st, guint8 value) |
136 | 0 | { |
137 | 0 | g_return_if_fail(st != NULL); |
138 | 0 | st->data[23] = value; |
139 | 0 | } |
140 | | /** |
141 | | * fu_struct_uswid_set_compression: (skip): |
142 | | **/ |
143 | | void |
144 | | fu_struct_uswid_set_compression(FuStructUswid *st, guint8 value) |
145 | 0 | { |
146 | 0 | g_return_if_fail(st != NULL); |
147 | 0 | st->data[24] = value; |
148 | 0 | } |
149 | | /** |
150 | | * fu_struct_uswid_new: (skip): |
151 | | **/ |
152 | | FuStructUswid * |
153 | | fu_struct_uswid_new(void) |
154 | 0 | { |
155 | 0 | FuStructUswid *st = g_byte_array_sized_new(25); |
156 | 0 | fu_byte_array_set_size(st, 25, 0x0); |
157 | 0 | fu_struct_uswid_set_magic(st, (fwupd_guid_t *) "\x53\x42\x4f\x4d\xd6\xba\x2e\xac\xa3\xe6\x7a\x52\xaa\xee\x3b\xaf"); |
158 | 0 | fu_struct_uswid_set_hdrsz(st, 25); |
159 | 0 | return st; |
160 | 0 | } |
161 | | /** |
162 | | * fu_struct_uswid_to_string: (skip): |
163 | | **/ |
164 | | static gchar * |
165 | | fu_struct_uswid_to_string(const FuStructUswid *st) |
166 | 0 | { |
167 | 0 | g_autoptr(GString) str = g_string_new("FuStructUswid:\n"); |
168 | 0 | g_return_val_if_fail(st != NULL, NULL); |
169 | 0 | g_string_append_printf(str, " hdrver: 0x%x\n", |
170 | 0 | (guint) fu_struct_uswid_get_hdrver(st)); |
171 | 0 | g_string_append_printf(str, " hdrsz: 0x%x\n", |
172 | 0 | (guint) fu_struct_uswid_get_hdrsz(st)); |
173 | 0 | g_string_append_printf(str, " payloadsz: 0x%x\n", |
174 | 0 | (guint) fu_struct_uswid_get_payloadsz(st)); |
175 | 0 | g_string_append_printf(str, " flags: 0x%x\n", |
176 | 0 | (guint) fu_struct_uswid_get_flags(st)); |
177 | 0 | g_string_append_printf(str, " compression: 0x%x\n", |
178 | 0 | (guint) fu_struct_uswid_get_compression(st)); |
179 | 0 | if (str->len > 0) |
180 | 0 | g_string_set_size(str, str->len - 1); |
181 | 0 | return g_string_free(g_steal_pointer(&str), FALSE); |
182 | 0 | } |
183 | | static gboolean |
184 | | fu_struct_uswid_validate_internal(FuStructUswid *st, GError **error) |
185 | 0 | { |
186 | 0 | g_return_val_if_fail(st != NULL, FALSE); |
187 | 0 | if (memcmp(fu_struct_uswid_get_magic(st), "\x53\x42\x4f\x4d\xd6\xba\x2e\xac\xa3\xe6\x7a\x52\xaa\xee\x3b\xaf", 16) != 0) { |
188 | 0 | g_set_error_literal(error, |
189 | 0 | FWUPD_ERROR, |
190 | 0 | FWUPD_ERROR_INVALID_DATA, |
191 | 0 | "constant FuStructUswid.magic was not valid"); |
192 | 0 | return FALSE; |
193 | 0 | } |
194 | 0 | return TRUE; |
195 | 0 | } |
196 | | /** |
197 | | * fu_struct_uswid_validate_stream: (skip): |
198 | | **/ |
199 | | gboolean |
200 | | fu_struct_uswid_validate_stream(GInputStream *stream, gsize offset, GError **error) |
201 | 0 | { |
202 | 0 | g_autoptr(GByteArray) st = NULL; |
203 | 0 | g_return_val_if_fail(G_IS_INPUT_STREAM(stream), FALSE); |
204 | 0 | g_return_val_if_fail(error == NULL || *error == NULL, FALSE); |
205 | 0 | st = fu_input_stream_read_byte_array(stream, offset, 25, NULL, error); |
206 | 0 | if (st == NULL) { |
207 | 0 | g_prefix_error(error, "FuStructUswid failed read of 0x%x: ", (guint) 25); |
208 | 0 | return FALSE; |
209 | 0 | } |
210 | 0 | if (st->len != 25) { |
211 | 0 | g_set_error(error, |
212 | 0 | FWUPD_ERROR, |
213 | 0 | FWUPD_ERROR_INVALID_DATA, |
214 | 0 | "FuStructUswid requested 0x%x and got 0x%x", |
215 | 0 | (guint) 25, |
216 | 0 | (guint) st->len); |
217 | 0 | return FALSE; |
218 | 0 | } |
219 | 0 | return fu_struct_uswid_validate_internal(st, error); |
220 | 0 | } |
221 | | static gboolean |
222 | | fu_struct_uswid_parse_internal(FuStructUswid *st, GError **error) |
223 | 0 | { |
224 | 0 | if (!fu_struct_uswid_validate_internal(st, error)) |
225 | 0 | return FALSE; |
226 | 0 | if (g_getenv("FWUPD_VERBOSE") != NULL) { |
227 | 0 | g_autofree gchar *str = fu_struct_uswid_to_string(st); |
228 | 0 | g_debug("%s", str); |
229 | 0 | } |
230 | 0 | return TRUE; |
231 | 0 | } |
232 | | /** |
233 | | * fu_struct_uswid_parse_stream: (skip): |
234 | | **/ |
235 | | FuStructUswid * |
236 | | fu_struct_uswid_parse_stream(GInputStream *stream, gsize offset, GError **error) |
237 | 0 | { |
238 | 0 | g_autoptr(GByteArray) st = NULL; |
239 | 0 | st = fu_input_stream_read_byte_array(stream, offset, 25, NULL, error); |
240 | 0 | if (st == NULL) { |
241 | 0 | g_prefix_error(error, "FuStructUswid failed read of 0x%x: ", (guint) 25); |
242 | 0 | return NULL; |
243 | 0 | } |
244 | 0 | if (st->len != 25) { |
245 | 0 | g_set_error(error, |
246 | 0 | FWUPD_ERROR, |
247 | 0 | FWUPD_ERROR_INVALID_DATA, |
248 | 0 | "FuStructUswid requested 0x%x and got 0x%x", |
249 | 0 | (guint) 25, |
250 | 0 | (guint) st->len); |
251 | 0 | return NULL; |
252 | 0 | } |
253 | 0 | if (!fu_struct_uswid_parse_internal(st, error)) |
254 | 0 | return NULL; |
255 | 0 | return g_steal_pointer(&st); |
256 | 0 | } |