/**
 *  Constructor for the certificate object
 */
int createCertificateObject(CK_ATTRIBUTE_PTR pTemplate, CK_ULONG ulCount, struct p11Object_t *object)
{
	unsigned int i;
	int index, rc;

	rc = createStorageObject(pTemplate, ulCount, object);

	if (rc) {
		return rc;
	}

	for (i = 0; i < NEEDED_ATTRIBUTES_CERTIFICATEOBJECT; i++) {
		index = findAttributeInTemplate(attributesCertificateObject[i].attribute.type, pTemplate, ulCount);

		if (index == -1) { /* The attribute is not present - is it optional? */
			if (attributesCertificateObject[i].optional) {
				addAttribute(object, &attributesCertificateObject[i].attribute);
			} else { /* the attribute is not optional */
				removeAllAttributes(object);
				memset(object, 0x00, sizeof(*object));
				return CKR_TEMPLATE_INCOMPLETE;
			}
		} else {
			addAttribute(object, &pTemplate[index]);
		}
	}

#ifdef DEBUG
	dumpAttributeList(object);
#endif

	return 0;
}
Exemple #2
0
int createKeyObject(CK_ATTRIBUTE_PTR pTemplate, CK_ULONG ulCount, struct p11Object_t *pObject)
{
	int rc;

	rc = createStorageObject(pTemplate, ulCount, pObject);

	if (rc) {
		return rc;
	}

	rc = copyObjectAttributes(pTemplate, ulCount, pObject, attributesKeyObject);

	return rc;
}