Line | Count | Source (jump to first uncovered line) |
1 | | /* |
2 | | * Copyright (C) 2000-2012 Free Software Foundation, Inc. |
3 | | * Copyright (C) 2016-2017 Red Hat, Inc. |
4 | | * |
5 | | * Author: Nikos Mavrogiannopoulos |
6 | | * |
7 | | * This file is part of GnuTLS. |
8 | | * |
9 | | * The GnuTLS is free software; you can redistribute it and/or |
10 | | * modify it under the terms of the GNU Lesser General Public License |
11 | | * as published by the Free Software Foundation; either version 2.1 of |
12 | | * the License, or (at your option) any later version. |
13 | | * |
14 | | * This library is distributed in the hope that it will be useful, but |
15 | | * WITHOUT ANY WARRANTY; without even the implied warranty of |
16 | | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
17 | | * Lesser General Public License for more details. |
18 | | * |
19 | | * You should have received a copy of the GNU Lesser General Public License |
20 | | * along with this program. If not, see <https://www.gnu.org/licenses/> |
21 | | * |
22 | | */ |
23 | | |
24 | | #ifndef GNUTLS_LIB_STR_H |
25 | | # define GNUTLS_LIB_STR_H |
26 | | |
27 | | # include <config.h> |
28 | | # include "gnutls_int.h" |
29 | | # include "errors.h" |
30 | | # include <datum.h> |
31 | | # include <c-ctype.h> |
32 | | # include "errors.h" |
33 | | |
34 | | # ifdef HAVE_DCGETTEXT |
35 | | # include "gettext.h" |
36 | 0 | # define _(String) dgettext (PACKAGE, String) |
37 | | # define N_(String) gettext_noop (String) |
38 | | # else |
39 | | # define _(String) String |
40 | | # define N_(String) String |
41 | | # endif |
42 | | |
43 | | int gnutls_utf8_password_normalize(const uint8_t * password, |
44 | | unsigned password_len, gnutls_datum_t * out, |
45 | | unsigned flags); |
46 | | |
47 | | # define _gnutls_utf8_password_normalize(p, plen, out, ignore_errs) \ |
48 | 0 | gnutls_utf8_password_normalize((unsigned char*)p, plen, out, \ |
49 | 0 | ignore_errs?(GNUTLS_UTF8_IGNORE_ERRS):0) |
50 | | |
51 | | int _gnutls_idna_email_map(const char *input, unsigned ilen, |
52 | | gnutls_datum_t * output); |
53 | | int _gnutls_idna_email_reverse_map(const char *input, unsigned ilen, |
54 | | gnutls_datum_t * output); |
55 | | |
56 | | inline static unsigned _gnutls_str_is_print(const char *str, unsigned size) |
57 | 0 | { |
58 | 0 | unsigned i; |
59 | 0 | for (i = 0; i < size; i++) { |
60 | 0 | if (!c_isprint(str[i])) |
61 | 0 | return 0; |
62 | 0 | } |
63 | 0 | return 1; |
64 | 0 | } Unexecuted instantiation: common.c:_gnutls_str_is_print Unexecuted instantiation: crl.c:_gnutls_str_is_print Unexecuted instantiation: crq.c:_gnutls_str_is_print Unexecuted instantiation: dn.c:_gnutls_str_is_print Unexecuted instantiation: extensions.c:_gnutls_str_is_print Unexecuted instantiation: hostname-verify.c:_gnutls_str_is_print Unexecuted instantiation: key_decode.c:_gnutls_str_is_print Unexecuted instantiation: key_encode.c:_gnutls_str_is_print Unexecuted instantiation: mpi.c:_gnutls_str_is_print Unexecuted instantiation: ocsp.c:_gnutls_str_is_print Unexecuted instantiation: output.c:_gnutls_str_is_print Unexecuted instantiation: pkcs12.c:_gnutls_str_is_print Unexecuted instantiation: pkcs12_bag.c:_gnutls_str_is_print Unexecuted instantiation: pkcs12_encr.c:_gnutls_str_is_print Unexecuted instantiation: pkcs7-crypt.c:_gnutls_str_is_print Unexecuted instantiation: privkey_openssl.c:_gnutls_str_is_print Unexecuted instantiation: privkey_pkcs8.c:_gnutls_str_is_print Unexecuted instantiation: privkey_pkcs8_pbes1.c:_gnutls_str_is_print Unexecuted instantiation: prov-seed.c:_gnutls_str_is_print Unexecuted instantiation: sign.c:_gnutls_str_is_print Unexecuted instantiation: time.c:_gnutls_str_is_print Unexecuted instantiation: tls_features.c:_gnutls_str_is_print Unexecuted instantiation: verify-high.c:_gnutls_str_is_print Unexecuted instantiation: verify-high2.c:_gnutls_str_is_print Unexecuted instantiation: verify.c:_gnutls_str_is_print Unexecuted instantiation: virt-san.c:_gnutls_str_is_print Unexecuted instantiation: x509.c:_gnutls_str_is_print Unexecuted instantiation: x509_dn.c:_gnutls_str_is_print Unexecuted instantiation: x509_ext.c:_gnutls_str_is_print Unexecuted instantiation: x509_write.c:_gnutls_str_is_print Unexecuted instantiation: attributes.c:_gnutls_str_is_print Unexecuted instantiation: email-verify.c:_gnutls_str_is_print Unexecuted instantiation: ip.c:_gnutls_str_is_print Unexecuted instantiation: krb5.c:_gnutls_str_is_print Unexecuted instantiation: name_constraints.c:_gnutls_str_is_print |
65 | | |
66 | | inline static unsigned _gnutls_dnsname_is_valid(const char *str, unsigned size) |
67 | 0 | { |
68 | 0 | unsigned i; |
69 | 0 | for (i = 0; i < size; i++) { |
70 | 0 | if (!(c_isalnum(str[i]) || str[i] == '-' || str[i] == '.')) |
71 | 0 | return 0; |
72 | 0 | } |
73 | 0 | return 1; |
74 | 0 | } Unexecuted instantiation: common.c:_gnutls_dnsname_is_valid Unexecuted instantiation: crl.c:_gnutls_dnsname_is_valid Unexecuted instantiation: crq.c:_gnutls_dnsname_is_valid Unexecuted instantiation: dn.c:_gnutls_dnsname_is_valid Unexecuted instantiation: extensions.c:_gnutls_dnsname_is_valid Unexecuted instantiation: hostname-verify.c:_gnutls_dnsname_is_valid Unexecuted instantiation: key_decode.c:_gnutls_dnsname_is_valid Unexecuted instantiation: key_encode.c:_gnutls_dnsname_is_valid Unexecuted instantiation: mpi.c:_gnutls_dnsname_is_valid Unexecuted instantiation: ocsp.c:_gnutls_dnsname_is_valid Unexecuted instantiation: output.c:_gnutls_dnsname_is_valid Unexecuted instantiation: pkcs12.c:_gnutls_dnsname_is_valid Unexecuted instantiation: pkcs12_bag.c:_gnutls_dnsname_is_valid Unexecuted instantiation: pkcs12_encr.c:_gnutls_dnsname_is_valid Unexecuted instantiation: pkcs7-crypt.c:_gnutls_dnsname_is_valid Unexecuted instantiation: privkey_openssl.c:_gnutls_dnsname_is_valid Unexecuted instantiation: privkey_pkcs8.c:_gnutls_dnsname_is_valid Unexecuted instantiation: privkey_pkcs8_pbes1.c:_gnutls_dnsname_is_valid Unexecuted instantiation: prov-seed.c:_gnutls_dnsname_is_valid Unexecuted instantiation: sign.c:_gnutls_dnsname_is_valid Unexecuted instantiation: time.c:_gnutls_dnsname_is_valid Unexecuted instantiation: tls_features.c:_gnutls_dnsname_is_valid Unexecuted instantiation: verify-high.c:_gnutls_dnsname_is_valid Unexecuted instantiation: verify-high2.c:_gnutls_dnsname_is_valid Unexecuted instantiation: verify.c:_gnutls_dnsname_is_valid Unexecuted instantiation: virt-san.c:_gnutls_dnsname_is_valid Unexecuted instantiation: x509.c:_gnutls_dnsname_is_valid Unexecuted instantiation: x509_dn.c:_gnutls_dnsname_is_valid Unexecuted instantiation: x509_ext.c:_gnutls_dnsname_is_valid Unexecuted instantiation: x509_write.c:_gnutls_dnsname_is_valid Unexecuted instantiation: attributes.c:_gnutls_dnsname_is_valid Unexecuted instantiation: email-verify.c:_gnutls_dnsname_is_valid Unexecuted instantiation: ip.c:_gnutls_dnsname_is_valid Unexecuted instantiation: krb5.c:_gnutls_dnsname_is_valid Unexecuted instantiation: name_constraints.c:_gnutls_dnsname_is_valid |
75 | | |
76 | | inline static bool _gnutls_has_embedded_null(const char *str, unsigned size) |
77 | 0 | { |
78 | 0 | if (strlen(str) != size) |
79 | 0 | return true; |
80 | 0 | return false; |
81 | 0 | } Unexecuted instantiation: common.c:_gnutls_has_embedded_null Unexecuted instantiation: crl.c:_gnutls_has_embedded_null Unexecuted instantiation: crq.c:_gnutls_has_embedded_null Unexecuted instantiation: dn.c:_gnutls_has_embedded_null Unexecuted instantiation: extensions.c:_gnutls_has_embedded_null Unexecuted instantiation: hostname-verify.c:_gnutls_has_embedded_null Unexecuted instantiation: key_decode.c:_gnutls_has_embedded_null Unexecuted instantiation: key_encode.c:_gnutls_has_embedded_null Unexecuted instantiation: mpi.c:_gnutls_has_embedded_null Unexecuted instantiation: ocsp.c:_gnutls_has_embedded_null Unexecuted instantiation: output.c:_gnutls_has_embedded_null Unexecuted instantiation: pkcs12.c:_gnutls_has_embedded_null Unexecuted instantiation: pkcs12_bag.c:_gnutls_has_embedded_null Unexecuted instantiation: pkcs12_encr.c:_gnutls_has_embedded_null Unexecuted instantiation: pkcs7-crypt.c:_gnutls_has_embedded_null Unexecuted instantiation: privkey_openssl.c:_gnutls_has_embedded_null Unexecuted instantiation: privkey_pkcs8.c:_gnutls_has_embedded_null Unexecuted instantiation: privkey_pkcs8_pbes1.c:_gnutls_has_embedded_null Unexecuted instantiation: prov-seed.c:_gnutls_has_embedded_null Unexecuted instantiation: sign.c:_gnutls_has_embedded_null Unexecuted instantiation: time.c:_gnutls_has_embedded_null Unexecuted instantiation: tls_features.c:_gnutls_has_embedded_null Unexecuted instantiation: verify-high.c:_gnutls_has_embedded_null Unexecuted instantiation: verify-high2.c:_gnutls_has_embedded_null Unexecuted instantiation: verify.c:_gnutls_has_embedded_null Unexecuted instantiation: virt-san.c:_gnutls_has_embedded_null Unexecuted instantiation: x509.c:_gnutls_has_embedded_null Unexecuted instantiation: x509_dn.c:_gnutls_has_embedded_null Unexecuted instantiation: x509_ext.c:_gnutls_has_embedded_null Unexecuted instantiation: x509_write.c:_gnutls_has_embedded_null Unexecuted instantiation: attributes.c:_gnutls_has_embedded_null Unexecuted instantiation: email-verify.c:_gnutls_has_embedded_null Unexecuted instantiation: ip.c:_gnutls_has_embedded_null Unexecuted instantiation: krb5.c:_gnutls_has_embedded_null Unexecuted instantiation: name_constraints.c:_gnutls_has_embedded_null |
82 | | |
83 | | void _gnutls_str_cpy(char *dest, size_t dest_tot_size, const char *src); |
84 | | void _gnutls_str_cat(char *dest, size_t dest_tot_size, const char *src); |
85 | | |
86 | | typedef struct gnutls_buffer_st { |
87 | | uint8_t *allocd; /* pointer to allocated data */ |
88 | | uint8_t *data; /* API: pointer to data to copy from */ |
89 | | size_t max_length; |
90 | | size_t length; /* API: current length */ |
91 | | } gnutls_buffer_st; |
92 | | |
93 | | /* Initialize a buffer */ |
94 | | void _gnutls_buffer_init(gnutls_buffer_st *); |
95 | | |
96 | | /* Free the data in a buffer */ |
97 | | void _gnutls_buffer_clear(gnutls_buffer_st *); |
98 | | |
99 | | /* Set the buffer data to be of zero length */ |
100 | | inline static void _gnutls_buffer_reset(gnutls_buffer_st * buf) |
101 | 0 | { |
102 | 0 | buf->data = buf->allocd; |
103 | 0 | buf->length = 0; |
104 | 0 | } Unexecuted instantiation: common.c:_gnutls_buffer_reset Unexecuted instantiation: crl.c:_gnutls_buffer_reset Unexecuted instantiation: crq.c:_gnutls_buffer_reset Unexecuted instantiation: dn.c:_gnutls_buffer_reset Unexecuted instantiation: extensions.c:_gnutls_buffer_reset Unexecuted instantiation: hostname-verify.c:_gnutls_buffer_reset Unexecuted instantiation: key_decode.c:_gnutls_buffer_reset Unexecuted instantiation: key_encode.c:_gnutls_buffer_reset Unexecuted instantiation: mpi.c:_gnutls_buffer_reset Unexecuted instantiation: ocsp.c:_gnutls_buffer_reset Unexecuted instantiation: output.c:_gnutls_buffer_reset Unexecuted instantiation: pkcs12.c:_gnutls_buffer_reset Unexecuted instantiation: pkcs12_bag.c:_gnutls_buffer_reset Unexecuted instantiation: pkcs12_encr.c:_gnutls_buffer_reset Unexecuted instantiation: pkcs7-crypt.c:_gnutls_buffer_reset Unexecuted instantiation: privkey_openssl.c:_gnutls_buffer_reset Unexecuted instantiation: privkey_pkcs8.c:_gnutls_buffer_reset Unexecuted instantiation: privkey_pkcs8_pbes1.c:_gnutls_buffer_reset Unexecuted instantiation: prov-seed.c:_gnutls_buffer_reset Unexecuted instantiation: sign.c:_gnutls_buffer_reset Unexecuted instantiation: time.c:_gnutls_buffer_reset Unexecuted instantiation: tls_features.c:_gnutls_buffer_reset Unexecuted instantiation: verify-high.c:_gnutls_buffer_reset Unexecuted instantiation: verify-high2.c:_gnutls_buffer_reset Unexecuted instantiation: verify.c:_gnutls_buffer_reset Unexecuted instantiation: virt-san.c:_gnutls_buffer_reset Unexecuted instantiation: x509.c:_gnutls_buffer_reset Unexecuted instantiation: x509_dn.c:_gnutls_buffer_reset Unexecuted instantiation: x509_ext.c:_gnutls_buffer_reset Unexecuted instantiation: x509_write.c:_gnutls_buffer_reset Unexecuted instantiation: attributes.c:_gnutls_buffer_reset Unexecuted instantiation: email-verify.c:_gnutls_buffer_reset Unexecuted instantiation: ip.c:_gnutls_buffer_reset Unexecuted instantiation: krb5.c:_gnutls_buffer_reset Unexecuted instantiation: name_constraints.c:_gnutls_buffer_reset |
105 | | |
106 | | int _gnutls_buffer_resize(gnutls_buffer_st *, size_t new_size); |
107 | | |
108 | | int _gnutls_buffer_append_str(gnutls_buffer_st *, const char *str); |
109 | | |
110 | 0 | # define _gnutls_buffer_append_data gnutls_buffer_append_data |
111 | | |
112 | | # include <num.h> |
113 | | |
114 | | int _gnutls_buffer_append_prefix(gnutls_buffer_st * buf, int pfx_size, |
115 | | size_t data_size); |
116 | | |
117 | | int _gnutls_buffer_append_mpi(gnutls_buffer_st * buf, int pfx_size, |
118 | | bigint_t, int lz); |
119 | | |
120 | | int _gnutls_buffer_append_fixed_mpi(gnutls_buffer_st * buf, |
121 | | bigint_t mpi, unsigned size); |
122 | | |
123 | | int _gnutls_buffer_append_data_prefix(gnutls_buffer_st * buf, int pfx_size, |
124 | | const void *data, size_t data_size); |
125 | | int _gnutls_buffer_pop_data(gnutls_buffer_st *, void *, size_t size); |
126 | | void _gnutls_buffer_pop_datum(gnutls_buffer_st *, gnutls_datum_t *, |
127 | | size_t max_size); |
128 | | |
129 | | /* 32-bit prefix */ |
130 | | int _gnutls_buffer_pop_prefix32(gnutls_buffer_st * buf, size_t *data_size, |
131 | | int check); |
132 | | int _gnutls_buffer_pop_prefix24(gnutls_buffer_st * buf, size_t *data_size, |
133 | | int check); |
134 | | int _gnutls_buffer_pop_prefix16(gnutls_buffer_st * buf, size_t *data_size, |
135 | | int check); |
136 | | int _gnutls_buffer_pop_prefix8(gnutls_buffer_st *, uint8_t *, int check); |
137 | | |
138 | | /* 32-bit prefix */ |
139 | | int _gnutls_buffer_pop_datum_prefix32(gnutls_buffer_st * buf, |
140 | | gnutls_datum_t * data); |
141 | | |
142 | | /* 24-bit prefix */ |
143 | | int _gnutls_buffer_pop_datum_prefix24(gnutls_buffer_st * buf, |
144 | | gnutls_datum_t * data); |
145 | | |
146 | | /* 16-bit prefix */ |
147 | | int _gnutls_buffer_pop_datum_prefix16(gnutls_buffer_st * buf, |
148 | | gnutls_datum_t * data); |
149 | | |
150 | | /* 8-bit prefix */ |
151 | | int _gnutls_buffer_pop_datum_prefix8(gnutls_buffer_st * buf, |
152 | | gnutls_datum_t * data); |
153 | | |
154 | | int _gnutls_buffer_to_datum(gnutls_buffer_st * str, gnutls_datum_t * data, |
155 | | unsigned is_str); |
156 | | |
157 | | inline static |
158 | | void _gnutls_ro_buffer_from_datum(gnutls_buffer_st * str, gnutls_datum_t * data) |
159 | 0 | { |
160 | 0 | _gnutls_buffer_init(str); |
161 | 0 | str->length = data->size; |
162 | 0 | str->max_length = data->size; |
163 | 0 | str->data = data->data; |
164 | 0 | } Unexecuted instantiation: common.c:_gnutls_ro_buffer_from_datum Unexecuted instantiation: crl.c:_gnutls_ro_buffer_from_datum Unexecuted instantiation: crq.c:_gnutls_ro_buffer_from_datum Unexecuted instantiation: dn.c:_gnutls_ro_buffer_from_datum Unexecuted instantiation: extensions.c:_gnutls_ro_buffer_from_datum Unexecuted instantiation: hostname-verify.c:_gnutls_ro_buffer_from_datum Unexecuted instantiation: key_decode.c:_gnutls_ro_buffer_from_datum Unexecuted instantiation: key_encode.c:_gnutls_ro_buffer_from_datum Unexecuted instantiation: mpi.c:_gnutls_ro_buffer_from_datum Unexecuted instantiation: ocsp.c:_gnutls_ro_buffer_from_datum Unexecuted instantiation: output.c:_gnutls_ro_buffer_from_datum Unexecuted instantiation: pkcs12.c:_gnutls_ro_buffer_from_datum Unexecuted instantiation: pkcs12_bag.c:_gnutls_ro_buffer_from_datum Unexecuted instantiation: pkcs12_encr.c:_gnutls_ro_buffer_from_datum Unexecuted instantiation: pkcs7-crypt.c:_gnutls_ro_buffer_from_datum Unexecuted instantiation: privkey_openssl.c:_gnutls_ro_buffer_from_datum Unexecuted instantiation: privkey_pkcs8.c:_gnutls_ro_buffer_from_datum Unexecuted instantiation: privkey_pkcs8_pbes1.c:_gnutls_ro_buffer_from_datum Unexecuted instantiation: prov-seed.c:_gnutls_ro_buffer_from_datum Unexecuted instantiation: sign.c:_gnutls_ro_buffer_from_datum Unexecuted instantiation: time.c:_gnutls_ro_buffer_from_datum Unexecuted instantiation: tls_features.c:_gnutls_ro_buffer_from_datum Unexecuted instantiation: verify-high.c:_gnutls_ro_buffer_from_datum Unexecuted instantiation: verify-high2.c:_gnutls_ro_buffer_from_datum Unexecuted instantiation: verify.c:_gnutls_ro_buffer_from_datum Unexecuted instantiation: virt-san.c:_gnutls_ro_buffer_from_datum Unexecuted instantiation: x509.c:_gnutls_ro_buffer_from_datum Unexecuted instantiation: x509_dn.c:_gnutls_ro_buffer_from_datum Unexecuted instantiation: x509_ext.c:_gnutls_ro_buffer_from_datum Unexecuted instantiation: x509_write.c:_gnutls_ro_buffer_from_datum Unexecuted instantiation: attributes.c:_gnutls_ro_buffer_from_datum Unexecuted instantiation: email-verify.c:_gnutls_ro_buffer_from_datum Unexecuted instantiation: ip.c:_gnutls_ro_buffer_from_datum Unexecuted instantiation: krb5.c:_gnutls_ro_buffer_from_datum Unexecuted instantiation: name_constraints.c:_gnutls_ro_buffer_from_datum |
165 | | |
166 | | int |
167 | | _gnutls_buffer_append_escape(gnutls_buffer_st * dest, const void *data, |
168 | | size_t data_size, const char *invalid_chars); |
169 | | int _gnutls_buffer_unescape(gnutls_buffer_st * dest); |
170 | | |
171 | | # ifndef __attribute__ |
172 | | /* This feature is available in gcc versions 2.5 and later. */ |
173 | | # if __GNUC__ < 2 || (__GNUC__ == 2 && __GNUC_MINOR__ < 5) |
174 | | # define __attribute__(Spec) /* empty */ |
175 | | # endif |
176 | | # endif |
177 | | |
178 | | int _gnutls_buffer_append_printf(gnutls_buffer_st * dest, const char *fmt, ...) |
179 | | __attribute__((format(printf, 2, 3))); |
180 | | |
181 | | void _gnutls_buffer_hexprint(gnutls_buffer_st * str, |
182 | | const void *data, size_t len); |
183 | | int _gnutls_buffer_base64print(gnutls_buffer_st * str, |
184 | | const void *data, size_t len); |
185 | | void _gnutls_buffer_hexdump(gnutls_buffer_st * str, const void *data, |
186 | | size_t len, const char *spc); |
187 | | void _gnutls_buffer_asciiprint(gnutls_buffer_st * str, |
188 | | const char *data, size_t len); |
189 | | |
190 | | char *_gnutls_bin2hex(const void *old, size_t oldlen, char *buffer, |
191 | | size_t buffer_size, const char *separator); |
192 | | int _gnutls_hex2bin(const char *hex_data, size_t hex_size, |
193 | | uint8_t * bin_data, size_t *bin_size); |
194 | | |
195 | | int _gnutls_hostname_compare(const char *certname, size_t certnamesize, |
196 | | const char *hostname, unsigned vflags); |
197 | | |
198 | | # define MAX_CN 256 |
199 | | # define MAX_DN 1024 |
200 | | |
201 | | # define BUFFER_APPEND(b, x, s) { \ |
202 | | ret = _gnutls_buffer_append_data(b, x, s); \ |
203 | | if (ret < 0) { \ |
204 | | gnutls_assert(); \ |
205 | | return ret; \ |
206 | | } \ |
207 | | } |
208 | | |
209 | | /* append data prefixed with 4-bytes length field*/ |
210 | | # define BUFFER_APPEND_PFX4(b, x, s) { \ |
211 | | ret = _gnutls_buffer_append_data_prefix(b, 32, x, s); \ |
212 | | if (ret < 0) { \ |
213 | | gnutls_assert(); \ |
214 | | return ret; \ |
215 | | } \ |
216 | | } |
217 | | |
218 | | # define BUFFER_APPEND_PFX3(b, x, s) { \ |
219 | | ret = _gnutls_buffer_append_data_prefix(b, 24, x, s); \ |
220 | | if (ret < 0) { \ |
221 | | gnutls_assert(); \ |
222 | | return ret; \ |
223 | | } \ |
224 | | } |
225 | | |
226 | | # define BUFFER_APPEND_PFX2(b, x, s) { \ |
227 | | ret = _gnutls_buffer_append_data_prefix(b, 16, x, s); \ |
228 | | if (ret < 0) { \ |
229 | | gnutls_assert(); \ |
230 | | return ret; \ |
231 | | } \ |
232 | | } |
233 | | |
234 | | # define BUFFER_APPEND_PFX1(b, x, s) { \ |
235 | | ret = _gnutls_buffer_append_data_prefix(b, 8, x, s); \ |
236 | | if (ret < 0) { \ |
237 | | gnutls_assert(); \ |
238 | | return ret; \ |
239 | | } \ |
240 | | } |
241 | | |
242 | | # define BUFFER_APPEND_NUM(b, s) { \ |
243 | | ret = _gnutls_buffer_append_prefix(b, 32, s); \ |
244 | | if (ret < 0) { \ |
245 | | gnutls_assert(); \ |
246 | | return ret; \ |
247 | | } \ |
248 | | } |
249 | | |
250 | | # define BUFFER_APPEND_TS(b, s) { \ |
251 | | ret = _gnutls_buffer_append_prefix(b, 32, (uint64_t) s.tv_sec >> 32); \ |
252 | | if (ret < 0) { \ |
253 | | gnutls_assert(); \ |
254 | | return ret; \ |
255 | | } \ |
256 | | ret = _gnutls_buffer_append_prefix(b, 32, s.tv_sec & 0xFFFFFFFF); \ |
257 | | if (ret < 0) { \ |
258 | | gnutls_assert(); \ |
259 | | return ret; \ |
260 | | } \ |
261 | | ret = _gnutls_buffer_append_prefix(b, 32, s.tv_nsec); \ |
262 | | if (ret < 0) { \ |
263 | | gnutls_assert(); \ |
264 | | return ret; \ |
265 | | } \ |
266 | | } |
267 | | |
268 | | # define BUFFER_POP(b, x, s) { \ |
269 | | ret = _gnutls_buffer_pop_data(b, x, s); \ |
270 | | if (ret < 0) { \ |
271 | | ret = GNUTLS_E_PARSING_ERROR; \ |
272 | | gnutls_assert(); \ |
273 | | goto error; \ |
274 | | } \ |
275 | | } |
276 | | |
277 | | # define BUFFER_POP_DATUM(b, o) { \ |
278 | | gnutls_datum_t d; \ |
279 | | ret = _gnutls_buffer_pop_datum_prefix32(b, &d); \ |
280 | | if (ret >= 0) \ |
281 | | ret = _gnutls_set_datum (o, d.data, d.size); \ |
282 | | if (ret < 0) { \ |
283 | | gnutls_assert(); \ |
284 | | goto error; \ |
285 | | } \ |
286 | | } |
287 | | |
288 | | # define BUFFER_POP_NUM(b, o) { \ |
289 | | size_t s; \ |
290 | | ret = _gnutls_buffer_pop_prefix32(b, &s, 0); \ |
291 | | if (ret < 0) { \ |
292 | | gnutls_assert(); \ |
293 | | goto error; \ |
294 | | } \ |
295 | | o = s; \ |
296 | | } |
297 | | |
298 | | # define BUFFER_POP_CAST_NUM(b, o) { \ |
299 | | size_t s; \ |
300 | | ret = _gnutls_buffer_pop_prefix32(b, &s, 0); \ |
301 | | if (ret < 0) { \ |
302 | | gnutls_assert(); \ |
303 | | goto error; \ |
304 | | } \ |
305 | | o = (void *) (intptr_t)(s); \ |
306 | | } |
307 | | |
308 | | # define BUFFER_POP_TS(b, o) { \ |
309 | | size_t s; \ |
310 | | uint64_t v; \ |
311 | | ret = _gnutls_buffer_pop_prefix32(b, &s, 0); \ |
312 | | if (ret < 0) { \ |
313 | | gnutls_assert(); \ |
314 | | goto error; \ |
315 | | } \ |
316 | | v = s; \ |
317 | | ret = _gnutls_buffer_pop_prefix32(b, &s, 0); \ |
318 | | if (ret < 0) { \ |
319 | | gnutls_assert(); \ |
320 | | goto error; \ |
321 | | } \ |
322 | | v = (v << 32) | s; \ |
323 | | ret = _gnutls_buffer_pop_prefix32(b, &s, 0); \ |
324 | | if (ret < 0) { \ |
325 | | gnutls_assert(); \ |
326 | | goto error; \ |
327 | | } \ |
328 | | o.tv_sec = v; \ |
329 | | o.tv_nsec = s; \ |
330 | | } |
331 | | |
332 | | #endif /* GNUTLS_LIB_STR_H */ |