[gcr: 3/4] gck-slot: Add gck_slot_token_has_flags() function




commit 11d27265d1978d09b2f0526970debc9f62aacbea
Author: Marco Trevisan (TreviƱo) <mail 3v1n0 net>
Date:   Fri Nov 13 20:32:46 2020 +0100

    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

 gck/gck-slot.c | 39 +++++++++++++++++++++++++++++++++++++++
 1 file changed, 39 insertions(+)
---
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
@@ -851,6 +851,45 @@ gck_slot_has_flags (GckSlot *self, gulong flags)
        return (info.flags & flags) != 0;
 }
 
+/**
+ * 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


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