if (spki == NULL) { spki = (NSSLOWCERTSubjectPublicKeyInfo *) PORT_ArenaZAlloc(cert->arena, sizeof(NSSLOWCERTSubjectPublicKeyInfo)); if (spki == NULL) { PORT_FreeArena (arena, PR_FALSE); return NULL; } rv = SEC_ASN1DecodeItem(cert->arena, spki, nsslowcert_SubjectPublicKeyInfoTemplate, &cert->derSubjKeyInfo); if (rv != SECSuccess) { PORT_FreeArena (arena, PR_FALSE); return NULL; } cert->subjectPublicKeyInfo = spki; }
nsslowcert_ExtractPublicKey(NSSLOWCERTCertificate *cert){    NSSLOWCERTSubjectPublicKeyInfo *spki = &cert->subjectPublicKeyInfo;    NSSLOWKEYPublicKey *pubk;    SECItem os;    SECStatus rv;    PRArenaPool *arena;    SECOidTag tag;    arena = PORT_NewArena (DER_DEFAULT_CHUNKSIZE);    if (arena == NULL)        return NULL;    pubk = (NSSLOWKEYPublicKey *) 		PORT_ArenaZAlloc(arena, sizeof(NSSLOWKEYPublicKey));    if (pubk == NULL) {        PORT_FreeArena (arena, PR_FALSE);        return NULL;    }    pubk->arena = arena;    /* Convert bit string length from bits to bytes */    os = spki->subjectPublicKey;    DER_ConvertBitString (&os);    tag = SECOID_GetAlgorithmTag(&spki->algorithm);    switch ( tag ) {      case SEC_OID_X500_RSA_ENCRYPTION:      case SEC_OID_PKCS1_RSA_ENCRYPTION:        pubk->keyType = NSSLOWKEYRSAKey;        prepare_low_rsa_pub_key_for_asn1(pubk);        rv = SEC_ASN1DecodeItem(arena, pubk, 				nsslowcert_RSAPublicKeyTemplate, &os);        if (rv == SECSuccess)            return pubk;        break;      case SEC_OID_ANSIX9_DSA_SIGNATURE:        pubk->keyType = NSSLOWKEYDSAKey;        prepare_low_dsa_pub_key_for_asn1(pubk);        rv = SEC_ASN1DecodeItem(arena, pubk,				 nsslowcert_DSAPublicKeyTemplate, &os);        if (rv == SECSuccess) return pubk;        break;      case SEC_OID_X942_DIFFIE_HELMAN_KEY:        pubk->keyType = NSSLOWKEYDHKey;        prepare_low_dh_pub_key_for_asn1(pubk);        rv = SEC_ASN1DecodeItem(arena, pubk,				 nsslowcert_DHPublicKeyTemplate, &os);        if (rv == SECSuccess) return pubk;        break;      default:        rv = SECFailure;        break;    }    nsslowkey_DestroyPublicKey (pubk);    return NULL;}