diff options
author | Marco Trevisan (Treviño) <mail@3v1n0.net> | 2020-11-13 20:32:46 +0100 |
---|---|---|
committer | Marco Trevisan (Treviño) <mail@3v1n0.net> | 2020-11-13 20:32:46 +0100 |
commit | 11d27265d1978d09b2f0526970debc9f62aacbea (patch) | |
tree | ff2c651def9b888df6f7fcb8e006aeedaad5d1d9 /gck | |
parent | 7efb3056d64968e6faaabc4582abc7a5b93a1b23 (diff) | |
download | gcr-11d27265d1978d09b2f0526970debc9f62aacbea.tar.gz |
gck-slot: Add gck_slot_token_has_flags() function
Given that gck_slot_has_flags changed meaning in the previous commit,
add back a function that allows to get the slot token flags
Diffstat (limited to 'gck')
-rw-r--r-- | gck/gck-slot.c | 39 |
1 files changed, 39 insertions, 0 deletions
diff --git a/gck/gck-slot.c b/gck/gck-slot.c index 60698a9..f42c3ee 100644 --- a/gck/gck-slot.c +++ b/gck/gck-slot.c @@ -852,6 +852,45 @@ gck_slot_has_flags (GckSlot *self, gulong flags) } /** + * gck_slot_token_has_flags: + * @self: The GckSlot object. + * @flags: The flags to check. + * + * Check if the PKCS11 token in the slot has the given flags. + * + * Returns: Whether one or more flags exist. + */ +gboolean +gck_slot_token_has_flags (GckSlot *self, gulong flags) +{ + CK_FUNCTION_LIST_PTR funcs; + GckModule *module = NULL; + CK_TOKEN_INFO info; + CK_SLOT_ID handle; + CK_RV rv; + + g_return_val_if_fail (GCK_IS_SLOT (self), FALSE); + + g_object_get (self, "module", &module, "handle", &handle, NULL); + g_return_val_if_fail (GCK_IS_MODULE (module), FALSE); + + funcs = gck_module_get_functions (module); + g_return_val_if_fail (funcs, FALSE); + + memset (&info, 0, sizeof (info)); + rv = (funcs->C_GetTokenInfo) (handle, &info); + + g_object_unref (module); + + if (rv != CKR_OK) { + g_warning ("couldn't get slot info: %s", gck_message_from_rv (rv)); + return FALSE; + } + + return (info.flags & flags) != 0; +} + +/** * gck_slot_enumerate_objects: * @self: a #GckSlot to enumerate objects on * @match: attributes that the objects must match, or empty for all objects |