Blame lib/datum.h

Packit 549fdc
/*
Packit 549fdc
 * Copyright (C) 2000-2012 Free Software Foundation, Inc.
Packit 549fdc
 *
Packit 549fdc
 * Author: Nikos Mavrogiannopoulos
Packit 549fdc
 *
Packit 549fdc
 * This file is part of GnuTLS.
Packit 549fdc
 *
Packit 549fdc
 * The GnuTLS is free software; you can redistribute it and/or
Packit 549fdc
 * modify it under the terms of the GNU Lesser General Public License
Packit 549fdc
 * as published by the Free Software Foundation; either version 2.1 of
Packit 549fdc
 * the License, or (at your option) any later version.
Packit 549fdc
 *
Packit 549fdc
 * This library is distributed in the hope that it will be useful, but
Packit 549fdc
 * WITHOUT ANY WARRANTY; without even the implied warranty of
Packit 549fdc
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
Packit 549fdc
 * Lesser General Public License for more details.
Packit 549fdc
 *
Packit 549fdc
 * You should have received a copy of the GNU Lesser General Public License
Packit 549fdc
 * along with this program.  If not, see <http://www.gnu.org/licenses/>
Packit 549fdc
 *
Packit 549fdc
 */
Packit 549fdc
Packit 549fdc
#ifndef GNUTLS_DATUM_H
Packit 549fdc
#define GNUTLS_DATUM_H
Packit 549fdc
Packit 549fdc
# include "gnutls_int.h"
Packit 549fdc
Packit 549fdc
/* This will copy the provided data in @dat. If the provided data are
Packit 549fdc
 * NULL or zero-size @dat will be NULL as well.
Packit 549fdc
 */
Packit 549fdc
int _gnutls_set_datum(gnutls_datum_t * dat, const void *data,
Packit 549fdc
		      size_t data_size);
Packit 549fdc
Packit 549fdc
/* This will always return a non-NULL, and zero-terminated string in @dat.
Packit 549fdc
 */
Packit 549fdc
int _gnutls_set_strdatum(gnutls_datum_t * dat, const void *data,
Packit 549fdc
			 size_t data_size);
Packit 549fdc
Packit 549fdc
Packit 549fdc
inline static
Packit 549fdc
void _gnutls_free_datum(gnutls_datum_t * dat)
Packit 549fdc
{
Packit 549fdc
	if (dat == NULL)
Packit 549fdc
		return;
Packit 549fdc
Packit 549fdc
	if (dat->data != NULL)
Packit 549fdc
		gnutls_free(dat->data);
Packit 549fdc
Packit 549fdc
	dat->data = NULL;
Packit 549fdc
	dat->size = 0;
Packit 549fdc
}
Packit 549fdc
Packit 549fdc
inline static
Packit 549fdc
void _gnutls_free_temp_key_datum(gnutls_datum_t * dat)
Packit 549fdc
{
Packit 549fdc
	if (dat->data != NULL) {
Packit 549fdc
		zeroize_temp_key(dat->data, dat->size);
Packit 549fdc
		gnutls_free(dat->data);
Packit 549fdc
	}
Packit 549fdc
Packit 549fdc
	dat->data = NULL;
Packit 549fdc
	dat->size = 0;
Packit 549fdc
}
Packit 549fdc
Packit 549fdc
inline static
Packit 549fdc
void _gnutls_free_key_datum(gnutls_datum_t * dat)
Packit 549fdc
{
Packit 549fdc
	if (dat->data != NULL) {
Packit 549fdc
		zeroize_key(dat->data, dat->size);
Packit 549fdc
		gnutls_free(dat->data);
Packit 549fdc
	}
Packit 549fdc
Packit 549fdc
	dat->data = NULL;
Packit 549fdc
	dat->size = 0;
Packit 549fdc
}
Packit 549fdc
Packit 549fdc
#endif