From 0a20e7d43c43c9d5793f0fdb5bf8422affa5d841 Mon Sep 17 00:00:00 2001 From: Philip Withnall Date: Wed, 7 Jun 2017 15:27:10 +0100 Subject: lib/ref: Add OstreeCollectionRef type for globally unique refs MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This is a type representing the tuple (collection ID, ref name), which is guaranteed to be globally unique. It will be used in upcoming commits. It introduces the concept of a ‘collection’ which is a unique, curated set of refs which lie in the same trust domain (i.e. all signed by the same key and validated by the same developer). Flathub might be a collection, for example; or the set of OS refs coming from a particular OS vendor. It includes a function for validating collection IDs. Signed-off-by: Philip Withnall Closes: #924 Approved by: cgwalters --- src/libostree/ostree-core.c | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) (limited to 'src/libostree/ostree-core.c') diff --git a/src/libostree/ostree-core.c b/src/libostree/ostree-core.c index 32516b7c..c0b7cbe3 100644 --- a/src/libostree/ostree-core.c +++ b/src/libostree/ostree-core.c @@ -210,6 +210,38 @@ ostree_validate_remote_name (const char *remote_name, return TRUE; } +/** + * ostree_validate_collection_id: + * @rev: (nullable): A collection ID + * @error: Error + * + * Check whether the given @collection_id is valid. Return an error if it is + * invalid or %NULL. + * + * Valid collection IDs are reverse DNS names: + * * They are composed of 1 or more elements separated by a period (`.`) character. + * All elements must contain at least one character. + * * Each element must only contain the ASCII characters `[A-Z][a-z][0-9]_` and must not + * begin with a digit. + * * They must contain at least one `.` (period) character (and thus at least two elements). + * * They must not begin with a `.` (period) character. + * * They must not exceed 255 characters in length. + * + * (This makes their format identical to D-Bus interface names, for consistency.) + * + * Returns: %TRUE if @collection_id is a valid collection ID, %FALSE if it is invalid + * or %NULL + */ +gboolean +ostree_validate_collection_id (const char *collection_id, GError **error) +{ + /* Abuse g_dbus_is_interface_name(), since collection IDs have the same format. */ + if (collection_id == NULL || !g_dbus_is_interface_name (collection_id)) + return glnx_throw (error, "Invalid collection ID %s", collection_id); + + return TRUE; +} + GVariant * _ostree_file_header_new (GFileInfo *file_info, GVariant *xattrs) -- cgit v1.2.1