Use id manager to acquire nonce context id

This commit is contained in:
Reto Buerki
2013-03-19 15:23:45 +01:00
committed by Tobias Brunner
parent f3cd7f50de
commit c38459d77d
+16 -6
View File
@@ -14,11 +14,12 @@
* for more details. * for more details.
*/ */
#include "tkm_nonceg.h"
#include <tkm/client.h> #include <tkm/client.h>
#include <tkm/constants.h> #include <tkm/constants.h>
#include "tkm.h"
#include "tkm_nonceg.h"
typedef struct private_tkm_nonceg_t private_tkm_nonceg_t; typedef struct private_tkm_nonceg_t private_tkm_nonceg_t;
/** /**
@@ -31,16 +32,18 @@ struct private_tkm_nonceg_t {
*/ */
tkm_nonceg_t public; tkm_nonceg_t public;
/**
* Context id.
*/
nc_id_type context_id;
}; };
METHOD(nonce_gen_t, get_nonce, bool, METHOD(nonce_gen_t, get_nonce, bool,
private_tkm_nonceg_t *this, size_t size, u_int8_t *buffer) private_tkm_nonceg_t *this, size_t size, u_int8_t *buffer)
{ {
nonce_type nonce; nonce_type nonce;
if (ike_nc_create(this->context_id, size, &nonce) != TKM_OK)
/* request nonce from TKM, the context is not yet used */
const result_type result = ike_nc_create(1, size, &nonce);
if (result != TKM_OK)
{ {
return FALSE; return FALSE;
} }
@@ -77,7 +80,14 @@ tkm_nonceg_t *tkm_nonceg_create()
.destroy = _destroy, .destroy = _destroy,
}, },
}, },
.context_id = tkm->idmgr->acquire_id(tkm->idmgr, TKM_CTX_NONCE),
); );
if (!this->context_id)
{
free(this);
return NULL;
}
return &this->public; return &this->public;
} }