diff options
-rw-r--r-- | docs/gck/pkcs11-links.md | 4 | ||||
-rw-r--r-- | gck/gck-enumerator.c | 2 | ||||
-rw-r--r-- | gck/gck-modules.c | 4 | ||||
-rw-r--r-- | gck/gck-uri.c | 26 | ||||
-rw-r--r-- | gck/gck.h | 4 | ||||
-rw-r--r-- | gck/test-gck-uri.c | 54 | ||||
-rw-r--r-- | gcr/gcr-pkcs11-importer.c | 4 |
7 files changed, 48 insertions, 50 deletions
diff --git a/docs/gck/pkcs11-links.md b/docs/gck/pkcs11-links.md index ad89d6c..ee62924 100644 --- a/docs/gck/pkcs11-links.md +++ b/docs/gck/pkcs11-links.md @@ -17,8 +17,8 @@ A PKCS#11 URI can always resolve to more than one object, token or module. A PKCS#11 URI that refers to a token, would (when used in a context that expects objects) refer to all the token on that module. -To parse a PKCS#11 URI, use the [func@uri_parse] function passing in the type of -context in which you're using the URI. To build a URI, use the [func@uri_build] +To parse a PKCS#11 URI, use the [func@Gck.UriData.parse] function passing in the type of +context in which you're using the URI. To build a URI, use the [method@Gck.UriData.build] function. In most cases, the parsing or building of URIs is already handled for you in the diff --git a/gck/gck-enumerator.c b/gck/gck-enumerator.c index 220c3d4..70b04fe 100644 --- a/gck/gck-enumerator.c +++ b/gck/gck-enumerator.c @@ -680,7 +680,7 @@ created_enumerator (GckUriData *uri_data, { gchar *attrs, *uri; attrs = uri_data->attributes ? gck_attributes_to_string (uri_data->attributes) : NULL; - uri = uri_data ? gck_uri_build (uri_data, GCK_URI_FOR_TOKEN | GCK_URI_FOR_MODULE) : NULL; + uri = uri_data ? gck_uri_data_build (uri_data, GCK_URI_FOR_TOKEN | GCK_URI_FOR_MODULE) : NULL; g_debug ("for = %s, tokens = %s, objects = %s", type, uri, attrs); g_free (attrs); g_free (uri); diff --git a/gck/gck-modules.c b/gck/gck-modules.c index fb9b93e..1512eae 100644 --- a/gck/gck-modules.c +++ b/gck/gck-modules.c @@ -231,7 +231,7 @@ tokens_for_uri (GList *modules, GckUriFlags flags; flags = GCK_URI_FOR_OBJECT_ON_TOKEN_AND_MODULE | GCK_URI_FOR_MODULE_WITH_VERSION; - uri_data = gck_uri_parse (uri, flags, error); + uri_data = gck_uri_data_parse (uri, flags, error); if (uri_data == NULL) return NULL; @@ -418,7 +418,7 @@ gck_modules_enumerate_uri (GList *modules, g_return_val_if_fail (uri != NULL, NULL); - uri_data = gck_uri_parse (uri, GCK_URI_FOR_ANY, error); + uri_data = gck_uri_data_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 e0c3faf..3cc0dc8 100644 --- a/gck/gck-uri.c +++ b/gck/gck-uri.c @@ -132,11 +132,11 @@ gck_uri_error_get_quark (void) GckUriData * gck_uri_data_new (void) { - return g_slice_new0 (GckUriData); + return g_new0 (GckUriData, 1); } /** - * gck_uri_parse: + * gck_uri_data_parse: * @string: the URI to parse. * @flags: the context in which the URI will be used. * @error: a #GError, or %NULL. @@ -151,7 +151,7 @@ gck_uri_data_new (void) * freed with gck_uri_data_free() */ GckUriData* -gck_uri_parse (const gchar *string, GckUriFlags flags, GError **error) +gck_uri_data_parse (const gchar *string, GckUriFlags flags, GError **error) { GckUriData *uri_data = NULL; GckBuilder builder; @@ -217,7 +217,7 @@ gck_uri_parse (const gchar *string, GckUriFlags flags, GError **error) } /** - * gck_uri_build: + * gck_uri_data_build: * @uri_data: the info to build the URI from. * @flags: The context that the URI is for * @@ -227,7 +227,7 @@ gck_uri_parse (const gchar *string, GckUriFlags flags, GError **error) * Return value: a newly allocated string containing a PKCS#11 URI. */ gchar* -gck_uri_build (GckUriData *uri_data, GckUriFlags flags) +gck_uri_data_build (GckUriData *uri_data, GckUriFlags flags) { const GckAttribute *attr; P11KitUri *p11_uri = 0; @@ -298,13 +298,11 @@ gck_uri_data_copy (GckUriData *uri_data) void gck_uri_data_free (GckUriData *uri_data) { - if (uri_data) { - if (uri_data->attributes) - gck_attributes_unref (uri_data->attributes); - if (uri_data->module_info) - gck_module_info_free (uri_data->module_info); - if (uri_data->token_info) - gck_token_info_free (uri_data->token_info); - g_slice_free (GckUriData, uri_data); - } + if (!uri_data) + return; + + g_clear_pointer (&uri_data->attributes, gck_attributes_unref); + g_clear_pointer (&uri_data->module_info, gck_module_info_free); + g_clear_pointer (&uri_data->token_info, gck_token_info_free); + g_free (uri_data); } @@ -1572,10 +1572,10 @@ GQuark gck_uri_error_get_quark (void) G_GNUC_CONST; GckUriData* gck_uri_data_new (void); -gchar* gck_uri_build (GckUriData *uri_data, +gchar* gck_uri_data_build (GckUriData *uri_data, GckUriFlags flags); -GckUriData* gck_uri_parse (const gchar *string, +GckUriData* gck_uri_data_parse (const gchar *string, GckUriFlags flags, GError **error); diff --git a/gck/test-gck-uri.c b/gck/test-gck-uri.c index 57adee9..1254fc9 100644 --- a/gck/test-gck-uri.c +++ b/gck/test-gck-uri.c @@ -37,7 +37,7 @@ test_parse (void) GError *error = NULL; GckUriData *uri_data; - uri_data = gck_uri_parse ("pkcs11:", GCK_URI_FOR_MODULE, &error); + uri_data = gck_uri_data_parse ("pkcs11:", GCK_URI_FOR_MODULE, &error); g_assert_nonnull (uri_data); g_assert_no_error (error); @@ -57,7 +57,7 @@ test_parse_bad_scheme (void) GError *error = NULL; GckUriData *uri_data; - uri_data = gck_uri_parse ("http:\\example.com\test", GCK_URI_FOR_ANY, &error); + uri_data = gck_uri_data_parse ("http:\\example.com\test", GCK_URI_FOR_ANY, &error); g_assert_null (uri_data); g_assert_error (error, GCK_URI_ERROR, GCK_URI_BAD_SCHEME); g_error_free (error); @@ -70,7 +70,7 @@ test_parse_with_label (void) GckUriData *uri_data; gchar *value; - uri_data = gck_uri_parse ("pkcs11:object=Test%20Label", GCK_URI_FOR_ANY, &error); + uri_data = gck_uri_data_parse ("pkcs11:object=Test%20Label", GCK_URI_FOR_ANY, &error); g_assert_nonnull (uri_data); g_assert_nonnull (uri_data->attributes); @@ -91,7 +91,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_FOR_ANY, &error); + uri_data = gck_uri_data_parse ("pkcs11:object=Test%20Label;objecttype=cert", GCK_URI_FOR_ANY, &error); g_assert_nonnull (uri_data); g_assert_nonnull (uri_data->attributes); @@ -115,7 +115,7 @@ test_parse_with_id (void) const GckAttribute *attr; GckUriData *uri_data; - uri_data = gck_uri_parse ("pkcs11:id=%54%45%53%54%00", GCK_URI_FOR_OBJECT, &error); + uri_data = gck_uri_data_parse ("pkcs11:id=%54%45%53%54%00", GCK_URI_FOR_OBJECT, &error); g_assert_nonnull (uri_data); g_assert_nonnull (uri_data->attributes); @@ -133,7 +133,7 @@ test_parse_with_bad_string_encoding (void) GError *error = NULL; GckUriData *uri_data; - uri_data = gck_uri_parse ("pkcs11:object=Test%", GCK_URI_FOR_OBJECT, &error); + uri_data = gck_uri_data_parse ("pkcs11:object=Test%", GCK_URI_FOR_OBJECT, &error); g_assert_null (uri_data); g_assert_error (error, GCK_URI_ERROR, GCK_URI_BAD_ENCODING); g_error_free (error); @@ -144,7 +144,7 @@ test_parse_with_bad_binary_encoding (void) { GError *error = NULL; GckUriData *uri_data; - uri_data = gck_uri_parse ("pkcs11:id=%%", GCK_URI_FOR_ANY, &error); + uri_data = gck_uri_data_parse ("pkcs11:id=%%", GCK_URI_FOR_ANY, &error); g_assert_null (uri_data); g_assert_error (error, GCK_URI_ERROR, GCK_URI_BAD_ENCODING); g_error_free (error); @@ -156,7 +156,7 @@ test_parse_with_token (void) GError *error = NULL; GckUriData *uri_data = NULL; - uri_data = gck_uri_parse ("pkcs11:token=Token%20Label;serial=3333;model=Deluxe;manufacturer=Me", + uri_data = gck_uri_data_parse ("pkcs11:token=Token%20Label;serial=3333;model=Deluxe;manufacturer=Me", GCK_URI_FOR_TOKEN, &error); g_assert_nonnull (uri_data); @@ -174,7 +174,7 @@ test_parse_with_token_bad_encoding (void) GError *error = NULL; GckUriData *uri_data; - uri_data = gck_uri_parse ("pkcs11:token=Token%", GCK_URI_FOR_TOKEN, &error); + uri_data = gck_uri_data_parse ("pkcs11:token=Token%", GCK_URI_FOR_TOKEN, &error); g_assert_null (uri_data); g_assert_error (error, GCK_URI_ERROR, GCK_URI_BAD_ENCODING); g_error_free (error); @@ -186,7 +186,7 @@ test_parse_with_bad_syntax (void) GError *error = NULL; GckUriData *uri_data; - uri_data = gck_uri_parse ("pkcs11:token", GCK_URI_FOR_ANY, &error); + uri_data = gck_uri_data_parse ("pkcs11:token", GCK_URI_FOR_ANY, &error); g_assert_null (uri_data); g_assert_error (error, GCK_URI_ERROR, GCK_URI_BAD_SYNTAX); g_error_free (error); @@ -198,7 +198,7 @@ test_parse_with_library (void) GError *error = NULL; GckUriData *uri_data = NULL; - uri_data = gck_uri_parse ("pkcs11:library-description=The%20Library;library-manufacturer=Me", + uri_data = gck_uri_data_parse ("pkcs11:library-description=The%20Library;library-manufacturer=Me", GCK_URI_FOR_MODULE, &error); g_assert_nonnull (uri_data); @@ -214,7 +214,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_FOR_MODULE, &error); + uri_data = gck_uri_data_parse ("pkcs11:library-description=Library%", GCK_URI_FOR_MODULE, &error); g_assert_null (uri_data); g_assert_error (error, GCK_URI_ERROR, GCK_URI_BAD_ENCODING); g_error_free (error); @@ -227,7 +227,7 @@ test_build_empty (void) gchar *uri; memset (&uri_data, 0, sizeof (uri_data)); - uri = gck_uri_build (&uri_data, 0); + uri = gck_uri_data_build (&uri_data, 0); g_assert_cmpstr (uri, ==, "pkcs11:"); g_free (uri); } @@ -246,10 +246,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_FOR_TOKEN); + uri = gck_uri_data_build (&uri_data, GCK_URI_FOR_TOKEN); g_assert_nonnull (uri); - check = gck_uri_parse (uri, GCK_URI_FOR_TOKEN, NULL); + check = gck_uri_data_parse (uri, GCK_URI_FOR_TOKEN, NULL); g_assert_nonnull (check); g_assert_nonnull (check->token_info); @@ -277,7 +277,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_FOR_TOKEN); + uri = gck_uri_data_build (&uri_data, GCK_URI_FOR_TOKEN); g_assert_nonnull (uri); g_assert_true (g_str_has_prefix (uri, "pkcs11:")); @@ -299,7 +299,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_FOR_TOKEN); + uri = gck_uri_data_build (&uri_data, GCK_URI_FOR_TOKEN); g_assert_nonnull (uri); g_assert_true (g_str_has_prefix (uri, "pkcs11:")); @@ -327,12 +327,12 @@ test_build_with_attributes (void) gck_builder_add_data (&builder, CKA_ID, (const guchar *)"TEST", 5); uri_data.attributes = gck_attributes_ref_sink (gck_builder_end (&builder)); - uri = gck_uri_build (&uri_data, GCK_URI_FOR_OBJECT); + uri = gck_uri_data_build (&uri_data, GCK_URI_FOR_OBJECT); g_assert_nonnull (uri); gck_attributes_unref (uri_data.attributes); - check = gck_uri_parse (uri, GCK_URI_FOR_ANY, NULL); + check = gck_uri_data_parse (uri, GCK_URI_FOR_ANY, NULL); g_assert_nonnull (check); g_assert_nonnull (check->attributes); @@ -366,7 +366,7 @@ test_parse_private_key (void) GError *error = NULL; gulong klass; - uri_data = gck_uri_parse ("pkcs11:objecttype=private", GCK_URI_FOR_OBJECT, &error); + uri_data = gck_uri_data_parse ("pkcs11:objecttype=private", GCK_URI_FOR_OBJECT, &error); g_assert_nonnull (uri_data); g_assert_no_error (error); @@ -385,7 +385,7 @@ test_parse_secret_key (void) GError *error = NULL; gulong klass; - uri_data = gck_uri_parse ("pkcs11:objecttype=secretkey", GCK_URI_FOR_OBJECT, &error); + uri_data = gck_uri_data_parse ("pkcs11:objecttype=secretkey", GCK_URI_FOR_OBJECT, &error); g_assert_nonnull (uri_data); g_assert_no_error (error); @@ -405,7 +405,7 @@ test_parse_unknown_objecttype (void) GError *error = NULL; gulong klass; - uri_data = gck_uri_parse ("pkcs11:objecttype=unknown", GCK_URI_FOR_OBJECT, &error); + uri_data = gck_uri_data_parse ("pkcs11:objecttype=unknown", GCK_URI_FOR_OBJECT, &error); g_assert_nonnull (uri_data); g_assert_no_error (error); @@ -428,7 +428,7 @@ test_build_objecttype_cert (void) gck_builder_add_ulong (&builder, CKA_CLASS, CKO_CERTIFICATE); uri_data->attributes = gck_attributes_ref_sink (gck_builder_end (&builder)); - uri = gck_uri_build (uri_data, GCK_URI_FOR_OBJECT); + uri = gck_uri_data_build (uri_data, GCK_URI_FOR_OBJECT); g_assert_nonnull (uri); g_assert_true (strstr (uri, "object-type=cert") || strstr (uri, "type=cert")); @@ -447,7 +447,7 @@ test_build_objecttype_private (void) gck_builder_add_ulong (&builder, CKA_CLASS, CKO_PRIVATE_KEY); uri_data->attributes = gck_attributes_ref_sink (gck_builder_end (&builder)); - uri = gck_uri_build (uri_data, GCK_URI_FOR_OBJECT); + uri = gck_uri_data_build (uri_data, GCK_URI_FOR_OBJECT); g_assert_nonnull (uri); g_assert_true (strstr (uri, "object-type=private") || strstr (uri, "type=private")); @@ -466,7 +466,7 @@ test_build_objecttype_public (void) gck_builder_add_ulong (&builder, CKA_CLASS, CKO_PUBLIC_KEY); uri_data->attributes = gck_attributes_ref_sink (gck_builder_end (&builder)); - uri = gck_uri_build (uri_data, GCK_URI_FOR_OBJECT); + uri = gck_uri_data_build (uri_data, GCK_URI_FOR_OBJECT); g_assert_nonnull (uri); g_assert_true (strstr (uri, "object-type=public") || strstr (uri, "type=public")); @@ -486,7 +486,7 @@ test_build_objecttype_secret (void) gck_builder_add_ulong (&builder, CKA_CLASS, CKO_SECRET_KEY); uri_data->attributes = gck_attributes_ref_sink (gck_builder_end (&builder)); - uri = gck_uri_build (uri_data, GCK_URI_FOR_OBJECT); + uri = gck_uri_data_build (uri_data, GCK_URI_FOR_OBJECT); g_assert_nonnull (uri); g_assert_true (strstr (uri, "object-type=secret-key") || strstr (uri, "type=secret-key")); @@ -505,7 +505,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_FOR_MODULE); + uri = gck_uri_data_build (uri_data, GCK_URI_FOR_MODULE); g_assert_nonnull (uri); g_assert_true (strstr (uri, "library-description=The%20Description")); diff --git a/gcr/gcr-pkcs11-importer.c b/gcr/gcr-pkcs11-importer.c index b2aa9ae..b686742 100644 --- a/gcr/gcr-pkcs11-importer.c +++ b/gcr/gcr-pkcs11-importer.c @@ -628,7 +628,7 @@ calculate_uri (GcrPkcs11Importer *self) data = gck_uri_data_new (); data->token_info = gck_slot_get_token_info (self->slot); - uri = gck_uri_build (data, GCK_URI_FOR_TOKEN); + uri = gck_uri_data_build (data, GCK_URI_FOR_TOKEN); data->token_info = NULL; gck_uri_data_free (data); @@ -754,7 +754,7 @@ is_slot_importable (GckSlot *slot, } for (i = 0; token_blacklist[i] != NULL; i++) { - uri = gck_uri_parse (token_blacklist[i], GCK_URI_FOR_TOKEN | GCK_URI_FOR_MODULE, &error); + uri = gck_uri_data_parse (token_blacklist[i], GCK_URI_FOR_TOKEN | GCK_URI_FOR_MODULE, &error); if (uri == NULL) { g_warning ("couldn't parse pkcs11 blacklist uri: %s", error->message); g_clear_error (&error); |