diff --git a/libfwupdplugin/fu-common.c b/libfwupdplugin/fu-common.c index 03c4c14a1..847f1db92 100644 --- a/libfwupdplugin/fu-common.c +++ b/libfwupdplugin/fu-common.c @@ -2492,6 +2492,23 @@ fu_byte_array_append_uint64 (GByteArray *array, guint64 data, FuEndianType endia g_byte_array_append (array, buf, sizeof(buf)); } +/** + * fu_byte_array_append_bytes: + * @array: A #GByteArray + * @bytes: A #GBytes + * + * Adds the contents of a GBytes to a byte array + * + * Since: 1.5.8 + **/ +void +fu_byte_array_append_bytes (GByteArray *array, GBytes *bytes) +{ + g_byte_array_append (array, + g_bytes_get_data (bytes, NULL), + g_bytes_get_size (bytes)); +} + /** * fu_byte_array_set_size: * @array: a #GByteArray diff --git a/libfwupdplugin/fu-common.h b/libfwupdplugin/fu-common.h index 86ecf9d7d..86c76a119 100644 --- a/libfwupdplugin/fu-common.h +++ b/libfwupdplugin/fu-common.h @@ -272,6 +272,8 @@ void fu_byte_array_append_uint32 (GByteArray *array, void fu_byte_array_append_uint64 (GByteArray *array, guint64 data, FuEndianType endian); +void fu_byte_array_append_bytes (GByteArray *array, + GBytes *bytes); void fu_common_write_uint16 (guint8 *buf, guint16 val_native, diff --git a/libfwupdplugin/fwupdplugin.map b/libfwupdplugin/fwupdplugin.map index 92ef1e2c8..0a0dea8bc 100644 --- a/libfwupdplugin/fwupdplugin.map +++ b/libfwupdplugin/fwupdplugin.map @@ -736,6 +736,7 @@ LIBFWUPDPLUGIN_1.5.8 { global: fu_bluez_device_notify_start; fu_bluez_device_notify_stop; + fu_byte_array_append_bytes; fu_byte_array_append_uint64; fu_common_read_uint64; fu_common_read_uint64_safe; diff --git a/plugins/bcm57xx/fu-bcm57xx-firmware.c b/plugins/bcm57xx/fu-bcm57xx-firmware.c index 9f1264da2..6e66f7a1f 100644 --- a/plugins/bcm57xx/fu-bcm57xx-firmware.c +++ b/plugins/bcm57xx/fu-bcm57xx-firmware.c @@ -396,12 +396,6 @@ fu_bcm57xx_firmware_parse (FuFirmware *firmware, return TRUE; } -static void -_g_byte_array_append_bytes (GByteArray *buf, GBytes *bytes) -{ - g_byte_array_append (buf, g_bytes_get_data (bytes, NULL), g_bytes_get_size (bytes)); -} - static GBytes * _g_bytes_new_sized (gsize sz) { @@ -519,7 +513,7 @@ fu_bcm57xx_firmware_write (FuFirmware *firmware, GError **error) self->model, G_BIG_ENDIAN); blob_info = g_byte_array_free_to_bytes (tmp); } - _g_byte_array_append_bytes (buf, blob_info); + fu_byte_array_append_bytes (buf, blob_info); /* add vpd */ img_vpd = fu_firmware_get_image_by_id (firmware, "vpd", NULL); @@ -530,7 +524,7 @@ fu_bcm57xx_firmware_write (FuFirmware *firmware, GError **error) } else { blob_vpd = _g_bytes_new_sized (BCM_NVRAM_VPD_SZ); } - _g_byte_array_append_bytes (buf, blob_vpd); + fu_byte_array_append_bytes (buf, blob_vpd); /* add info2 */ img_info2 = fu_firmware_get_image_by_id (firmware, "info2", NULL); @@ -541,16 +535,16 @@ fu_bcm57xx_firmware_write (FuFirmware *firmware, GError **error) } else { blob_info2 = _g_bytes_new_sized (BCM_NVRAM_INFO2_SZ); } - _g_byte_array_append_bytes (buf, blob_info2); + fu_byte_array_append_bytes (buf, blob_info2); /* add stage1+2 */ - _g_byte_array_append_bytes (buf, blob_stage1); - _g_byte_array_append_bytes (buf, blob_stage2); + fu_byte_array_append_bytes (buf, blob_stage1); + fu_byte_array_append_bytes (buf, blob_stage2); /* add dictionaries, e.g. APE */ for (guint i = 0; i < blob_dicts->len; i++) { GBytes *blob = g_ptr_array_index (blob_dicts, i); - _g_byte_array_append_bytes (buf, blob); + fu_byte_array_append_bytes (buf, blob); } /* pad until full */ diff --git a/plugins/elantp/fu-elantp-firmware.c b/plugins/elantp/fu-elantp-firmware.c index 1770e57cd..d12c6f5b7 100644 --- a/plugins/elantp/fu-elantp-firmware.c +++ b/plugins/elantp/fu-elantp-firmware.c @@ -168,7 +168,7 @@ fu_elantp_firmware_write (FuFirmware *firmware, GError **error) self->module_id, G_LITTLE_ENDIAN, error)) return NULL; - g_byte_array_append (buf, g_bytes_get_data (blob, NULL), g_bytes_get_size (blob)); + fu_byte_array_append_bytes (buf, blob); g_byte_array_append (buf, elantp_signature, sizeof(elantp_signature)); return g_byte_array_free_to_bytes (g_steal_pointer (&buf)); } diff --git a/plugins/solokey/fu-solokey-device.c b/plugins/solokey/fu-solokey-device.c index 517d1b46d..e36aaa8a4 100644 --- a/plugins/solokey/fu-solokey-device.c +++ b/plugins/solokey/fu-solokey-device.c @@ -411,7 +411,7 @@ fu_solokey_device_verify (FuSolokeyDevice *self, GBytes *fw_sig, GError **error) g_autoptr(GByteArray) sig = g_byte_array_new (); fu_device_set_status (FU_DEVICE (self), FWUPD_STATUS_DEVICE_VERIFY); - g_byte_array_append (sig, g_bytes_get_data (fw_sig, NULL), g_bytes_get_size (fw_sig)); + fu_byte_array_append_bytes (sig, fw_sig); fu_solokey_device_exchange (req, SOLO_BOOTLOADER_DONE, 0x00, sig); res = fu_solokey_device_packet (self, SOLO_BOOTLOADER_HID_CMD_BOOT, req, error); if (res == NULL)