| Index: nss/lib/cryptohi/seckey.c
|
| diff --git a/nss/lib/cryptohi/seckey.c b/nss/lib/cryptohi/seckey.c
|
| index f63d15062d979146c1487eb0b382becf4ce82a17..16d2a499b785ac5a501db9dd05633331b22bbeaf 100644
|
| --- a/nss/lib/cryptohi/seckey.c
|
| +++ b/nss/lib/cryptohi/seckey.c
|
| @@ -1213,18 +1213,13 @@ SECKEY_ConvertToPublicKey(SECKEYPrivateKey *privk)
|
| return NULL;
|
| }
|
|
|
| -CERTSubjectPublicKeyInfo *
|
| -SECKEY_CreateSubjectPublicKeyInfo(SECKEYPublicKey *pubk)
|
| +static CERTSubjectPublicKeyInfo *
|
| +seckey_CreateSubjectPublicKeyInfo_helper(SECKEYPublicKey *pubk)
|
| {
|
| CERTSubjectPublicKeyInfo *spki;
|
| PLArenaPool *arena;
|
| SECItem params = { siBuffer, NULL, 0 };
|
|
|
| - if (!pubk) {
|
| - PORT_SetError(SEC_ERROR_INVALID_ARGS);
|
| - return NULL;
|
| - }
|
| -
|
| arena = PORT_NewArena(DER_DEFAULT_CHUNKSIZE);
|
| if (arena == NULL) {
|
| PORT_SetError(SEC_ERROR_NO_MEMORY);
|
| @@ -1332,78 +1327,36 @@ SECKEY_CreateSubjectPublicKeyInfo(SECKEYPublicKey *pubk)
|
| return NULL;
|
| }
|
|
|
| -void
|
| -SECKEY_DestroySubjectPublicKeyInfo(CERTSubjectPublicKeyInfo *spki)
|
| -{
|
| - if (spki && spki->arena) {
|
| - PORT_FreeArena(spki->arena, PR_FALSE);
|
| - }
|
| -}
|
| -
|
| -/*
|
| - * this only works for RSA keys... need to do something
|
| - * similiar to CERT_ExtractPublicKey for other key times.
|
| - */
|
| -SECKEYPublicKey *
|
| -SECKEY_DecodeDERPublicKey(const SECItem *pubkder)
|
| +CERTSubjectPublicKeyInfo *
|
| +SECKEY_CreateSubjectPublicKeyInfo(const SECKEYPublicKey *pubk)
|
| {
|
| - PLArenaPool *arena;
|
| - SECKEYPublicKey *pubk;
|
| - SECStatus rv;
|
| - SECItem newPubkder;
|
| + CERTSubjectPublicKeyInfo *spki;
|
| + SECKEYPublicKey *tempKey;
|
|
|
| - arena = PORT_NewArena (DER_DEFAULT_CHUNKSIZE);
|
| - if (arena == NULL) {
|
| - PORT_SetError (SEC_ERROR_NO_MEMORY);
|
| - return NULL;
|
| + if (!pubk) {
|
| + PORT_SetError(SEC_ERROR_INVALID_ARGS);
|
| + return NULL;
|
| }
|
|
|
| - pubk = (SECKEYPublicKey *) PORT_ArenaZAlloc (arena, sizeof (SECKEYPublicKey));
|
| - if (pubk != NULL) {
|
| - pubk->arena = arena;
|
| - pubk->pkcs11Slot = NULL;
|
| - pubk->pkcs11ID = 0;
|
| - prepare_rsa_pub_key_for_asn1(pubk);
|
| - /* copy the DER into the arena, since Quick DER returns data that points
|
| - into the DER input, which may get freed by the caller */
|
| - rv = SECITEM_CopyItem(arena, &newPubkder, pubkder);
|
| - if ( rv == SECSuccess ) {
|
| - rv = SEC_QuickDERDecodeItem(arena, pubk, SECKEY_RSAPublicKeyTemplate,
|
| - &newPubkder);
|
| - }
|
| - if (rv == SECSuccess)
|
| - return pubk;
|
| - SECKEY_DestroyPublicKey (pubk);
|
| - } else {
|
| - PORT_SetError (SEC_ERROR_NO_MEMORY);
|
| + tempKey = SECKEY_CopyPublicKey(pubk);
|
| + if (!tempKey) {
|
| + return NULL;
|
| }
|
| -
|
| - PORT_FreeArena (arena, PR_FALSE);
|
| - return NULL;
|
| + spki = seckey_CreateSubjectPublicKeyInfo_helper(tempKey);
|
| + SECKEY_DestroyPublicKey(tempKey);
|
| + return spki;
|
| }
|
|
|
| -/*
|
| - * Decode a base64 ascii encoded DER encoded public key.
|
| - */
|
| -SECKEYPublicKey *
|
| -SECKEY_ConvertAndDecodePublicKey(const char *pubkstr)
|
| +void
|
| +SECKEY_DestroySubjectPublicKeyInfo(CERTSubjectPublicKeyInfo *spki)
|
| {
|
| - SECKEYPublicKey *pubk;
|
| - SECStatus rv;
|
| - SECItem der;
|
| -
|
| - rv = ATOB_ConvertAsciiToItem (&der, pubkstr);
|
| - if (rv != SECSuccess)
|
| - return NULL;
|
| -
|
| - pubk = SECKEY_DecodeDERPublicKey (&der);
|
| -
|
| - PORT_Free (der.data);
|
| - return pubk;
|
| + if (spki && spki->arena) {
|
| + PORT_FreeArena(spki->arena, PR_FALSE);
|
| + }
|
| }
|
|
|
| SECItem *
|
| -SECKEY_EncodeDERSubjectPublicKeyInfo(SECKEYPublicKey *pubk)
|
| +SECKEY_EncodeDERSubjectPublicKeyInfo(const SECKEYPublicKey *pubk)
|
| {
|
| CERTSubjectPublicKeyInfo *spki=NULL;
|
| SECItem *spkiDER=NULL;
|
| @@ -1757,7 +1710,7 @@ SECKEY_ImportDERPublicKey(const SECItem *derKey, CK_KEY_TYPE type)
|
| finish:
|
| if (rv != SECSuccess) {
|
| if (arena != NULL) {
|
| - PORT_FreeArena(arena, PR_TRUE);
|
| + PORT_FreeArena(arena, PR_FALSE);
|
| }
|
| pubk = NULL;
|
| }
|
|
|