2 * Copyright (C) 2000-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/>
26 #include <gnutls_int.h>
27 #include <gnutls_datum.h>
29 void _gnutls_str_cpy (char *dest
, size_t dest_tot_size
, const char *src
);
30 void _gnutls_mem_cpy (char *dest
, size_t dest_tot_size
, const char *src
,
32 void _gnutls_str_cat (char *dest
, size_t dest_tot_size
, const char *src
);
36 uint8_t *allocd
; /* pointer to allocated data */
37 uint8_t *data
; /* API: pointer to data to copy from */
39 size_t length
; /* API: current length */
42 /* Initialize a buffer */
43 void _gnutls_buffer_init (gnutls_buffer_st
*);
45 /* Free the data in a buffer */
46 void _gnutls_buffer_clear (gnutls_buffer_st
*);
48 /* Set the buffer data to be of zero length */
49 inline static void _gnutls_buffer_reset (gnutls_buffer_st
* buf
)
51 buf
->data
= buf
->allocd
;
55 int _gnutls_buffer_resize (gnutls_buffer_st
*, size_t new_size
);
57 int _gnutls_buffer_append_str (gnutls_buffer_st
*, const char *str
);
58 int _gnutls_buffer_append_data (gnutls_buffer_st
*, const void *data
,
61 #include <gnutls_num.h>
63 void _gnutls_buffer_replace_data( gnutls_buffer_st
* buf
, gnutls_datum_t
* data
);
65 int _gnutls_buffer_append_prefix (gnutls_buffer_st
* buf
, int pfx_size
, size_t data_size
);
67 int _gnutls_buffer_append_mpi (gnutls_buffer_st
* buf
, int pfx_size
, bigint_t
, int lz
);
69 int _gnutls_buffer_append_data_prefix (gnutls_buffer_st
* buf
, int pfx_size
,
70 const void *data
, size_t data_size
);
71 void _gnutls_buffer_pop_data (gnutls_buffer_st
*, void *, size_t * size
);
72 void _gnutls_buffer_pop_datum (gnutls_buffer_st
*, gnutls_datum_t
*,
75 int _gnutls_buffer_pop_prefix (gnutls_buffer_st
* buf
, size_t * data_size
,
78 int _gnutls_buffer_pop_data_prefix (gnutls_buffer_st
* buf
, void *data
,
81 int _gnutls_buffer_pop_datum_prefix (gnutls_buffer_st
* buf
,
82 gnutls_datum_t
* data
);
83 int _gnutls_buffer_to_datum (gnutls_buffer_st
* str
, gnutls_datum_t
* data
);
85 int _gnutls_buffer_escape (gnutls_buffer_st
* dest
, int all
,
86 const char *const invalid_chars
);
87 int _gnutls_buffer_unescape (gnutls_buffer_st
* dest
);
90 /* This feature is available in gcc versions 2.5 and later. */
91 #if __GNUC__ < 2 || (__GNUC__ == 2 && __GNUC_MINOR__ < 5)
92 #define __attribute__(Spec) /* empty */
96 int _gnutls_buffer_append_printf (gnutls_buffer_st
* dest
, const char *fmt
,
98 __attribute__ ((format (printf
, 2, 3)));
100 void _gnutls_buffer_hexprint (gnutls_buffer_st
* str
,
101 const void *data
, size_t len
);
102 void _gnutls_buffer_hexdump (gnutls_buffer_st
* str
, const void *data
,
103 size_t len
, const char *spc
);
104 void _gnutls_buffer_asciiprint (gnutls_buffer_st
* str
,
105 const char *data
, size_t len
);
107 char *_gnutls_bin2hex (const void *old
, size_t oldlen
, char *buffer
,
108 size_t buffer_size
, const char *separator
);
109 int _gnutls_hex2bin (const char * hex_data
, size_t hex_size
, uint8_t * bin_data
,
112 int _gnutls_hostname_compare (const char *certname
, size_t certnamesize
,
113 const char *hostname
, int level
);
118 #define BUFFER_APPEND(b, x, s) { \
119 ret = _gnutls_buffer_append_data(b, x, s); \
126 /* append data prefixed with 4-bytes length field*/
127 #define BUFFER_APPEND_PFX4(b, x, s) { \
128 ret = _gnutls_buffer_append_data_prefix(b, 32, x, s); \
135 #define BUFFER_APPEND_PFX3(b, x, s) { \
136 ret = _gnutls_buffer_append_data_prefix(b, 24, x, s); \
143 #define BUFFER_APPEND_PFX2(b, x, s) { \
144 ret = _gnutls_buffer_append_data_prefix(b, 16, x, s); \
151 #define BUFFER_APPEND_PFX1(b, x, s) { \
152 ret = _gnutls_buffer_append_data_prefix(b, 8, x, s); \
159 #define BUFFER_APPEND_NUM(b, s) { \
160 ret = _gnutls_buffer_append_prefix(b, 32, s); \
167 #define BUFFER_POP(b, x, s) { \
169 _gnutls_buffer_pop_data(b, x, &is); \
171 ret = GNUTLS_E_PARSING_ERROR; \
177 #define BUFFER_POP_DATUM(b, o) { \
179 ret = _gnutls_buffer_pop_datum_prefix(b, &d); \
181 ret = _gnutls_set_datum (o, d.data, d.size); \
188 #define BUFFER_POP_NUM(b, o) { \
190 ret = _gnutls_buffer_pop_prefix(b, &s, 0); \