blob: 8d760ae22883a7f44f50245d550f669e86c0b901 [file] [log] [blame]
Richard Hughes02c90d82018-08-09 12:13:03 +01001/*
Richard Hughes5c9b1fc2021-01-07 14:20:49 +00002 * Copyright (C) 2017 Richard Hughes <richard@hughsie.com>
Richard Hughes7383ce22018-05-08 14:14:35 +01003 *
Mario Limonciello51308e62018-05-28 20:05:46 -05004 * SPDX-License-Identifier: LGPL-2.1+
Richard Hughes7383ce22018-05-08 14:14:35 +01005 */
6
Richard Hughesaeb59af2020-03-31 12:13:51 +01007#define G_LOG_DOMAIN "FuKeyring"
8
Richard Hughes7383ce22018-05-08 14:14:35 +01009#include <config.h>
Richard Hughesa14de302020-12-14 11:38:18 +000010#include <string.h>
Richard Hughes7383ce22018-05-08 14:14:35 +010011
12#include "fwupd-error.h"
13
14#include "fu-keyring-utils.h"
15
Richard Hughes7383ce22018-05-08 14:14:35 +010016/**
Richard Hughes245885c2019-03-04 08:46:02 +000017 * fu_keyring_get_release_flags:
Richard Hughes481aa2a2018-09-18 20:51:46 +010018 * @release: A #XbNode, e.g. %FWUPD_KEYRING_KIND_GPG
Richard Hughes245885c2019-03-04 08:46:02 +000019 * @flags: A #FwupdReleaseFlags, e.g. %FWUPD_RELEASE_FLAG_TRUSTED_PAYLOAD
Richard Hughes7383ce22018-05-08 14:14:35 +010020 * @error: A #GError, or %NULL
21 *
22 * Uses the correct keyring to get the trust flags for a given release.
23 *
Richard Hughes245885c2019-03-04 08:46:02 +000024 * Returns: %TRUE if @flags has been set
Richard Hughes7383ce22018-05-08 14:14:35 +010025 **/
26gboolean
Richard Hughes245885c2019-03-04 08:46:02 +000027fu_keyring_get_release_flags (XbNode *release,
28 FwupdReleaseFlags *flags,
29 GError **error)
Richard Hughes7383ce22018-05-08 14:14:35 +010030{
Richard Hughesd5aab652020-02-25 12:47:50 +000031 GBytes *blob;
Richard Hughes7383ce22018-05-08 14:14:35 +010032
Richard Hughesd5aab652020-02-25 12:47:50 +000033 blob = g_object_get_data (G_OBJECT (release), "fwupd::ReleaseFlags");
Richard Hughes61a2dba2020-10-01 13:41:24 +010034 if (blob == NULL)
Richard Hughes7383ce22018-05-08 14:14:35 +010035 return TRUE;
Richard Hughesd5aab652020-02-25 12:47:50 +000036 if (g_bytes_get_size (blob) != sizeof(FwupdReleaseFlags)) {
Richard Hughesd5aab652020-02-25 12:47:50 +000037 g_set_error_literal (error,
38 FWUPD_ERROR,
39 FWUPD_ERROR_INVALID_FILE,
40 "invalid fwupd::ReleaseFlags set by loader");
41 return FALSE;
Richard Hughes7383ce22018-05-08 14:14:35 +010042 }
Richard Hughesd5aab652020-02-25 12:47:50 +000043 memcpy (flags, g_bytes_get_data (blob, NULL), sizeof(FwupdReleaseFlags));
Richard Hughes7383ce22018-05-08 14:14:35 +010044 return TRUE;
45}