Back to index

lightning-sunbird  0.9+nobinonly
Public Member Functions | Private Attributes
nsKeygenThread Class Reference

#include <nsKeygenThread.h>

Inheritance diagram for nsKeygenThread:
Inheritance graph
[legend]
Collaboration diagram for nsKeygenThread:
Collaboration graph
[legend]

List of all members.

Public Member Functions

 nsKeygenThread ()
virtual ~nsKeygenThread ()
NS_DECL_NSIKEYGENTHREAD
NS_DECL_ISUPPORTS void 
SetParams (PK11SlotInfo *a_slot, PRUint32 a_keyGenMechanism, void *a_params, PRBool a_isPerm, PRBool a_isSensitive, void *a_wincx)
nsresult GetParams (SECKEYPrivateKey **a_privateKey, SECKEYPublicKey **a_publicKey)
void Join (void)
void Run (void)
void startKeyGeneration (in nsIObserver observer)
 startKeyGeneration - run the thread A user interface using this interface needs to call this method as soon as the status information is displaying.
void userCanceled (out boolean threadAlreadyClosedDialog)
 userCanceled - notify the thread If the user canceled, the thread is no longer allowed to close the dialog.

Private Attributes

PRLockmutex
nsCOMPtr< nsIObserverobserver
PRBool iAmRunning
PRBool keygenReady
PRBool statusDialogClosed
PRBool alreadyReceivedParams
SECKEYPrivateKey * privateKey
SECKEYPublicKey * publicKey
PK11SlotInfo * slot
PRUint32 keyGenMechanism
voidparams
PRBool isPerm
PRBool isSensitive
voidwincx
PRThreadthreadHandle

Detailed Description

Definition at line 50 of file nsKeygenThread.h.


Constructor & Destructor Documentation

Definition at line 68 of file nsKeygenThread.cpp.

{
  if (mutex) {
    PR_DestroyLock(mutex);
  }
}

Here is the call graph for this function:


Member Function Documentation

nsresult nsKeygenThread::GetParams ( SECKEYPrivateKey **  a_privateKey,
SECKEYPublicKey **  a_publicKey 
)

Definition at line 104 of file nsKeygenThread.cpp.

{
  if (!a_privateKey || !a_publicKey) {
    return NS_ERROR_FAILURE;
  }

  nsresult rv;
  
  PR_Lock(mutex);
  
    // GetParams must not be called until thread creator called
    // Join on this thread.
    NS_ASSERTION(keygenReady, "logic error in nsKeygenThread::GetParams");

    if (keygenReady) {
      *a_privateKey = privateKey;
      *a_publicKey = publicKey;

      privateKey = 0;
      publicKey = 0;
      
      rv = NS_OK;
    }
    else {
      rv = NS_ERROR_FAILURE;
    }
  
  PR_Unlock(mutex);
  
  return rv;
}

Here is the caller graph for this function:

Definition at line 263 of file nsKeygenThread.cpp.

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 212 of file nsKeygenThread.cpp.

{
  nsNSSShutDownPreventionLock locker;
  PRBool canGenerate = PR_FALSE;

  PR_Lock(mutex);

    if (alreadyReceivedParams) {
      canGenerate = PR_TRUE;
      keygenReady = PR_FALSE;
    }

  PR_Unlock(mutex);

  if (canGenerate)
    privateKey = PK11_GenerateKeyPair(slot, keyGenMechanism,
                                         params, &publicKey,
                                         isPerm, isSensitive, wincx);
  
  // This call gave us ownership over privateKey and publicKey.
  // But as the params structure is owner by our caller,
  // we effectively transferred ownership to the caller.
  // As long as key generation can't be canceled, we don't need 
  // to care for cleaning this up.

  nsCOMPtr<nsIObserver> obs;
  PR_Lock(mutex);

    keygenReady = PR_TRUE;
    iAmRunning = PR_FALSE;

    // forget our parameters
    if (slot) {
      PK11_FreeSlot(slot);
      slot = 0;
    }
    keyGenMechanism = 0;
    params = 0;
    wincx = 0;

    if (!statusDialogClosed)
      obs = observer;

    observer = nsnull;

  PR_Unlock(mutex);

  if (obs)
    obs->Observe(nsnull, "keygen-finished", nsnull);
}

Here is the call graph for this function:

void nsKeygenThread::SetParams ( PK11SlotInfo *  a_slot,
PRUint32  a_keyGenMechanism,
void a_params,
PRBool  a_isPerm,
PRBool  a_isSensitive,
void a_wincx 
)

Definition at line 75 of file nsKeygenThread.cpp.

{
  nsNSSShutDownPreventionLock locker;
  PR_Lock(mutex);
 
    if (!alreadyReceivedParams) {
      alreadyReceivedParams = PR_TRUE;
      if (a_slot) {
        slot = PK11_ReferenceSlot(a_slot);
      }
      else {
        slot = nsnull;
      }
      keyGenMechanism = a_keyGenMechanism;
      params = a_params;
      isPerm = a_isPerm;
      isSensitive = a_isSensitive;
      wincx = a_wincx;
    }

  PR_Unlock(mutex);
}

Here is the call graph for this function:

Here is the caller graph for this function:

startKeyGeneration - run the thread A user interface using this interface needs to call this method as soon as the status information is displaying.

This will trigger key generation. To allow the closure of the status information, the thread needs a handle to an observer.

observer will be called on the UI thread. When the key generation is done, the observe method will be called with a topic of "keygen-finished" and null data and subject.

void nsIKeygenThread::userCanceled ( out boolean  threadAlreadyClosedDialog) [inherited]

userCanceled - notify the thread If the user canceled, the thread is no longer allowed to close the dialog.

However, if the thread already closed it, we are not allowed to close it.


Member Data Documentation

Definition at line 60 of file nsKeygenThread.h.

Definition at line 57 of file nsKeygenThread.h.

Definition at line 67 of file nsKeygenThread.h.

Definition at line 68 of file nsKeygenThread.h.

Definition at line 65 of file nsKeygenThread.h.

Definition at line 58 of file nsKeygenThread.h.

Definition at line 53 of file nsKeygenThread.h.

Definition at line 55 of file nsKeygenThread.h.

Definition at line 66 of file nsKeygenThread.h.

SECKEYPrivateKey* nsKeygenThread::privateKey [private]

Definition at line 62 of file nsKeygenThread.h.

SECKEYPublicKey* nsKeygenThread::publicKey [private]

Definition at line 63 of file nsKeygenThread.h.

PK11SlotInfo* nsKeygenThread::slot [private]

Definition at line 64 of file nsKeygenThread.h.

Definition at line 59 of file nsKeygenThread.h.

Definition at line 71 of file nsKeygenThread.h.

Definition at line 69 of file nsKeygenThread.h.


The documentation for this class was generated from the following files: