[gnome-keyring] gck: Update GckUriFlags to match p11-kit



commit e1e311edaa7c153e9d20ef21c6ce4851b9ee2715
Author: Stef Walter <stefw collabora co uk>
Date:   Wed Jul 6 17:52:54 2011 +0200

    gck: Update GckUriFlags to match p11-kit

 gck/gck-modules.c        |    6 +++-
 gck/gck-uri.c            |   21 ++++++++++++------
 gck/gck.h                |   18 ++++++++++++---
 gck/tests/test-gck-uri.c |   52 +++++++++++++++++++++++-----------------------
 4 files changed, 58 insertions(+), 39 deletions(-)
---
diff --git a/gck/gck-modules.c b/gck/gck-modules.c
index cc342e5..4782688 100644
--- a/gck/gck-modules.c
+++ b/gck/gck-modules.c
@@ -145,8 +145,10 @@ gck_modules_token_for_uri (GList *modules, const gchar *uri, GError **error)
 	GList *slots;
 	GList *m, *s;
 	gboolean matched;
+	GckUriFlags flags;
 
-	uri_data = gck_uri_parse (uri, GCK_URI_CONTEXT_TOKEN, error);
+	flags = GCK_URI_FOR_OBJECT_ON_TOKEN_AND_MODULE | GCK_URI_FOR_MODULE_WITH_VERSION;
+	uri_data = gck_uri_parse (uri, flags, error);
 	if (uri_data == NULL)
 		return NULL;
 
@@ -269,7 +271,7 @@ gck_modules_enumerate_uri (GList *modules, const gchar *uri, guint session_optio
 {
 	GckUriData *uri_data;
 
-	uri_data = gck_uri_parse (uri, GCK_URI_CONTEXT_OBJECT, error);
+	uri_data = gck_uri_parse (uri, GCK_URI_FOR_ANY, error);
 	if (uri_data == NULL)
 		return NULL;
 
diff --git a/gck/gck-uri.c b/gck/gck-uri.c
index 12e535b..77fc948 100644
--- a/gck/gck-uri.c
+++ b/gck/gck-uri.c
@@ -90,6 +90,13 @@
 #define URI_PREFIX "pkcs11:"
 #define N_URI_PREFIX 7
 
+struct _GckUri {
+	gboolean any_unrecognized;
+	GckModuleInfo *module_info;
+	GckTokenInfo *token_info;
+	GckAttributes *attributes;
+};
+
 GQuark
 gck_uri_get_error_quark (void)
 {
@@ -181,11 +188,11 @@ gck_uri_parse (const gchar *string, GckUriFlags flags, GError **error)
 
 	/* Convert it to a GckUri */
 	uri_data = gck_uri_data_new ();
-	if ((flags & GCK_URI_CONTEXT_MODULE) == GCK_URI_CONTEXT_MODULE)
+	if (flags & GCK_URI_FOR_MODULE_WITH_VERSION)
 		uri_data->module_info = _gck_module_info_from_pkcs11 (p11_kit_uri_get_module_info (p11_uri));
-	if ((flags & GCK_URI_CONTEXT_TOKEN) == GCK_URI_CONTEXT_TOKEN)
+	if (flags & GCK_URI_FOR_TOKEN)
 		uri_data->token_info = _gck_token_info_from_pkcs11 (p11_kit_uri_get_token_info (p11_uri));
-	if ((flags & GCK_URI_CONTEXT_OBJECT) == GCK_URI_CONTEXT_OBJECT) {
+	if (flags & GCK_URI_FOR_OBJECT) {
 		attrs = p11_kit_uri_get_attributes (p11_uri, &n_attrs);
 		uri_data->attributes = gck_attributes_new ();
 		for (i = 0; i < n_attrs; ++i)
@@ -220,13 +227,13 @@ gck_uri_build (GckUriData *uri_data, GckUriFlags flags)
 
 	p11_uri = p11_kit_uri_new ();
 
-	if ((flags & GCK_URI_CONTEXT_MODULE) == GCK_URI_CONTEXT_MODULE && uri_data->module_info)
+	if ((flags & GCK_URI_FOR_MODULE_WITH_VERSION) && uri_data->module_info)
 		_gck_module_info_to_pkcs11 (uri_data->module_info,
 		                            p11_kit_uri_get_module_info (p11_uri));
-	if ((flags & GCK_URI_CONTEXT_TOKEN) == GCK_URI_CONTEXT_TOKEN && uri_data->token_info)
+	if ((flags & GCK_URI_FOR_TOKEN) && uri_data->token_info)
 		_gck_token_info_to_pkcs11 (uri_data->token_info,
 		                           p11_kit_uri_get_token_info (p11_uri));
-	if ((flags & GCK_URI_CONTEXT_OBJECT) == GCK_URI_CONTEXT_OBJECT && uri_data->attributes) {
+	if ((flags & GCK_URI_FOR_OBJECT) && uri_data->attributes) {
 		for (i = 0; i < gck_attributes_count (uri_data->attributes); ++i) {
 			attr = gck_attributes_at (uri_data->attributes, i);
 			res = p11_kit_uri_set_attribute (p11_uri, (CK_ATTRIBUTE_PTR)attr);
@@ -237,7 +244,7 @@ gck_uri_build (GckUriData *uri_data, GckUriFlags flags)
 		}
 	}
 
-	res = p11_kit_uri_format (p11_uri, flags & GCK_URI_CONTEXT_ANY, &string);
+	res = p11_kit_uri_format (p11_uri, flags & GCK_URI_FOR_ANY, &string);
 	if (res == P11_KIT_URI_NO_MEMORY)
 		g_error ("failed to allocate memory in p11_kit_uri_format()");
 	else if (res != P11_KIT_URI_OK)
diff --git a/gck/gck.h b/gck/gck.h
index 1db67e1..4de88fd 100644
--- a/gck/gck.h
+++ b/gck/gck.h
@@ -1125,10 +1125,20 @@ enum {
 
 /* WARNING: Don't modify these without syncing with p11-kit */
 typedef enum {
-	GCK_URI_CONTEXT_MODULE = (1 << 1),
-	GCK_URI_CONTEXT_TOKEN =   (1 << 2) | GCK_URI_CONTEXT_MODULE,
-	GCK_URI_CONTEXT_OBJECT =  (1 << 3) | GCK_URI_CONTEXT_TOKEN,
-	GCK_URI_CONTEXT_ANY =     0x00000FFF,
+	GCK_URI_FOR_OBJECT =  (1 << 1),
+	GCK_URI_FOR_TOKEN =   (1 << 2),
+	GCK_URI_FOR_MODULE =  (1 << 3),
+
+	GCK_URI_FOR_MODULE_WITH_VERSION =
+		(1 << 4) | GCK_URI_FOR_MODULE,
+
+	GCK_URI_FOR_OBJECT_ON_TOKEN =
+		GCK_URI_FOR_OBJECT | GCK_URI_FOR_TOKEN,
+
+	GCK_URI_FOR_OBJECT_ON_TOKEN_AND_MODULE =
+		GCK_URI_FOR_OBJECT_ON_TOKEN | GCK_URI_FOR_MODULE,
+
+	GCK_URI_FOR_ANY =     0x0000FFFF,
 } GckUriFlags;
 
 typedef struct _GckUriData {
diff --git a/gck/tests/test-gck-uri.c b/gck/tests/test-gck-uri.c
index 732f2da..452e7e7 100644
--- a/gck/tests/test-gck-uri.c
+++ b/gck/tests/test-gck-uri.c
@@ -38,7 +38,7 @@ test_parse (void)
 	GError *error = NULL;
 	GckUriData *uri_data;
 
-	uri_data = gck_uri_parse ("pkcs11:", GCK_URI_CONTEXT_MODULE, &error);
+	uri_data = gck_uri_parse ("pkcs11:", GCK_URI_FOR_MODULE, &error);
 	g_assert (uri_data != NULL);
 	g_assert_no_error (error);
 
@@ -58,7 +58,7 @@ test_parse_bad_scheme (void)
 	GError *error = NULL;
 	GckUriData *uri_data;
 
-	uri_data = gck_uri_parse ("http:\\example.com\test", GCK_URI_CONTEXT_ANY, &error);
+	uri_data = gck_uri_parse ("http:\\example.com\test", GCK_URI_FOR_ANY, &error);
 	g_assert (uri_data == NULL);
 	g_assert_error (error, GCK_URI_ERROR, GCK_URI_BAD_PREFIX);
 	g_error_free (error);
@@ -71,7 +71,7 @@ test_parse_with_label (void)
 	GckUriData *uri_data;
 	gchar *value;
 
-	uri_data = gck_uri_parse ("pkcs11:object=Test%20Label", GCK_URI_CONTEXT_ANY, &error);
+	uri_data = gck_uri_parse ("pkcs11:object=Test%20Label", GCK_URI_FOR_ANY, &error);
 	g_assert (uri_data != NULL);
 	g_assert (uri_data->attributes != NULL);
 
@@ -92,7 +92,7 @@ test_parse_with_label_and_klass (void)
 	gchar *value;
 	gulong klass;
 
-	uri_data = gck_uri_parse ("pkcs11:object=Test%20Label;objecttype=cert", GCK_URI_CONTEXT_ANY, &error);
+	uri_data = gck_uri_parse ("pkcs11:object=Test%20Label;objecttype=cert", GCK_URI_FOR_ANY, &error);
 	g_assert (uri_data);
 	g_assert (uri_data->attributes);
 
@@ -116,7 +116,7 @@ test_parse_with_id (void)
 	GckAttribute *attr;
 	GckUriData *uri_data;
 
-	uri_data = gck_uri_parse ("pkcs11:id=%54%45%53%54%00", GCK_URI_CONTEXT_OBJECT, &error);
+	uri_data = gck_uri_parse ("pkcs11:id=%54%45%53%54%00", GCK_URI_FOR_OBJECT, &error);
 	g_assert (uri_data != NULL);
 	g_assert (uri_data->attributes != NULL);
 
@@ -135,7 +135,7 @@ test_parse_with_bad_string_encoding (void)
 	GError *error = NULL;
 	GckUriData *uri_data;
 
-	uri_data = gck_uri_parse ("pkcs11:object=Test%", GCK_URI_CONTEXT_OBJECT, &error);
+	uri_data = gck_uri_parse ("pkcs11:object=Test%", GCK_URI_FOR_OBJECT, &error);
 	g_assert (uri_data == NULL);
 	g_assert_error (error, GCK_URI_ERROR, GCK_URI_BAD_ENCODING);
 	g_error_free (error);
@@ -146,7 +146,7 @@ test_parse_with_bad_binary_encoding (void)
 {
 	GError *error = NULL;
 	GckUriData *uri_data;
-	uri_data = gck_uri_parse ("pkcs11:id=%%", GCK_URI_CONTEXT_ANY, &error);
+	uri_data = gck_uri_parse ("pkcs11:id=%%", GCK_URI_FOR_ANY, &error);
 	g_assert (!uri_data);
 	g_assert_error (error, GCK_URI_ERROR, GCK_URI_BAD_ENCODING);
 	g_error_free (error);
@@ -159,7 +159,7 @@ test_parse_with_token (void)
 	GckUriData *uri_data = NULL;
 
 	uri_data = gck_uri_parse ("pkcs11:token=Token%20Label;serial=3333;model=Deluxe;manufacturer=Me",
-	                          GCK_URI_CONTEXT_TOKEN, &error);
+	                          GCK_URI_FOR_TOKEN, &error);
 
 	g_assert (uri_data);
 	g_assert (uri_data->token_info);
@@ -176,7 +176,7 @@ test_parse_with_token_bad_encoding (void)
 	GError *error = NULL;
 	GckUriData *uri_data;
 
-	uri_data = gck_uri_parse ("pkcs11:token=Token%", GCK_URI_CONTEXT_TOKEN, &error);
+	uri_data = gck_uri_parse ("pkcs11:token=Token%", GCK_URI_FOR_TOKEN, &error);
 	g_assert (!uri_data);
 	g_assert_error (error, GCK_URI_ERROR, GCK_URI_BAD_ENCODING);
 	g_error_free (error);
@@ -188,7 +188,7 @@ test_parse_with_bad_syntax (void)
 	GError *error = NULL;
 	GckUriData *uri_data;
 
-	uri_data = gck_uri_parse ("pkcs11:token", GCK_URI_CONTEXT_ANY, &error);
+	uri_data = gck_uri_parse ("pkcs11:token", GCK_URI_FOR_ANY, &error);
 	g_assert (uri_data == NULL);
 	g_assert (g_error_matches (error, GCK_URI_ERROR, GCK_URI_BAD_SYNTAX));
 	g_error_free (error);
@@ -201,7 +201,7 @@ test_parse_with_library (void)
 	GckUriData *uri_data = NULL;
 
 	uri_data = gck_uri_parse ("pkcs11:library-description=The%20Library;library-manufacturer=Me",
-	                          GCK_URI_CONTEXT_MODULE, &error);
+	                          GCK_URI_FOR_MODULE, &error);
 
 	g_assert (uri_data);
 	g_assert (uri_data->module_info);
@@ -216,7 +216,7 @@ test_parse_with_library_bad_encoding (void)
 	GError *error = NULL;
 	GckUriData *uri_data;
 
-	uri_data = gck_uri_parse ("pkcs11:library-description=Library%", GCK_URI_CONTEXT_MODULE, &error);
+	uri_data = gck_uri_parse ("pkcs11:library-description=Library%", GCK_URI_FOR_MODULE, &error);
 	g_assert (!uri_data);
 	g_assert_error (error, GCK_URI_ERROR, GCK_URI_BAD_ENCODING);
 	g_error_free (error);
@@ -248,10 +248,10 @@ test_build_with_token_info (void)
 	uri_data.token_info->manufacturer_id = g_strdup ("Me");
 	uri_data.token_info->model = g_strdup ("Deluxe");
 
-	uri = gck_uri_build (&uri_data, GCK_URI_CONTEXT_TOKEN);
+	uri = gck_uri_build (&uri_data, GCK_URI_FOR_TOKEN);
 	g_assert (uri);
 
-	check = gck_uri_parse (uri, GCK_URI_CONTEXT_TOKEN, NULL);
+	check = gck_uri_parse (uri, GCK_URI_FOR_TOKEN, NULL);
 	g_assert (check);
 	g_assert (check->token_info);
 
@@ -279,7 +279,7 @@ test_build_with_token_null_info (void)
 	uri_data.token_info = g_new0 (GckTokenInfo, 1);
 	uri_data.token_info->label = g_strdup ("The Label");
 
-	uri = gck_uri_build (&uri_data, GCK_URI_CONTEXT_TOKEN);
+	uri = gck_uri_build (&uri_data, GCK_URI_FOR_TOKEN);
 	g_assert (uri);
 
 	g_assert (g_str_has_prefix (uri, "pkcs11:"));
@@ -301,7 +301,7 @@ test_build_with_token_empty_info (void)
 	uri_data.token_info->label = g_strdup ("The Label");
 	uri_data.token_info->serial_number = g_strdup ("");
 
-	uri = gck_uri_build (&uri_data, GCK_URI_CONTEXT_TOKEN);
+	uri = gck_uri_build (&uri_data, GCK_URI_FOR_TOKEN);
 	g_assert (uri);
 
 	g_assert (g_str_has_prefix (uri, "pkcs11:"));
@@ -328,12 +328,12 @@ test_build_with_attributes (void)
 	gck_attributes_add_ulong (uri_data.attributes, CKA_CLASS, CKO_DATA);
 	gck_attributes_add_data (uri_data.attributes, CKA_ID, "TEST", 5);
 
-	uri = gck_uri_build (&uri_data, GCK_URI_CONTEXT_OBJECT);
+	uri = gck_uri_build (&uri_data, GCK_URI_FOR_OBJECT);
 	g_assert (uri);
 
 	gck_attributes_unref (uri_data.attributes);
 
-	check = gck_uri_parse (uri, GCK_URI_CONTEXT_ANY, NULL);
+	check = gck_uri_parse (uri, GCK_URI_FOR_ANY, NULL);
 	g_assert (check);
 	g_assert (check->attributes);
 
@@ -367,7 +367,7 @@ test_parse_private_key (void)
 	GError *error = NULL;
 	gulong klass;
 
-	uri_data = gck_uri_parse ("pkcs11:objecttype=private", GCK_URI_CONTEXT_OBJECT, &error);
+	uri_data = gck_uri_parse ("pkcs11:objecttype=private", GCK_URI_FOR_OBJECT, &error);
 	g_assert (uri_data);
 	g_assert_no_error (error);
 
@@ -386,7 +386,7 @@ test_parse_secret_key (void)
 	GError *error = NULL;
 	gulong klass;
 
-	uri_data = gck_uri_parse ("pkcs11:objecttype=secretkey", GCK_URI_CONTEXT_OBJECT, &error);
+	uri_data = gck_uri_parse ("pkcs11:objecttype=secretkey", GCK_URI_FOR_OBJECT, &error);
 	g_assert (uri_data);
 	g_assert_no_error (error);
 
@@ -406,7 +406,7 @@ test_parse_unknown_objecttype (void)
 	GError *error = NULL;
 	gulong klass;
 
-	uri_data = gck_uri_parse ("pkcs11:objecttype=unknown", GCK_URI_CONTEXT_OBJECT, &error);
+	uri_data = gck_uri_parse ("pkcs11:objecttype=unknown", GCK_URI_FOR_OBJECT, &error);
 	g_assert (uri_data);
 	g_assert_no_error (error);
 
@@ -428,7 +428,7 @@ test_build_objecttype_cert (void)
 	uri_data->attributes = gck_attributes_new ();
 	gck_attributes_add_ulong (uri_data->attributes, CKA_CLASS, CKO_CERTIFICATE);
 
-	uri = gck_uri_build (uri_data, GCK_URI_CONTEXT_OBJECT);
+	uri = gck_uri_build (uri_data, GCK_URI_FOR_OBJECT);
 	g_assert (uri);
 	g_assert (strstr (uri, "objecttype=cert"));
 
@@ -446,7 +446,7 @@ test_build_objecttype_private (void)
 	uri_data->attributes = gck_attributes_new ();
 	gck_attributes_add_ulong (uri_data->attributes, CKA_CLASS, CKO_PRIVATE_KEY);
 
-	uri = gck_uri_build (uri_data, GCK_URI_CONTEXT_OBJECT);
+	uri = gck_uri_build (uri_data, GCK_URI_FOR_OBJECT);
 	g_assert (uri);
 	g_assert (strstr (uri, "objecttype=private"));
 
@@ -464,7 +464,7 @@ test_build_objecttype_public (void)
 	uri_data->attributes = gck_attributes_new ();
 	gck_attributes_add_ulong (uri_data->attributes, CKA_CLASS, CKO_PUBLIC_KEY);
 
-	uri = gck_uri_build (uri_data, GCK_URI_CONTEXT_OBJECT);
+	uri = gck_uri_build (uri_data, GCK_URI_FOR_OBJECT);
 	g_assert (uri);
 	g_assert (strstr (uri, "objecttype=public"));
 
@@ -482,7 +482,7 @@ test_build_objecttype_secret (void)
 	uri_data->attributes = gck_attributes_new ();
 	gck_attributes_add_ulong (uri_data->attributes, CKA_CLASS, CKO_SECRET_KEY);
 
-	uri = gck_uri_build (uri_data, GCK_URI_CONTEXT_OBJECT);
+	uri = gck_uri_build (uri_data, GCK_URI_FOR_OBJECT);
 	g_assert (uri);
 	g_assert (strstr (uri, "objecttype=secretkey"));
 
@@ -500,7 +500,7 @@ test_build_with_library (void)
 	uri_data->module_info = g_new0 (GckModuleInfo, 1);
 	uri_data->module_info->library_description = g_strdup ("The Description");
 
-	uri = gck_uri_build (uri_data, GCK_URI_CONTEXT_MODULE);
+	uri = gck_uri_build (uri_data, GCK_URI_FOR_MODULE);
 	g_assert (uri);
 	g_assert (strstr (uri, "library-description=The%20Description"));
 



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]