This commit is contained in:
wtc%netscape.com 2003-09-23 22:56:46 +00:00
Родитель 20665a5b45
Коммит f64cfc45de
1 изменённых файлов: 0 добавлений и 145 удалений

Просмотреть файл

@ -48,151 +48,6 @@
#include <java_ids.h>
#include <jss_exceptions.h>
/***********************************************************************
* HACKS which belong in pk11cert.c
***********************************************************************/
typedef struct pk11KeyCallbackStr {
SECStatus (* callback)(SECKEYPrivateKey *,void *);
void *callbackArg;
void *wincx;
} pk11KeyCallback;
/**********************************************************************
* Callback information for keyTraversalCallback
*/
typedef enum {
CERT_OBJECT,
KEY_OBJECT
} ObjectType;
typedef struct {
JNIEnv *env;
jobject vector;
ObjectType type;
} TraversalCallbackInfo;
/**********************************************************************
* traversalCallback
*
* Generic callback that does the job for both private keys
* and certificates.
*
*/
static SECStatus
traversalCallback(void *keyCert, void *arg)
{
TraversalCallbackInfo *info;
jclass vectorClass;
jmethodID addElement;
jobject object=NULL;
jobject vector;
JNIEnv *env;
SECKEYPrivateKey *key=NULL;
SECKEYPrivateKey *keyCopy=NULL;
CERTCertificate *cert=NULL;
CERTCertificate *certCopy=NULL;
SECStatus status = SECFailure;
/**************************************************
* Get the callback data
**************************************************/
if(arg == NULL) {
JSS_trace(env, JSS_TRACE_ERROR,
"traversalCallback called with NULL argument");
PR_ASSERT(PR_FALSE);
goto finish;
}
info = (TraversalCallbackInfo*)arg;
env = info->env;
vector = info->vector;
if(info->type == KEY_OBJECT) {
key = (SECKEYPrivateKey*)keyCert;
} else {
PR_ASSERT(info->type == CERT_OBJECT);
cert = (CERTCertificate*)keyCert;
}
if(env==NULL || vector==NULL) {
PR_ASSERT(PR_FALSE);
goto finish;
}
/**************************************************
* Get JNI ids
**************************************************/
vectorClass = (*env)->GetObjectClass(env, vector);
if(vectorClass == NULL) {
ASSERT_OUTOFMEM(env);
goto finish;
}
addElement = (*env)->GetMethodID(env,
vectorClass,
VECTOR_ADD_ELEMENT_NAME,
VECTOR_ADD_ELEMENT_SIG);
if(addElement == NULL) {
ASSERT_OUTOFMEM(env);
goto finish;
}
/***************************************************
* Wrap the object
***************************************************/
if(info->type == KEY_OBJECT) {
/** Private keys may be temporary now...
if(key->pkcs11IsTemp) {
JSS_trace(env, JSS_TRACE_ERROR,
"Private Key passed to keyTraversalCallback is a"
" temporary object");
PR_ASSERT(PR_FALSE);
goto finish;
}
*/
keyCopy = SECKEY_CopyPrivateKey(key);
object = JSS_PK11_wrapPrivKey(env, &keyCopy);
} else {
PR_ASSERT( info->type == CERT_OBJECT );
certCopy = CERT_DupCertificate(cert);
object = JSS_PK11_wrapCert(env, &certCopy);
}
if(object == NULL) {
PR_ASSERT( (*env)->ExceptionOccurred(env) );
goto finish;
}
/***************************************************
* Insert the key into the vector
***************************************************/
(*env)->CallVoidMethod(env, vector, addElement, object);
status = SECSuccess;
finish:
if(object==NULL) {
if(keyCopy!=NULL) {
SECKEY_DestroyPrivateKey(keyCopy);
}
if(certCopy!=NULL) {
CERT_DestroyCertificate(certCopy);
}
}
return status;
}
/**********************************************************************
* certTraversalCallback
*
* Given a certificate and vector, inserts the certificate into the vector.
*
*/
static SECStatus
certTraversalCallback(CERTCertificate *cert, void *arg)
{
PR_ASSERT( ((TraversalCallbackInfo*)arg)->type == CERT_OBJECT);
return traversalCallback( (void*)cert, arg);
}
/**********************************************************************
* PK11Store.putKeysInVector