if (attribute == NULL) return CKR_TEMPLATE_INCOMPLETE;
if (attribute == NULL) return CKR_TEMPLATE_INCOMPLETE; requiredLen = pk11_MapKeySize(key_type); if (attribute->attrib.ulValueLen != requiredLen) { pk11_FreeAttribute(attribute); return CKR_KEY_SIZE_RANGE; }
validateSecretKey(PK11Session *session, PK11Object *object, 					CK_KEY_TYPE key_type, PRBool isFIPS){    CK_RV crv;    CK_BBOOL cktrue = CK_TRUE;    CK_BBOOL ckfalse = CK_FALSE;    PK11Attribute *attribute = NULL;    crv = pk11_defaultAttribute(object,CKA_SENSITIVE,				isFIPS?&cktrue:&ckfalse,sizeof(CK_BBOOL));    if (crv != CKR_OK)  return crv;     crv = pk11_defaultAttribute(object,CKA_EXTRACTABLE,						&cktrue,sizeof(CK_BBOOL));    if (crv != CKR_OK)  return crv;     crv = pk11_defaultAttribute(object,CKA_ENCRYPT,&cktrue,sizeof(CK_BBOOL));    if (crv != CKR_OK)  return crv;     crv = pk11_defaultAttribute(object,CKA_DECRYPT,&cktrue,sizeof(CK_BBOOL));    if (crv != CKR_OK)  return crv;     crv = pk11_defaultAttribute(object,CKA_SIGN,&ckfalse,sizeof(CK_BBOOL));    if (crv != CKR_OK)  return crv;     crv = pk11_defaultAttribute(object,CKA_VERIFY,&ckfalse,sizeof(CK_BBOOL));    if (crv != CKR_OK)  return crv;     crv = pk11_defaultAttribute(object,CKA_WRAP,&cktrue,sizeof(CK_BBOOL));    if (crv != CKR_OK)  return crv;     crv = pk11_defaultAttribute(object,CKA_UNWRAP,&cktrue,sizeof(CK_BBOOL));    if (crv != CKR_OK)  return crv;     if ( !pk11_hasAttribute(object, CKA_VALUE)) {	return CKR_TEMPLATE_INCOMPLETE;    }    /* the next two bits get modified only in the key gen and token cases */    crv = pk11_forceAttribute(object,CKA_ALWAYS_SENSITIVE,						&ckfalse,sizeof(CK_BBOOL));    if (crv != CKR_OK)  return crv;     crv = pk11_forceAttribute(object,CKA_NEVER_EXTRACTABLE,						&ckfalse,sizeof(CK_BBOOL));    if (crv != CKR_OK)  return crv;     /* some types of keys have a value length */    crv = CKR_OK;    switch (key_type) {    /* force CKA_VALUE_LEN to be set */    case CKK_GENERIC_SECRET:    case CKK_RC2:    case CKK_RC4:#if NSS_SOFTOKEN_DOES_RC5    case CKK_RC5:#endif#ifdef NSS_SOFTOKEN_DOES_CAST    case CKK_CAST:    case CKK_CAST3:    case CKK_CAST5:#endif#if NSS_SOFTOKEN_DOES_IDEA    case CKK_IDEA:#endif	attribute = pk11_FindAttribute(object,CKA_VALUE);	/* shouldn't happen */	if (attribute == NULL) return CKR_TEMPLATE_INCOMPLETE;	crv = pk11_forceAttribute(object, CKA_VALUE_LEN, 			&attribute->attrib.ulValueLen, sizeof(CK_ULONG));	pk11_FreeAttribute(attribute);	break;    /* force the value to have the correct parity */    case CKK_DES:    case CKK_DES2:    case CKK_DES3:    case CKK_CDMF:	attribute = pk11_FindAttribute(object,CKA_VALUE);	/* shouldn't happen */	if (attribute == NULL) return CKR_TEMPLATE_INCOMPLETE;	pk11_FormatDESKey((unsigned char*)attribute->attrib.pValue,						 attribute->attrib.ulValueLen);	pk11_FreeAttribute(attribute);	break;    default:	break;    }    return crv;}