documented update
[gnutls.git] / lib / gnutls_str.h
blob965d2fc3a740ba5e80fc31149a00d65014fb6365
1 /*
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/>
23 #ifndef GNUTLS_STR_H
24 #define GNUTLS_STR_H
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,
31 size_t src_size);
32 void _gnutls_str_cat (char *dest, size_t dest_tot_size, const char *src);
34 typedef struct
36 uint8_t *allocd; /* pointer to allocated data */
37 uint8_t *data; /* API: pointer to data to copy from */
38 size_t max_length;
39 size_t length; /* API: current length */
40 } gnutls_buffer_st;
42 void _gnutls_buffer_init (gnutls_buffer_st *);
43 void _gnutls_buffer_clear (gnutls_buffer_st *);
44 inline static void _gnutls_buffer_reset (gnutls_buffer_st * buf)
46 buf->data = buf->allocd;
47 buf->length = 0;
50 int _gnutls_buffer_resize (gnutls_buffer_st *, size_t new_size);
52 int _gnutls_buffer_append_str (gnutls_buffer_st *, const char *str);
53 int _gnutls_buffer_append_data (gnutls_buffer_st *, const void *data,
54 size_t data_size);
56 #include <gnutls_num.h>
58 void _gnutls_buffer_replace_data( gnutls_buffer_st * buf, gnutls_datum_t * data);
60 int _gnutls_buffer_append_prefix (gnutls_buffer_st * buf, int pfx_size, size_t data_size);
62 int _gnutls_buffer_append_mpi (gnutls_buffer_st * buf, int pfx_size, bigint_t, int lz);
64 int _gnutls_buffer_append_data_prefix (gnutls_buffer_st * buf, int pfx_size,
65 const void *data, size_t data_size);
66 void _gnutls_buffer_pop_data (gnutls_buffer_st *, void *, size_t * size);
67 void _gnutls_buffer_pop_datum (gnutls_buffer_st *, gnutls_datum_t *,
68 size_t max_size);
70 int _gnutls_buffer_pop_prefix (gnutls_buffer_st * buf, size_t * data_size,
71 int check);
73 int _gnutls_buffer_pop_data_prefix (gnutls_buffer_st * buf, void *data,
74 size_t * data_size);
76 int _gnutls_buffer_pop_datum_prefix (gnutls_buffer_st * buf,
77 gnutls_datum_t * data);
78 int _gnutls_buffer_to_datum (gnutls_buffer_st * str, gnutls_datum_t * data);
80 int _gnutls_buffer_escape (gnutls_buffer_st * dest, int all,
81 const char *const invalid_chars);
82 int _gnutls_buffer_unescape (gnutls_buffer_st * dest);
84 #ifndef __attribute__
85 /* This feature is available in gcc versions 2.5 and later. */
86 #if __GNUC__ < 2 || (__GNUC__ == 2 && __GNUC_MINOR__ < 5)
87 #define __attribute__(Spec) /* empty */
88 #endif
89 #endif
91 int _gnutls_buffer_append_printf (gnutls_buffer_st * dest, const char *fmt,
92 ...)
93 __attribute__ ((format (printf, 2, 3)));
95 void _gnutls_buffer_hexprint (gnutls_buffer_st * str,
96 const void *data, size_t len);
97 void _gnutls_buffer_hexdump (gnutls_buffer_st * str, const void *data,
98 size_t len, const char *spc);
99 void _gnutls_buffer_asciiprint (gnutls_buffer_st * str,
100 const char *data, size_t len);
102 char *_gnutls_bin2hex (const void *old, size_t oldlen, char *buffer,
103 size_t buffer_size, const char *separator);
104 int _gnutls_hex2bin (const char * hex_data, size_t hex_size, uint8_t * bin_data,
105 size_t * bin_size);
107 int _gnutls_hostname_compare (const char *certname, size_t certnamesize,
108 const char *hostname, int level);
110 #define MAX_CN 256
111 #define MAX_DN 1024
113 #define BUFFER_APPEND(b, x, s) { \
114 ret = _gnutls_buffer_append_data(b, x, s); \
115 if (ret < 0) { \
116 gnutls_assert(); \
117 return ret; \
121 #define BUFFER_APPEND_PFX(b, x, s) { \
122 ret = _gnutls_buffer_append_data_prefix(b, 32, x, s); \
123 if (ret < 0) { \
124 gnutls_assert(); \
125 return ret; \
129 #define BUFFER_APPEND_NUM(b, s) { \
130 ret = _gnutls_buffer_append_prefix(b, 32, s); \
131 if (ret < 0) { \
132 gnutls_assert(); \
133 return ret; \
138 #define BUFFER_POP(b, x, s) { \
139 size_t is = s; \
140 _gnutls_buffer_pop_data(b, x, &is); \
141 if (is != s) { \
142 ret = GNUTLS_E_PARSING_ERROR; \
143 gnutls_assert(); \
144 goto error; \
148 #define BUFFER_POP_DATUM(b, o) { \
149 gnutls_datum_t d; \
150 ret = _gnutls_buffer_pop_datum_prefix(b, &d); \
151 if (ret >= 0) \
152 ret = _gnutls_set_datum (o, d.data, d.size); \
153 if (ret < 0) { \
154 gnutls_assert(); \
155 goto error; \
159 #define BUFFER_POP_NUM(b, o) { \
160 size_t s; \
161 ret = _gnutls_buffer_pop_prefix(b, &s, 0); \
162 if (ret < 0) { \
163 gnutls_assert(); \
164 goto error; \
166 o = s; \
169 #endif