summaryrefslogtreecommitdiff
path: root/src/lib/libcrypto/asn1/asn1_lib.c
diff options
context:
space:
mode:
authorjsing <>2021-12-15 18:00:32 +0000
committerjsing <>2021-12-15 18:00:32 +0000
commite61e8eab0ed72cba26134860e9976f836728d877 (patch)
tree582bd7e91dc07b37e1a88c57120d362994f5a80b /src/lib/libcrypto/asn1/asn1_lib.c
parentd97abc08cae4df58901d8ea1f6fe74e35d142843 (diff)
downloadopenbsd-e61e8eab0ed72cba26134860e9976f836728d877.tar.gz
openbsd-e61e8eab0ed72cba26134860e9976f836728d877.tar.bz2
openbsd-e61e8eab0ed72cba26134860e9976f836728d877.zip
Consolidate various ASN.1 code.
Rather than having multiple files per type (with minimal code per file), use one file per type (a_<type>.c). No functional change. Discussed with tb@
Diffstat (limited to 'src/lib/libcrypto/asn1/asn1_lib.c')
-rw-r--r--src/lib/libcrypto/asn1/asn1_lib.c148
1 files changed, 1 insertions, 147 deletions
diff --git a/src/lib/libcrypto/asn1/asn1_lib.c b/src/lib/libcrypto/asn1/asn1_lib.c
index 3e2ba29495..fc0958fb45 100644
--- a/src/lib/libcrypto/asn1/asn1_lib.c
+++ b/src/lib/libcrypto/asn1/asn1_lib.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: asn1_lib.c,v 1.48 2021/12/03 17:03:54 jsing Exp $ */ 1/* $OpenBSD: asn1_lib.c,v 1.49 2021/12/15 18:00:31 jsing Exp $ */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) 2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved. 3 * All rights reserved.
4 * 4 *
@@ -284,149 +284,3 @@ ASN1_object_size(int constructed, int length, int tag)
284 } 284 }
285 return (ret); 285 return (ret);
286} 286}
287
288int
289ASN1_STRING_copy(ASN1_STRING *dst, const ASN1_STRING *str)
290{
291 if (str == NULL)
292 return 0;
293 if (!ASN1_STRING_set(dst, str->data, str->length))
294 return 0;
295 dst->type = str->type;
296 dst->flags = str->flags;
297 return 1;
298}
299
300ASN1_STRING *
301ASN1_STRING_dup(const ASN1_STRING *str)
302{
303 ASN1_STRING *ret;
304
305 if (!str)
306 return NULL;
307 ret = ASN1_STRING_new();
308 if (!ret)
309 return NULL;
310 if (!ASN1_STRING_copy(ret, str)) {
311 ASN1_STRING_free(ret);
312 return NULL;
313 }
314 return ret;
315}
316
317int
318ASN1_STRING_set(ASN1_STRING *str, const void *_data, int len)
319{
320 const char *data = _data;
321
322 if (len < 0) {
323 if (data == NULL)
324 return (0);
325 else
326 len = strlen(data);
327 }
328 if ((str->length < len) || (str->data == NULL)) {
329 unsigned char *tmp;
330 tmp = realloc(str->data, len + 1);
331 if (tmp == NULL) {
332 ASN1error(ERR_R_MALLOC_FAILURE);
333 return (0);
334 }
335 str->data = tmp;
336 }
337 str->length = len;
338 if (data != NULL) {
339 memmove(str->data, data, len);
340 }
341 str->data[str->length] = '\0';
342 return (1);
343}
344
345void
346ASN1_STRING_set0(ASN1_STRING *str, void *data, int len)
347{
348 freezero(str->data, str->length);
349 str->data = data;
350 str->length = len;
351}
352
353ASN1_STRING *
354ASN1_STRING_new(void)
355{
356 return (ASN1_STRING_type_new(V_ASN1_OCTET_STRING));
357}
358
359ASN1_STRING *
360ASN1_STRING_type_new(int type)
361{
362 ASN1_STRING *a;
363
364 if ((a = calloc(1, sizeof(ASN1_STRING))) == NULL) {
365 ASN1error(ERR_R_MALLOC_FAILURE);
366 return NULL;
367 }
368 a->type = type;
369
370 return a;
371}
372
373void
374ASN1_STRING_free(ASN1_STRING *a)
375{
376 if (a == NULL)
377 return;
378 if (a->data != NULL && !(a->flags & ASN1_STRING_FLAG_NDEF))
379 freezero(a->data, a->length);
380 free(a);
381}
382
383int
384ASN1_STRING_cmp(const ASN1_STRING *a, const ASN1_STRING *b)
385{
386 int cmp;
387
388 if (a == NULL || b == NULL)
389 return -1;
390 if ((cmp = (a->length - b->length)) != 0)
391 return cmp;
392 if ((cmp = memcmp(a->data, b->data, a->length)) != 0)
393 return cmp;
394
395 return (a->type - b->type);
396}
397
398void
399asn1_add_error(const unsigned char *address, int offset)
400{
401 ERR_asprintf_error_data("offset=%d", offset);
402}
403
404int
405ASN1_STRING_length(const ASN1_STRING *x)
406{
407 return (x->length);
408}
409
410void
411ASN1_STRING_length_set(ASN1_STRING *x, int len)
412{
413 x->length = len;
414}
415
416int
417ASN1_STRING_type(const ASN1_STRING *x)
418{
419 return (x->type);
420}
421
422unsigned char *
423ASN1_STRING_data(ASN1_STRING *x)
424{
425 return (x->data);
426}
427
428const unsigned char *
429ASN1_STRING_get0_data(const ASN1_STRING *x)
430{
431 return (x->data);
432}