LineSegmentFrame::LineSegmentFrame(const FrameBase& aFrame)
    {
    Q_ASSERT(isCopyable(aFrame));
    setMaxVectors(aFrame.getDimensionT(VectorNo).mResolution);
    setVectorSizeT(VectorSize);
    int point[Dimensions] = {0, 0};
    for (point[VectorNo] = 0; point[VectorNo] < aFrame.getDimensionT(VectorNo).mResolution; ++point[VectorNo])
        for (point[ParamNo] = 0; point[ParamNo] < aFrame.getDimensionT(ParamNo).mResolution; ++point[ParamNo])
            setSampleT(point, aFrame.getSampleT(point));
    }
Esempio n. 2
0
// Save template
CK_RV P11Object::saveTemplate(Token *token, bool isPrivate, CK_ATTRIBUTE_PTR pTemplate, CK_ULONG ulAttributeCount, int op)
{
	if (osobject == NULL)
		return CKR_GENERAL_ERROR;
	if (osobject->startTransaction() == false)
		return CKR_GENERAL_ERROR;

	// [PKCS#11 v2.3 pg. 62] OBJECT_OP_COPY
	//    If the CKA_COPYABLE attribute of the object to be copied is set to CK_FALSE, C_CopyObject
	//    returns CKR_COPY_PROHIBITED.
	if (op == OBJECT_OP_COPY)
	{
		if (!isCopyable())
		{
			osobject->abortTransaction();
			return CKR_COPY_PROHIBITED;
		}
	}

	for (CK_ULONG i = 0; i < ulAttributeCount; i++)
	{
		// [PKCS#11 v2.3 pg. 61] OBJECT_OP_CREATE | OBJECT_OP_SET | OBJECT_OP_COPY
		//    1. If the supplied template specifies a value for an invalid attribute, then the attempt
		//    should fail with the error code CKR_ATTRIBUTE_TYPE_INVALID. An attribute
		//    is valid if it is either one of the attributes described in the Cryptoki specification or an
		//    additional vendor-specific attribute supported by the library and token.
		P11Attribute* attr = attributes[pTemplate[i].type];
		if (attr == NULL)
		{
			osobject->abortTransaction();
			return CKR_ATTRIBUTE_TYPE_INVALID;
		}

		// Additonal checks are done while updating the attributes themselves.
		CK_RV rv = attr->update(token,isPrivate, pTemplate[i].pValue, pTemplate[i].ulValueLen, op);
		if (rv != CKR_OK)
		{
			osobject->abortTransaction();
			return rv;
		}
	}

	// [PKCS#11 v2.3 pg. 60]
	//    4. If the attribute values in the supplied template, together with any default attribute
	//    values and any attribute values contributed to the object by the object-creation
	//    function itself, are insufficient to fully specify the object to create, then the attempt
	//    should fail with the error code CKR_TEMPLATE_INCOMPLETE.

	// All attributes that have to be specified are marked as such in the specification.
	// The following checks are relevant here:
	//  ck1  Must be specified when object is created with C_CreateObject.
	//  ck3  Must be specified when object is generated with C_GenerateKey or C_GenerateKeyPair.
	//  ck5  Must be specified when object is unwrapped with C_UnwrapKey.

	// TODO:
	//   Go through the attributes and see whether any attribute that MUST be specified
	//   during creation etc. have been specified in pTemplate.

	// [PKCS#11 v2.3 pg. 60]
	//    5. If the attribute values in the supplied template, together with any default attribute
	//    values and any attribute values contributed to the object by the object-creation
	//    function itself, are inconsistent, then the attempt should fail with the error code
	//    CKR_TEMPLATE_INCONSISTENT. A set of attribute values is inconsistent if not
	//    all of its members can be satisfied simultaneously by the token, although each value
	//    individually is valid in Cryptoki. One example of an inconsistent template would be
	//    using a template which specifies two different values for the same attribute. Another
	//    example would be trying to create a secret key object with an attribute which is
	//    appropriate for various types of public keys or private keys, but not for secret keys.
	//    A final example would be a template with an attribute that violates some token
	//    specific requirement. Note that this final example of an inconsistent template is
	//    token-dependent—on a different token, such a template might not be inconsistent.

	if (osobject->commitTransaction() == false)
	{
		return CKR_GENERAL_ERROR;
	}

	return CKR_OK;
}