Blame lib/datum.h

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