static gboolean download_archive (SoupURI *uri, const gchar *sha, GFile *archive_file, GError **error) { g_autoptr(GBytes) content = NULL; g_autofree gchar *sha256 = NULL; content = download_uri (uri, error); if (content == NULL) return FALSE; sha256 = g_compute_checksum_for_bytes (G_CHECKSUM_SHA256, content); if (g_strcmp0 (sha256, sha) != 0) { g_autofree gchar *path = g_file_get_path (archive_file); g_set_error (error, G_IO_ERROR, G_IO_ERROR_FAILED, "Wrong sha256 for %s, expected %s, was %s", path, sha, sha256); return FALSE; } return g_file_replace_contents (archive_file, g_bytes_get_data (content, NULL), g_bytes_get_size (content), NULL, FALSE, G_FILE_CREATE_NONE, NULL, NULL, error); }
static gboolean as_store_cab_verify_checksum_cab (AsRelease *release, GBytes *bytes, GError **error) { AsChecksum *csum_tmp; g_autofree gchar *actual = NULL; /* nothing already set, so just add */ actual = g_compute_checksum_for_bytes (G_CHECKSUM_SHA1, bytes); csum_tmp = as_release_get_checksum_by_target (release, AS_CHECKSUM_TARGET_CONTAINER); if (as_checksum_get_value (csum_tmp) == NULL) { as_checksum_set_kind (csum_tmp, G_CHECKSUM_SHA1); as_checksum_set_value (csum_tmp, actual); return TRUE; } /* check it matches */ if (g_strcmp0 (actual, as_checksum_get_value (csum_tmp)) != 0) { g_set_error (error, AS_STORE_ERROR, AS_STORE_ERROR_FAILED, "container checksum invalid, expected %s, got %s", as_checksum_get_value (csum_tmp), actual); return FALSE; } /* success */ return TRUE; }