public List<ObjectHandle> FindAllObjects(List<ObjectAttribute> attributes)
{
if (this._disposed)
throw new ObjectDisposedException(this.GetType().FullName);
List<ObjectHandle> foundObjects = new List<ObjectHandle>();
CK_ATTRIBUTE[] template = null;
uint templateLength = 0;
if (attributes != null)
{
templateLength = Convert.ToUInt32(attributes.Count);
template = new CK_ATTRIBUTE[templateLength];
for (int i = 0; i < templateLength; i++)
template[i] = attributes[i].CkAttribute;
}
CKR rv = _p11.C_FindObjectsInit(_sessionId, template, templateLength);
if (rv != CKR.CKR_OK)
throw new Pkcs11Exception("C_FindObjectsInit", rv);
uint objectsLength = 256;
uint[] objects = new uint[objectsLength];
uint objectCount = objectsLength;
while (objectCount == objectsLength)
{
rv = _p11.C_FindObjects(_sessionId, objects, objectsLength, ref objectCount);
if (rv != CKR.CKR_OK)
throw new Pkcs11Exception("C_FindObjects", rv);
for (int i = 0; i < objectCount; i++)
foundObjects.Add(new ObjectHandle(objects[i]));
}
rv = _p11.C_FindObjectsFinal(_sessionId);
if (rv != CKR.CKR_OK)
throw new Pkcs11Exception("C_FindObjectsFinal", rv);
return foundObjects;
}