static GP11Object*
create_credential (GP11Session *session, GP11Object *object,
                   const gchar *secret, GError **error)
{
	GP11Attributes *attrs;
	GP11Object *cred;

	g_return_val_if_fail (GP11_IS_SESSION (session), NULL);
	g_return_val_if_fail (!object || GP11_IS_OBJECT (object), NULL);

	if (!secret)
		secret = "";

	attrs = gp11_attributes_newv (CKA_CLASS, GP11_ULONG, CKO_G_CREDENTIAL,
	                              CKA_VALUE, strlen (secret), secret,
	                              CKA_MATE_TRANSIENT, GP11_BOOLEAN, TRUE,
	                              CKA_TOKEN, GP11_BOOLEAN, TRUE,
	                              GP11_INVALID);

	if (object)
		gp11_attributes_add_ulong (attrs, CKA_G_OBJECT,
		                           gp11_object_get_handle (object));

	cred = gp11_session_create_object_full (session, attrs, NULL, error);
	gp11_attributes_unref (attrs);

	if (cred != NULL)
		gp11_object_set_session (cred, session);

	return cred;
}
static void 
on_open_session(GP11Slot *slot, GAsyncResult *result, SeahorsePkcs11Refresher *self) 
{
	GError *err = NULL;
	GP11Attributes *attrs;
	
	g_return_if_fail (SEAHORSE_IS_PKCS11_REFRESHER (self));
	
	self->session = gp11_slot_open_session_finish (slot, result, &err);
	if (!self->session) {
		seahorse_pkcs11_mark_complete (SEAHORSE_OPERATION (self), err);
		return;
	}
	
	/* Step 2. Load all the objects that we want */
	attrs = gp11_attributes_new ();
	gp11_attributes_add_boolean (attrs, CKA_TOKEN, TRUE);
	gp11_attributes_add_ulong (attrs, CKA_CLASS, CKO_CERTIFICATE);
	gp11_session_find_objects_async (self->session, attrs, self->cancellable, 
	                                 (GAsyncReadyCallback)on_find_objects, self);
	gp11_attributes_unref (attrs);
}