item = SEC_ASN1EncodeItem(NULL,NULL,cert,pk11_SerialTemplate); if (item == NULL) break; attr = pk11_NewTokenAttribute(type, item->data, item->len, PR_TRUE); SECITEM_FreeItem(item,PR_TRUE); return attr;
return pk11_NewTokenAttribute(type,cert->derSN.data, cert->derSN.len, PR_FALSE);
pk11_FindCertAttribute(PK11TokenObject *object, CK_ATTRIBUTE_TYPE type){    NSSLOWCERTCertificate *cert;    NSSLOWKEYPublicKey  *pubKey;    unsigned char hash[SHA1_LENGTH];    SECItem *item;    PK11Attribute *attr;    switch (type) {    case CKA_PRIVATE:	return (PK11Attribute *) &pk11_StaticFalseAttr;    case CKA_MODIFIABLE:	return (PK11Attribute *) &pk11_StaticTrueAttr;    case CKA_CERTIFICATE_TYPE:        /* hardcoding X.509 into here */        return (PK11Attribute *)&pk11_StaticX509Attr;    case CKA_SENSITIVE:	return NULL;    default:	break;    }    cert = pk11_getCert(object);    if (cert == NULL) {	return NULL;    }    switch (type) {    case CKA_VALUE:	return pk11_NewTokenAttribute(type,cert->derCert.data,						cert->derCert.len,PR_FALSE);    case CKA_ID:	pubKey = nsslowcert_ExtractPublicKey(cert);	if (pubKey == NULL) break;	item = pk11_GetPubItem(pubKey);	if (item == NULL) {	    nsslowkey_DestroyPublicKey(pubKey);	    break;	}	SHA1_HashBuf(hash,item->data,item->len);	/* item is imbedded in pubKey, just free the key */	nsslowkey_DestroyPublicKey(pubKey);	return pk11_NewTokenAttribute(type, hash, SHA1_LENGTH, PR_TRUE);    case CKA_LABEL:	return cert->nickname ? pk11_NewTokenAttribute(type, cert->nickname,				PORT_Strlen(cert->nickname), PR_FALSE) :					(PK11Attribute *) &pk11_StaticNullAttr;    case CKA_SUBJECT:	return pk11_NewTokenAttribute(type,cert->derSubject.data,						cert->derSubject.len, PR_FALSE);    case CKA_ISSUER:	return pk11_NewTokenAttribute(type,cert->derIssuer.data,						cert->derIssuer.len, PR_FALSE);    case CKA_SERIAL_NUMBER:	item = SEC_ASN1EncodeItem(NULL,NULL,cert,pk11_SerialTemplate);	if (item == NULL) break;	attr = pk11_NewTokenAttribute(type, item->data, item->len, PR_TRUE);	SECITEM_FreeItem(item,PR_TRUE);	return attr;    case CKA_NETSCAPE_EMAIL:	return cert->emailAddr ? pk11_NewTokenAttribute(type, cert->emailAddr,				PORT_Strlen(cert->emailAddr), PR_FALSE) :					(PK11Attribute *) &pk11_StaticNullAttr;    default:	break;    }    return NULL;}