Helper function for matching mechanism types.
authorStefan Walter <stefw@src.gnome.org>
Tue, 6 Jan 2009 03:13:26 +0000 (03:13 +0000)
committerStefan Walter <stefw@src.gnome.org>
Tue, 6 Jan 2009 03:13:26 +0000 (03:13 +0000)
* gp11/gp11.h:
* gp11/gp11-slot.c: Helper function for matching mechanism types.

* pkcs11/ssh-agent/gck-ssh-agent.c:
* pkcs11/ssh-agent/gck-ssh-agent.h:
* pkcs11/ssh-agent/gck-ssh-agent-ops.c:
* pkcs11/ssh-agent/gck-ssh-agent-private.h:
* pkcs11/ssh-agent/gck-ssh-agent-standalone.c: The modular ssh agent now
uses keys from any available PKCS#11 slots, and automatically selects a decent
slot for it's session keys.

svn path=/trunk/; revision=1441

gp11/gp11-slot.c
gp11/gp11.h

index 35acfa5..843b796 100644 (file)
@@ -270,6 +270,50 @@ gp11_mechanism_info_free (GP11MechanismInfo *mech_info)
 }
 
 /**
+ * gp11_mechanisms_check:
+ * @mechanisms: A list of mechanisms, perhaps retrieved from gp11_slot_get_mechanisms().
+ *
+ * Check whether all the mechanism types are in the list.
+ *
+ * The arguments should be a list of CKM_XXX mechanism types. The last argument
+ * should be GP11_INVALID.
+ *
+ * Return value: Whether the mechanism is in the list or not.
+ **/
+gboolean
+gp11_mechanisms_check (GP11Mechanisms *mechanisms, ...)
+{
+       gboolean found = TRUE;
+       va_list va;
+       gulong mech;
+       gsize i;
+
+       g_return_val_if_fail (mechanisms, FALSE);
+
+       va_start (va, mechanisms);
+       for (;;) {
+               mech = va_arg (va, gulong);
+               if (mech == GP11_INVALID)
+                       break;
+
+               found = FALSE;
+               for (i = 0; i < gp11_mechanisms_length (mechanisms); ++i) {
+                       if (gp11_mechanisms_at (mechanisms, i) == mech) {
+                               found = TRUE;
+                               break;
+                       }
+               }
+
+               if (found == FALSE)
+                       break;
+
+       }
+       va_end (va);
+
+       return found;
+}
+
+/**
  * gp11_slot_get_handle:
  * @self: The slot to get the handle of.
  *
index 9db7801..d300d53 100644 (file)
@@ -387,6 +387,9 @@ typedef GArray GP11Mechanisms;
 
 #define gp11_mechanisms_free(a)         (g_array_free(a, TRUE))
 
+gboolean            gp11_mechanisms_check                   (GP11Mechanisms *mechanisms,
+                                                             ...);
+
 #define GP11_TYPE_SLOT             (gp11_slot_get_type())
 #define GP11_SLOT(obj)             (G_TYPE_CHECK_INSTANCE_CAST((obj), GP11_TYPE_SLOT, GP11Slot))
 #define GP11_SLOT_CLASS(klass)     (G_TYPE_CHECK_CLASS_CAST((klass), GP11_TYPE_SLOT, GP11Slot))