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 3 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
,
37 if (data_size
== 0 || data
== NULL
)
44 dat
->data
= gnutls_malloc (data_size
);
45 if (dat
->data
== NULL
)
46 return GNUTLS_E_MEMORY_ERROR
;
48 dat
->size
= data_size
;
49 memcpy (dat
->data
, data
, data_size
);
55 _gnutls_datum_append (gnutls_datum_t
* dst
, const void *data
,
59 dst
->data
= gnutls_realloc (dst
->data
, data_size
+ dst
->size
);
60 if (dst
->data
== NULL
)
61 return GNUTLS_E_MEMORY_ERROR
;
63 memcpy (&dst
->data
[dst
->size
], data
, data_size
);
64 dst
->size
+= data_size
;
70 _gnutls_free_datum (gnutls_datum_t
* dat
)
72 if (dat
->data
!= NULL
)
73 gnutls_free (dat
->data
);