trivial: Add fu_byte_array_append_bytes() helper

This commit is contained in:
Richard Hughes 2021-03-10 13:38:06 +00:00
parent 1981c63d58
commit e9664e8448
6 changed files with 28 additions and 14 deletions

View File

@ -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

View File

@ -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,

View File

@ -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;

View File

@ -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 */

View File

@ -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));
}

View File

@ -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)