sdcp: use GBytes for sdcp-data instead of GVariant

This commit is contained in:
Joshua Grisham
2025-09-01 01:37:06 +02:00
parent e96f9c3618
commit 74e15c793b
3 changed files with 19 additions and 44 deletions

View File

@@ -24,12 +24,12 @@
typedef struct typedef struct
{ {
GBytes *host_private_key; GBytes *host_private_key;
GBytes *host_public_key; GBytes *host_public_key;
GBytes *host_random; GBytes *host_random;
GBytes *reconnect_random; GBytes *reconnect_random;
GBytes *identify_nonce; GBytes *identify_nonce;
GVariant *data; GBytes *data;
} FpSdcpDevicePrivate; } FpSdcpDevicePrivate;
void fpi_sdcp_device_get_application_secret (FpSdcpDevice *self, void fpi_sdcp_device_get_application_secret (FpSdcpDevice *self,

View File

@@ -89,7 +89,7 @@ fp_sdcp_device_finalize (GObject *object)
g_clear_pointer (&priv->host_random, g_bytes_unref); g_clear_pointer (&priv->host_random, g_bytes_unref);
g_clear_pointer (&priv->reconnect_random, g_bytes_unref); g_clear_pointer (&priv->reconnect_random, g_bytes_unref);
g_clear_pointer (&priv->identify_nonce, g_bytes_unref); g_clear_pointer (&priv->identify_nonce, g_bytes_unref);
g_clear_pointer (&priv->data, g_variant_unref); g_clear_pointer (&priv->data, g_bytes_unref);
G_OBJECT_CLASS (fp_sdcp_device_parent_class)->finalize (object); G_OBJECT_CLASS (fp_sdcp_device_parent_class)->finalize (object);
} }
@@ -106,7 +106,7 @@ fp_sdcp_device_get_property (GObject *object,
switch (prop_id) switch (prop_id)
{ {
case PROP_SDCP_DATA: case PROP_SDCP_DATA:
g_value_set_variant (value, priv->data); g_value_set_boxed (value, priv->data);
break; break;
default: default:
@@ -126,8 +126,8 @@ fp_sdcp_device_set_property (GObject *object,
switch (prop_id) switch (prop_id)
{ {
case PROP_SDCP_DATA: case PROP_SDCP_DATA:
g_clear_pointer (&priv->data, g_variant_unref); g_clear_pointer (&priv->data, g_bytes_unref);
priv->data = g_value_dup_variant (value); priv->data = g_value_dup_boxed (value);
break; break;
default: default:
@@ -159,13 +159,12 @@ fp_sdcp_device_class_init (FpSdcpDeviceClass *klass)
fp_device_class->identify = fp_sdcp_device_identify; fp_device_class->identify = fp_sdcp_device_identify;
properties[PROP_SDCP_DATA] = properties[PROP_SDCP_DATA] =
g_param_spec_variant ("sdcp-data", g_param_spec_boxed ("sdcp-data",
"SDCP Data", "SDCP Data",
"SDCP-related device data that should be persisted and used with the " "SDCP-related device data that should be persisted and used with the "
"device during the current system boot", "device during the current system boot",
G_VARIANT_TYPE_ANY, G_TYPE_BYTES,
NULL, G_PARAM_STATIC_STRINGS | G_PARAM_READWRITE);
G_PARAM_STATIC_STRINGS | G_PARAM_READWRITE);
g_object_class_install_properties (object_class, N_PROPS, properties); g_object_class_install_properties (object_class, N_PROPS, properties);

View File

@@ -151,10 +151,7 @@ void
fpi_sdcp_device_get_application_secret (FpSdcpDevice *self, fpi_sdcp_device_get_application_secret (FpSdcpDevice *self,
GBytes **application_secret) GBytes **application_secret)
{ {
g_autoptr(GVariant) data = NULL; GBytes *data = NULL;
g_autoptr(GVariant) application_secret_var = NULL;
const guint8 *application_secret_data;
gsize application_secret_len = 0;
g_return_if_fail (*application_secret == NULL); g_return_if_fail (*application_secret == NULL);
@@ -163,37 +160,16 @@ fpi_sdcp_device_get_application_secret (FpSdcpDevice *self,
if (!data) if (!data)
return; return;
if (!g_variant_check_format_string (data, "(@ay)", FALSE)) *application_secret = g_steal_pointer (&data);
{
fp_warn ("SDCP data is not in expected format.");
return;
}
g_variant_get (data, "(@ay)", &application_secret_var);
application_secret_data = g_variant_get_fixed_array (application_secret_var,
&application_secret_len,
sizeof (guint8));
*application_secret = g_bytes_new (application_secret_data, application_secret_len);
} }
void void
fpi_sdcp_device_set_application_secret (FpSdcpDevice *self, fpi_sdcp_device_set_application_secret (FpSdcpDevice *self,
GBytes *application_secret) GBytes *application_secret)
{ {
GVariant *application_secret_var;
GVariant *data;
g_return_if_fail (application_secret); g_return_if_fail (application_secret);
application_secret_var = g_variant_new_fixed_array (G_VARIANT_TYPE_BYTE, g_object_set (G_OBJECT (self), "sdcp-data", application_secret, NULL);
g_bytes_get_data (application_secret, NULL),
g_bytes_get_size (application_secret),
sizeof (guint8));
data = g_variant_new ("(@ay)", application_secret_var);
g_object_set (G_OBJECT (self), "sdcp-data", data, NULL);
} }
void void