From: jsing Date: Sat, 25 Jun 2022 13:57:17 +0000 (+0000) Subject: Add regress for ASN1_INTEGER_cmp() X-Git-Url: http://artulab.com/gitweb/?a=commitdiff_plain;h=9badb9ad8932c12f4ece484255eb2703a2518c17;p=openbsd Add regress for ASN1_INTEGER_cmp() --- diff --git a/regress/lib/libcrypto/asn1/asn1basic.c b/regress/lib/libcrypto/asn1/asn1basic.c index 6c7e32df6c8..543ee93ee89 100644 --- a/regress/lib/libcrypto/asn1/asn1basic.c +++ b/regress/lib/libcrypto/asn1/asn1basic.c @@ -1,4 +1,4 @@ -/* $OpenBSD: asn1basic.c,v 1.6 2022/04/27 17:43:06 jsing Exp $ */ +/* $OpenBSD: asn1basic.c,v 1.7 2022/06/25 13:57:17 jsing Exp $ */ /* * Copyright (c) 2017, 2021 Joel Sing * @@ -459,6 +459,79 @@ asn1_integer_decode_test(struct asn1_integer_test *ait) return failed; } +static int +asn1_integer_cmp_test(void) +{ + ASN1_INTEGER *a = NULL, *b = NULL; + int failed = 1; + + if ((a = ASN1_INTEGER_new()) == NULL) + goto failed; + if ((b = ASN1_INTEGER_new()) == NULL) + goto failed; + + if (ASN1_INTEGER_cmp(a, b) != 0) { + fprintf(stderr, "FAIL: INTEGER 0 == 0"); + goto failed; + } + + if (!ASN1_INTEGER_set(b, 1)) { + fprintf(stderr, "FAIL: failed to set INTEGER"); + goto failed; + } + if (ASN1_INTEGER_cmp(a, b) >= 0) { + fprintf(stderr, "FAIL: INTEGER 0 < 1"); + goto failed; + } + if (ASN1_INTEGER_cmp(b, a) <= 0) { + fprintf(stderr, "FAIL: INTEGER 1 > 0"); + goto failed; + } + + if (!ASN1_INTEGER_set(b, -1)) { + fprintf(stderr, "FAIL: failed to set INTEGER"); + goto failed; + } + if (ASN1_INTEGER_cmp(a, b) <= 0) { + fprintf(stderr, "FAIL: INTEGER 0 > -1"); + goto failed; + } + if (ASN1_INTEGER_cmp(b, a) >= 0) { + fprintf(stderr, "FAIL: INTEGER -1 < 0"); + goto failed; + } + + if (!ASN1_INTEGER_set(a, 1)) { + fprintf(stderr, "FAIL: failed to set INTEGER"); + goto failed; + } + if (ASN1_INTEGER_cmp(a, b) <= 0) { + fprintf(stderr, "FAIL: INTEGER 1 > -1"); + goto failed; + } + if (ASN1_INTEGER_cmp(b, a) >= 0) { + fprintf(stderr, "FAIL: INTEGER -1 < 1"); + goto failed; + } + + if (!ASN1_INTEGER_set(b, 1)) { + fprintf(stderr, "FAIL: failed to set INTEGER"); + goto failed; + } + if (ASN1_INTEGER_cmp(a, b) != 0) { + fprintf(stderr, "FAIL: INTEGER 1 == 1"); + goto failed; + } + + failed = 0; + + failed: + ASN1_INTEGER_free(a); + ASN1_INTEGER_free(b); + + return failed; +} + static int asn1_integer_test(void) { @@ -475,6 +548,8 @@ asn1_integer_test(void) failed |= asn1_integer_decode_test(ait); } + failed |= asn1_integer_cmp_test(); + return failed; }