int p11_match_uri_module_info (CK_INFO_PTR one,
CK_INFO_PTR two);
+int p11_match_uri_slot_info (CK_SLOT_INFO_PTR one,
+ CK_SLOT_INFO_PTR two);
+
int p11_match_uri_token_info (CK_TOKEN_INFO_PTR one,
CK_TOKEN_INFO_PTR two);
info->libraryVersion.minor == (CK_BYTE)-1);
}
+static int
+is_slot_empty (P11KitUri *uri)
+{
+ CK_SLOT_INFO_PTR slot = p11_kit_uri_get_slot_info (uri);
+ return (slot->slotDescription[0] == 0 &&
+ slot->manufacturerID[0] == 0);
+}
+
static int
is_token_empty (P11KitUri *uri)
{
assert_num_eq (P11_KIT_URI_OK, ret);
assert (is_module_empty (uri));
+ assert (is_slot_empty (uri));
assert (is_token_empty (uri));
assert (are_attributes_empty (uri));
assert_num_eq (P11_KIT_URI_OK, ret);
assert (is_module_empty (uri));
+ assert (is_slot_empty (uri));
assert (is_token_empty (uri));
attr = p11_kit_uri_get_attribute (uri, CKA_LABEL);
p11_kit_uri_free (uri);
}
+static void
+test_uri_parse_with_slot (void)
+{
+ P11KitUri *uri = NULL;
+ CK_SLOT_INFO_PTR slot;
+ int ret;
+
+ uri = p11_kit_uri_new ();
+ assert_ptr_not_null (uri);
+
+ ret = p11_kit_uri_parse ("pkcs11:slot-description=Slot%20Description;slot-manufacturer=Me",
+ P11_KIT_URI_FOR_SLOT, uri);
+ assert_num_eq (P11_KIT_URI_OK, ret);
+
+ slot = p11_kit_uri_get_slot_info (uri);
+ assert (is_space_string (slot->slotDescription, sizeof (slot->slotDescription), "Slot Description"));
+ assert (is_space_string (slot->manufacturerID, sizeof (slot->manufacturerID), "Me"));
+
+ p11_kit_uri_free (uri);
+}
+
static void
test_uri_build_empty (void)
{
p11_kit_uri_free (uri);
}
+static void
+test_uri_build_with_slot_info (void)
+{
+ char *string = NULL;
+ P11KitUri *uri;
+ P11KitUri *check;
+ CK_SLOT_INFO_PTR slot;
+ int ret;
+
+ uri = p11_kit_uri_new ();
+ assert_ptr_not_null (uri);
+
+ slot = p11_kit_uri_get_slot_info (uri);
+ set_space_string (slot->slotDescription, sizeof (slot->slotDescription), "The Slot Description");
+ set_space_string (slot->manufacturerID, sizeof (slot->manufacturerID), "Me");
+
+ ret = p11_kit_uri_format (uri, P11_KIT_URI_FOR_ANY, &string);
+ assert_num_eq (P11_KIT_URI_OK, ret);
+ assert_ptr_not_null (string);
+
+ check = p11_kit_uri_new ();
+ assert_ptr_not_null (check);
+
+ ret = p11_kit_uri_parse (string, P11_KIT_URI_FOR_SLOT, check);
+ assert_num_eq (P11_KIT_URI_OK, ret);
+
+ p11_kit_uri_match_slot_info (check, p11_kit_uri_get_slot_info (uri));
+
+ p11_kit_uri_free (uri);
+ p11_kit_uri_free (check);
+
+ assert (strstr (string, "slot-description=The%20Slot%20Description") != NULL);
+ assert (strstr (string, "slot-manufacturer=Me") != NULL);
+
+ free (string);
+}
+
static void
test_uri_parse_private_key (void)
{
p11_test (test_uri_parse_with_spaces, "/uri/test_uri_parse_with_spaces");
p11_test (test_uri_parse_with_library, "/uri/test_uri_parse_with_library");
p11_test (test_uri_parse_with_library_bad_encoding, "/uri/test_uri_parse_with_library_bad_encoding");
+ p11_test (test_uri_parse_with_slot, "/uri/test_uri_parse_with_slot");
p11_test (test_uri_build_empty, "/uri/test_uri_build_empty");
p11_test (test_uri_build_with_token_info, "/uri/test_uri_build_with_token_info");
p11_test (test_uri_build_with_token_null_info, "/uri/test_uri_build_with_token_null_info");
p11_test (test_uri_build_with_token_empty_info, "/uri/test_uri_build_with_token_empty_info");
p11_test (test_uri_build_with_attributes, "/uri/test_uri_build_with_attributes");
+ p11_test (test_uri_build_with_slot_info, "/uri/test_uri_build_with_slot_info");
p11_test (test_uri_parse_private_key, "/uri/test_uri_parse_private_key");
p11_test (test_uri_parse_secret_key, "/uri/test_uri_parse_secret_key");
p11_test (test_uri_parse_library_version, "/uri/test_uri_parse_library_version");
* P11KitUriType:
* @P11_KIT_URI_FOR_OBJECT: The URI represents one or more objects
* @P11_KIT_URI_FOR_TOKEN: The URI represents one or more tokens
+ * @P11_KIT_URI_FOR_SLOT: The URI represents one or more slots
* @P11_KIT_URI_FOR_MODULE: The URI represents one or more modules
* @P11_KIT_URI_FOR_MODULE_WITH_VERSION: The URI represents a module with
* a specific version.
struct p11_kit_uri {
bool unrecognized;
CK_INFO module;
+ CK_SLOT_INFO slot;
CK_TOKEN_INFO token;
CK_ATTRIBUTE *attrs;
char *pin_source;
return p11_match_uri_module_info (&uri->module, info);
}
+/**
+ * p11_kit_uri_get_slot_info:
+ * @uri: the URI
+ *
+ * Get the <code>CK_SLOT_INFO</code> structure associated with this URI.
+ *
+ * If this is a parsed URI, then the fields corresponding to slot parts of
+ * the URI will be filled in. Any slot URI parts that were missing will have
+ * their fields filled with zeros.
+ *
+ * If the caller wishes to setup information for building a URI, then relevant
+ * fields should be filled in. Fields that should not appear as parts in the
+ * resulting URI should be filled with zeros.
+ *
+ * Returns: A pointer to the <code>CK_INFO</code> structure.
+ */
+CK_SLOT_INFO_PTR
+p11_kit_uri_get_slot_info (P11KitUri *uri)
+{
+ return_val_if_fail (uri != NULL, NULL);
+ return &uri->slot;
+}
+
+int
+p11_match_uri_slot_info (CK_SLOT_INFO_PTR one,
+ CK_SLOT_INFO_PTR two)
+{
+ return (match_struct_string (one->slotDescription,
+ two->slotDescription,
+ sizeof (one->slotDescription)) &&
+ match_struct_string (one->manufacturerID,
+ two->manufacturerID,
+ sizeof (one->manufacturerID)));
+}
+
+/**
+ * p11_kit_uri_match_slot_info:
+ * @uri: the URI
+ * @slot_info: the structure to match against the URI
+ *
+ * Match a <code>CK_SLOT_INFO</code> structure against the slot parts of this
+ * URI.
+ *
+ * Only the fields of the <code>CK_SLOT_INFO</code> structure that are valid
+ * for use in a URI will be matched. A URI part that was not specified in the
+ * URI will match any value in the structure. If during the URI parsing any
+ * unrecognized parts were encountered then this match will fail.
+ *
+ * Returns: 1 if the URI matches, 0 if not.
+ */
+int
+p11_kit_uri_match_slot_info (P11KitUri *uri, CK_SLOT_INFO_PTR slot_info)
+{
+ return_val_if_fail (uri != NULL, 0);
+ return_val_if_fail (slot_info != NULL, 0);
+
+ if (uri->unrecognized)
+ return 0;
+
+ return p11_match_uri_slot_info (&uri->slot, slot_info);
+}
+
/**
* p11_kit_uri_get_token_info:
* @uri: the URI
}
}
+ if ((uri_type & P11_KIT_URI_FOR_SLOT) == P11_KIT_URI_FOR_SLOT) {
+ if (!format_struct_string (&buffer, &is_first, "slot-description",
+ uri->slot.slotDescription,
+ sizeof (uri->slot.slotDescription)) ||
+ !format_struct_string (&buffer, &is_first, "slot-manufacturer",
+ uri->slot.manufacturerID,
+ sizeof (uri->slot.manufacturerID))) {
+ return_val_if_reached (P11_KIT_URI_UNEXPECTED);
+ }
+ }
+
if ((uri_type & P11_KIT_URI_FOR_TOKEN) == P11_KIT_URI_FOR_TOKEN) {
if (!format_struct_string (&buffer, &is_first, "model",
uri->token.model,
return 1;
}
+static int
+parse_slot_info (const char *name_start, const char *name_end,
+ const char *start, const char *end,
+ P11KitUri *uri)
+{
+ unsigned char *where;
+ size_t length;
+
+ assert (name_start <= name_end);
+ assert (start <= end);
+
+ if (memcmp ("slot-description", name_start, name_end - name_start) == 0) {
+ where = uri->slot.slotDescription;
+ length = sizeof (uri->slot.slotDescription);
+ } else if (memcmp ("slot-manufacturer", name_start, name_end - name_start) == 0) {
+ where = uri->slot.manufacturerID;
+ length = sizeof (uri->slot.manufacturerID);
+ } else {
+ return 0;
+ }
+
+ return parse_struct_info (where, length, start, end, uri);
+}
+
static int
parse_module_version_info (const char *name_start, const char *name_end,
const char *start, const char *end,
ret = parse_class_attribute (string, epos, epos + 1, spos, uri);
if (ret == 0 && (uri_type & P11_KIT_URI_FOR_TOKEN) == P11_KIT_URI_FOR_TOKEN)
ret = parse_token_info (string, epos, epos + 1, spos, uri);
+ if (ret == 0 && (uri_type & P11_KIT_URI_FOR_SLOT) == P11_KIT_URI_FOR_SLOT)
+ ret = parse_slot_info (string, epos, epos + 1, spos, uri);
if (ret == 0 && (uri_type & P11_KIT_URI_FOR_MODULE) == P11_KIT_URI_FOR_MODULE)
ret = parse_module_info (string, epos, epos + 1, spos, uri);
if (ret == 0 && (uri_type & P11_KIT_URI_FOR_MODULE_WITH_VERSION) == P11_KIT_URI_FOR_MODULE_WITH_VERSION)
typedef enum {
P11_KIT_URI_FOR_OBJECT = (1 << 1),
P11_KIT_URI_FOR_TOKEN = (1 << 2),
+ P11_KIT_URI_FOR_SLOT = (1 << 5),
P11_KIT_URI_FOR_MODULE = (1 << 3),
P11_KIT_URI_FOR_MODULE_WITH_VERSION =
int p11_kit_uri_match_module_info (P11KitUri *uri,
CK_INFO_PTR info);
+CK_SLOT_INFO_PTR p11_kit_uri_get_slot_info (P11KitUri *uri);
+
+int p11_kit_uri_match_slot_info (P11KitUri *uri,
+ CK_SLOT_INFO_PTR slot_info);
+
CK_TOKEN_INFO_PTR p11_kit_uri_get_token_info (P11KitUri *uri);
int p11_kit_uri_match_token_info (P11KitUri *uri,