aboutsummaryrefslogtreecommitdiff
path: root/src/daemon/https/tls/gnutls_str.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/daemon/https/tls/gnutls_str.c')
-rw-r--r--src/daemon/https/tls/gnutls_str.c129
1 files changed, 0 insertions, 129 deletions
diff --git a/src/daemon/https/tls/gnutls_str.c b/src/daemon/https/tls/gnutls_str.c
index 4fc4174b..4f123217 100644
--- a/src/daemon/https/tls/gnutls_str.c
+++ b/src/daemon/https/tls/gnutls_str.c
@@ -73,24 +73,6 @@ MHD_gtls_str_cpy (char *dest, size_t dest_tot_size, const char *src)
73} 73}
74 74
75void 75void
76MHD_gtls_mem_cpy (char *dest,
77 size_t dest_tot_size, const char *src, size_t src_size)
78{
79
80 if (dest_tot_size >= src_size)
81 {
82 memcpy (dest, src, src_size);
83 }
84 else
85 {
86 if (dest_tot_size > 0)
87 {
88 memcpy (dest, src, dest_tot_size);
89 }
90 }
91}
92
93void
94MHD_gtls_string_init (MHD_gtls_string * str, 76MHD_gtls_string_init (MHD_gtls_string * str,
95 MHD_gnutls_alloc_function alloc_func, 77 MHD_gnutls_alloc_function alloc_func,
96 MHD_gnutls_realloc_function realloc_func, 78 MHD_gnutls_realloc_function realloc_func,
@@ -117,83 +99,8 @@ MHD_gtls_string_clear (MHD_gtls_string * str)
117 str->length = 0; 99 str->length = 0;
118} 100}
119 101
120/* This one does not copy the string.
121 */
122MHD_gnutls_datum_t
123MHD_gtls_string2datum (MHD_gtls_string * str)
124{
125 MHD_gnutls_datum_t ret;
126
127 ret.data = str->data;
128 ret.size = str->length;
129
130 return ret;
131}
132
133#define MIN_CHUNK 256 102#define MIN_CHUNK 256
134 103
135int
136MHD_gtls_string_copy_str (MHD_gtls_string * dest, const char *src)
137{
138 size_t src_len = strlen (src);
139 size_t max;
140 if (dest->max_length >= src_len)
141 {
142 memcpy (dest->data, src, src_len);
143 dest->length = src_len;
144
145 return src_len;
146 }
147 else
148 {
149 max = (src_len > MIN_CHUNK) ? src_len : MIN_CHUNK;
150 dest->data = dest->realloc_func (dest->data, max);
151 if (dest->data == NULL)
152 {
153 MHD_gnutls_assert ();
154 return GNUTLS_E_MEMORY_ERROR;
155 }
156 dest->max_length = MAX (MIN_CHUNK, src_len);
157
158 memcpy (dest->data, src, src_len);
159 dest->length = src_len;
160
161 return src_len;
162 }
163}
164
165int
166MHD_gtls_string_append_str (MHD_gtls_string * dest, const char *src)
167{
168 size_t src_len = strlen (src);
169 size_t tot_len = src_len + dest->length;
170
171 if (dest->max_length >= tot_len)
172 {
173 memcpy (&dest->data[dest->length], src, src_len);
174 dest->length = tot_len;
175
176 return tot_len;
177 }
178 else
179 {
180 size_t new_len =
181 MAX (src_len, MIN_CHUNK) + MAX (dest->max_length, MIN_CHUNK);
182
183 dest->data = dest->realloc_func (dest->data, new_len);
184 if (dest->data == NULL)
185 {
186 MHD_gnutls_assert ();
187 return GNUTLS_E_MEMORY_ERROR;
188 }
189 dest->max_length = new_len;
190
191 memcpy (&dest->data[dest->length], src, src_len);
192 dest->length = tot_len;
193
194 return tot_len;
195 }
196}
197 104
198int 105int
199MHD_gtls_string_append_data (MHD_gtls_string * dest, 106MHD_gtls_string_append_data (MHD_gtls_string * dest,
@@ -249,39 +156,3 @@ MHD_gtls_bin2hex (const void *_old,
249 return buffer; 156 return buffer;
250} 157}
251 158
252/* just a hex2bin function.
253 */
254int
255MHD_gtls_hex2bin (const opaque * hex_data,
256 int hex_size, opaque * bin_data, size_t * bin_size)
257{
258 int i, j;
259 opaque hex2_data[3];
260 unsigned long val;
261
262 /* FIXME: we don't handle whitespace.
263 */
264 hex_size /= 2;
265
266 if (*bin_size < (size_t) hex_size)
267 {
268 MHD_gnutls_assert ();
269 return GNUTLS_E_SHORT_MEMORY_BUFFER;
270 }
271
272 for (i = j = 0; j < hex_size; i += 2, j++)
273 {
274 hex2_data[0] = hex_data[i];
275 hex2_data[1] = hex_data[i + 1];
276 hex2_data[2] = 0;
277 val = strtoul ((char *) hex2_data, NULL, 16);
278 if (val == ULONG_MAX)
279 {
280 MHD_gnutls_assert ();
281 return GNUTLS_E_SRP_PWD_PARSING_ERROR;
282 }
283 bin_data[j] = val;
284 }
285
286 return 0;
287}