*/
static status_t destroy(private_nonce_payload_t *this)
{
- if (this->nonce.ptr)
+ if (this->nonce.ptr != NULL)
{
allocator_free(this->nonce.ptr);
}
if (nonce.len >= 16 && nonce.len <= 256)
{
this->nonce.len = nonce.len;
- this->nonce.ptr = allocator_clone_bytes(nonce.ptr, nonce.len);
- if (this->nonce.ptr == NULL)
- {
- return OUT_OF_RES;
- }
+ this->nonce.ptr = nonce.ptr;
this->payload_length = NONCE_PAYLOAD_HEADER_LENGTH + nonce.len;
return SUCCESS;
}
static status_t get_nonce(private_nonce_payload_t *this, chunk_t *nonce)
{
nonce->len = this->nonce.len;
- nonce->ptr = allocator_clone_bytes(this->nonce.ptr, this->nonce.len);
- if (nonce->ptr == NULL)
- {
- return OUT_OF_RES;
- }
+ nonce->ptr = this->nonce.ptr;
return SUCCESS;
}
/**
* @brief Set the nonce value.
+ *
+ * The nonce must have length between 16 and 256 bytes
*
* @param this calling nonce_payload_t object
- * @param nonce chunk containing the nonce, will be cloned
- * @return SUCCESS in any case
+ * @param nonce chunk containing the nonce, will NOT be cloned
+ * @return
+ * - SUCCESS or
+ * - INVALID_ARG, if nonce has an invalid size
*/
status_t (*set_nonce) (nonce_payload_t *this, chunk_t nonce);
* @brief Get the nonce value.
*
* @param this calling nonce_payload_t object
- * @param[out] nonce chunk where the cloned nonce data is located
+ * @param[out] nonce chunk where nonce data is located (NOT cloned)
* @return SUCCESS in any case
*/
status_t (*get_nonce) (nonce_payload_t *this, chunk_t *nonce);