2 * Copyright (C) 2001-2012 Free Software Foundation, Inc.
4 * Author: Nikos Mavrogiannopoulos
6 * This file is part of GnuTLS.
8 * The GnuTLS is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Lesser General Public License
10 * as published by the Free Software Foundation; either version 2.1 of
11 * the License, or (at your option) any later version.
13 * This library is distributed in the hope that it will be useful, but
14 * WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * Lesser General Public License for more details.
18 * You should have received a copy of the GNU Lesser General Public License
19 * along with this program. If not, see <http://www.gnu.org/licenses/>
23 /* contains functions that make it easier to
24 * write vectors of <size|data>. The destination size
25 * should be preallocated (datum.size+(bits/8))
28 #include <gnutls_int.h>
29 #include <gnutls_num.h>
30 #include <gnutls_datum.h>
31 #include <gnutls_errors.h>
34 _gnutls_set_datum(gnutls_datum_t * dat, const void *data, size_t data_size)
36 if (data_size == 0 || data == NULL) {
42 dat->data = gnutls_malloc(data_size);
43 if (dat->data == NULL)
44 return GNUTLS_E_MEMORY_ERROR;
46 dat->size = data_size;
47 memcpy(dat->data, data, data_size);
53 _gnutls_datum_append(gnutls_datum_t * dst, const void *data,
57 dst->data = gnutls_realloc_fast(dst->data, data_size + dst->size);
58 if (dst->data == NULL)
59 return GNUTLS_E_MEMORY_ERROR;
61 memcpy(&dst->data[dst->size], data, data_size);
62 dst->size += data_size;