From e61e8eab0ed72cba26134860e9976f836728d877 Mon Sep 17 00:00:00 2001 From: jsing <> Date: Wed, 15 Dec 2021 18:00:32 +0000 Subject: Consolidate various ASN.1 code. Rather than having multiple files per type (with minimal code per file), use one file per type (a_.c). No functional change. Discussed with tb@ --- src/lib/libcrypto/asn1/asn1_lib.c | 148 +------------------------------------- 1 file changed, 1 insertion(+), 147 deletions(-) (limited to 'src/lib/libcrypto/asn1/asn1_lib.c') 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 @@ -/* $OpenBSD: asn1_lib.c,v 1.48 2021/12/03 17:03:54 jsing Exp $ */ +/* $OpenBSD: asn1_lib.c,v 1.49 2021/12/15 18:00:31 jsing Exp $ */ /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) * All rights reserved. * @@ -284,149 +284,3 @@ ASN1_object_size(int constructed, int length, int tag) } return (ret); } - -int -ASN1_STRING_copy(ASN1_STRING *dst, const ASN1_STRING *str) -{ - if (str == NULL) - return 0; - if (!ASN1_STRING_set(dst, str->data, str->length)) - return 0; - dst->type = str->type; - dst->flags = str->flags; - return 1; -} - -ASN1_STRING * -ASN1_STRING_dup(const ASN1_STRING *str) -{ - ASN1_STRING *ret; - - if (!str) - return NULL; - ret = ASN1_STRING_new(); - if (!ret) - return NULL; - if (!ASN1_STRING_copy(ret, str)) { - ASN1_STRING_free(ret); - return NULL; - } - return ret; -} - -int -ASN1_STRING_set(ASN1_STRING *str, const void *_data, int len) -{ - const char *data = _data; - - if (len < 0) { - if (data == NULL) - return (0); - else - len = strlen(data); - } - if ((str->length < len) || (str->data == NULL)) { - unsigned char *tmp; - tmp = realloc(str->data, len + 1); - if (tmp == NULL) { - ASN1error(ERR_R_MALLOC_FAILURE); - return (0); - } - str->data = tmp; - } - str->length = len; - if (data != NULL) { - memmove(str->data, data, len); - } - str->data[str->length] = '\0'; - return (1); -} - -void -ASN1_STRING_set0(ASN1_STRING *str, void *data, int len) -{ - freezero(str->data, str->length); - str->data = data; - str->length = len; -} - -ASN1_STRING * -ASN1_STRING_new(void) -{ - return (ASN1_STRING_type_new(V_ASN1_OCTET_STRING)); -} - -ASN1_STRING * -ASN1_STRING_type_new(int type) -{ - ASN1_STRING *a; - - if ((a = calloc(1, sizeof(ASN1_STRING))) == NULL) { - ASN1error(ERR_R_MALLOC_FAILURE); - return NULL; - } - a->type = type; - - return a; -} - -void -ASN1_STRING_free(ASN1_STRING *a) -{ - if (a == NULL) - return; - if (a->data != NULL && !(a->flags & ASN1_STRING_FLAG_NDEF)) - freezero(a->data, a->length); - free(a); -} - -int -ASN1_STRING_cmp(const ASN1_STRING *a, const ASN1_STRING *b) -{ - int cmp; - - if (a == NULL || b == NULL) - return -1; - if ((cmp = (a->length - b->length)) != 0) - return cmp; - if ((cmp = memcmp(a->data, b->data, a->length)) != 0) - return cmp; - - return (a->type - b->type); -} - -void -asn1_add_error(const unsigned char *address, int offset) -{ - ERR_asprintf_error_data("offset=%d", offset); -} - -int -ASN1_STRING_length(const ASN1_STRING *x) -{ - return (x->length); -} - -void -ASN1_STRING_length_set(ASN1_STRING *x, int len) -{ - x->length = len; -} - -int -ASN1_STRING_type(const ASN1_STRING *x) -{ - return (x->type); -} - -unsigned char * -ASN1_STRING_data(ASN1_STRING *x) -{ - return (x->data); -} - -const unsigned char * -ASN1_STRING_get0_data(const ASN1_STRING *x) -{ - return (x->data); -} -- cgit v1.2.3-55-g6feb