From a7deaf8f840c5d72a852457259c48d8fb9c57c9b Mon Sep 17 00:00:00 2001 From: jsing Date: Fri, 24 Dec 2021 14:12:26 +0000 Subject: [PATCH] Reorder some functions. No functional change. --- lib/libcrypto/asn1/a_string.c | 92 +++++++++++++++++------------------ 1 file changed, 46 insertions(+), 46 deletions(-) diff --git a/lib/libcrypto/asn1/a_string.c b/lib/libcrypto/asn1/a_string.c index b3a1323a54e..e7e75ff9d3f 100644 --- a/lib/libcrypto/asn1/a_string.c +++ b/lib/libcrypto/asn1/a_string.c @@ -1,4 +1,4 @@ -/* $OpenBSD: a_string.c,v 1.1 2021/12/15 18:00:31 jsing Exp $ */ +/* $OpenBSD: a_string.c,v 1.2 2021/12/24 14:12:26 jsing Exp $ */ /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) * All rights reserved. * @@ -63,6 +63,51 @@ #include #include +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); +} + int ASN1_STRING_copy(ASN1_STRING *dst, const ASN1_STRING *str) { @@ -128,51 +173,6 @@ ASN1_STRING_set0(ASN1_STRING *str, void *data, int len) 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) { -- 2.20.1