Back to index

lightning-sunbird  0.9+nobinonly
Classes | Defines | Typedefs | Functions
nsKeygenHandler.h File Reference
#include "nsIFormProcessor.h"
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

struct  SECKeySizeChoiceInfoStr
class  nsKeygenFormProcessor

Defines

#define DEFAULT_RSA_KEYGEN_PE   65537L
#define DEFAULT_RSA_KEYGEN_ALG   SEC_OID_PKCS1_MD5_WITH_RSA_ENCRYPTION

Typedefs

typedef struct
SECKeySizeChoiceInfoStr 
SECKeySizeChoiceInfo

Functions

nsresult GetSlotWithMechanism (PRUint32 mechanism, nsIInterfaceRequestor *ctx, PK11SlotInfo **retSlot)

Class Documentation

struct SECKeySizeChoiceInfoStr

Definition at line 45 of file nsKeygenHandler.h.

Collaboration diagram for SECKeySizeChoiceInfoStr:
Class Members
PRUnichar * name
int size

Define Documentation

Definition at line 55 of file nsKeygenHandler.h.

Definition at line 54 of file nsKeygenHandler.h.


Typedef Documentation


Function Documentation

nsresult GetSlotWithMechanism ( PRUint32  mechanism,
nsIInterfaceRequestor ctx,
PK11SlotInfo **  retSlot 
)

Definition at line 275 of file nsKeygenHandler.cpp.

{
    nsNSSShutDownPreventionLock locker;
    PK11SlotList * slotList = nsnull;
    PRUnichar** tokenNameList = nsnull;
    nsITokenDialogs * dialogs;
    PRUnichar *unicodeTokenChosen;
    PK11SlotListElement *slotElement, *tmpSlot;
    PRUint32 numSlots = 0, i = 0;
    PRBool canceled;
    nsresult rv = NS_OK;

    *aSlot = nsnull;

    // Get the slot
    slotList = PK11_GetAllTokens(MapGenMechToAlgoMech(aMechanism), 
                                PR_TRUE, PR_TRUE, m_ctx);
    if (!slotList || !slotList->head) {
        rv = NS_ERROR_FAILURE;
        goto loser;
    }

    if (!slotList->head->next) {
        /* only one slot available, just return it */
        *aSlot = slotList->head->slot;
      } else {
        // Gerenate a list of slots and ask the user to choose //
        tmpSlot = slotList->head;
        while (tmpSlot) {
            numSlots++;
            tmpSlot = tmpSlot->next;
        }

        // Allocate the slot name buffer //
        tokenNameList = NS_STATIC_CAST(PRUnichar**, nsMemory::Alloc(sizeof(PRUnichar *) * numSlots));
        if (!tokenNameList) {
            rv = NS_ERROR_OUT_OF_MEMORY;
            goto loser;
        }

        i = 0;
        slotElement = PK11_GetFirstSafe(slotList);
        while (slotElement) {
            tokenNameList[i] = UTF8ToNewUnicode(nsDependentCString(PK11_GetTokenName(slotElement->slot)));
            slotElement = PK11_GetNextSafe(slotList, slotElement, PR_FALSE);
            if (tokenNameList[i])
                i++;
            else {
                // OOM. adjust numSlots so we don't free unallocated memory. 
                numSlots = i;
                rv = NS_ERROR_OUT_OF_MEMORY;
                goto loser;
            }
        }

              /* Throw up the token list dialog and get back the token */
              rv = getNSSDialogs((void**)&dialogs,
                                    NS_GET_IID(nsITokenDialogs),
                     NS_TOKENDIALOGS_CONTRACTID);

              if (NS_FAILED(rv)) goto loser;

    {
      nsPSMUITracker tracker;
      if (!tokenNameList || !*tokenNameList) {
          rv = NS_ERROR_OUT_OF_MEMORY;
      }
      else if (tracker.isUIForbidden()) {
        rv = NS_ERROR_NOT_AVAILABLE;
      }
      else {
              rv = dialogs->ChooseToken(nsnull, (const PRUnichar**)tokenNameList, numSlots, &unicodeTokenChosen, &canceled);
      }
    }
              NS_RELEASE(dialogs);
              if (NS_FAILED(rv)) goto loser;

              if (canceled) { rv = NS_ERROR_NOT_AVAILABLE; goto loser; }

        // Get the slot //
        slotElement = PK11_GetFirstSafe(slotList);
        nsAutoString tokenStr(unicodeTokenChosen);
        while (slotElement) {
            if (tokenStr.Equals(NS_ConvertUTF8toUCS2(PK11_GetTokenName(slotElement->slot)))) {
                *aSlot = slotElement->slot;
                break;
            }
            slotElement = PK11_GetNextSafe(slotList, slotElement, PR_FALSE);
        }
        if(!(*aSlot)) {
            rv = NS_ERROR_FAILURE;
            goto loser;
        }
      }

      // Get a reference to the slot //
      PK11_ReferenceSlot(*aSlot);
loser:
      if (slotList) {
          PK11_FreeSlotList(slotList);
      }
      if (tokenNameList) {
          NS_FREE_XPCOM_ALLOCATED_POINTER_ARRAY(numSlots, tokenNameList);
      }
      return rv;
}

Here is the call graph for this function:

Here is the caller graph for this function: