X-Git-Url: https://git.openssl.org/gitweb/?a=blobdiff_plain;f=test%2Fasn1_encode_test.c;h=4ff8a20ff4743d589c2e44ea64e1777e5d10ae47;hb=2de64666a07cccf8477e6483de62ae31f463df64;hp=3da07503e7ea47a1e666702180575f8c64963495;hpb=6e5e196748b3dbfd2919b23e5b21688885e72881;p=openssl.git diff --git a/test/asn1_encode_test.c b/test/asn1_encode_test.c index 3da07503e7..4ff8a20ff4 100644 --- a/test/asn1_encode_test.c +++ b/test/asn1_encode_test.c @@ -1,7 +1,7 @@ /* - * Copyright 2017 The OpenSSL Project Authors. All Rights Reserved. + * Copyright 2017-2018 The OpenSSL Project Authors. All Rights Reserved. * - * Licensed under the OpenSSL license (the "License"). You may not use + * Licensed under the Apache License 2.0 (the "License"). You may not use * this file except in compliance with the License. You can obtain a copy * in the file LICENSE in the source distribution or at * https://www.openssl.org/source/license.html @@ -179,7 +179,7 @@ typedef struct { ENCDEC_DATA(-1, -1), \ ENCDEC_DATA(0, ASN1_LONG_UNDEF) -#if OPENSSL_API_COMPAT < 0x10200000L +#ifndef OPENSSL_NO_DEPRECATED_3_0 /***** LONG ******************************************************************/ typedef struct { @@ -396,7 +396,7 @@ static ASN1_INT64_DATA int64_expected[] = { CUSTOM_EXPECTED_FAILURE, /* t_8bytes_3_pad (illegal padding) */ CUSTOM_EXPECTED_SUCCESS(INT64_MIN, INT64_MIN), /* t_8bytes_4_neg */ CUSTOM_EXPECTED_FAILURE, /* t_8bytes_5_negpad (illegal padding) */ - CUSTOM_EXPECTED_SUCCESS(0x1ffffffff, 0x1ffffffff), /* t_5bytes_1 */ + CUSTOM_EXPECTED_SUCCESS(0x1ffffffffULL, 0x1ffffffffULL), /* t_5bytes_1 */ CUSTOM_EXPECTED_SUCCESS(0x80000000, 0x80000000), /* t_4bytes_1 */ CUSTOM_EXPECTED_SUCCESS(INT32_MAX - 1, INT32_MAX -1), /* t_4bytes_2 */ CUSTOM_EXPECTED_FAILURE, /* t_4bytes_3_pad (illegal padding) */ @@ -446,7 +446,7 @@ static ASN1_UINT64_DATA uint64_expected[] = { CUSTOM_EXPECTED_FAILURE, /* t_8bytes_3_pad */ CUSTOM_EXPECTED_FAILURE, /* t_8bytes_4_neg */ CUSTOM_EXPECTED_FAILURE, /* t_8bytes_5_negpad */ - CUSTOM_EXPECTED_SUCCESS(0x1ffffffff, 0x1ffffffff), /* t_5bytes_1 */ + CUSTOM_EXPECTED_SUCCESS(0x1ffffffffULL, 0x1ffffffffULL), /* t_5bytes_1 */ CUSTOM_EXPECTED_SUCCESS(0x80000000, 0x80000000), /* t_4bytes_1 */ CUSTOM_EXPECTED_SUCCESS(INT32_MAX - 1, INT32_MAX -1), /* t_4bytes_2 */ CUSTOM_EXPECTED_FAILURE, /* t_4bytes_3_pad (illegal padding) */ @@ -577,14 +577,14 @@ static size_t der_encode_length(size_t len, unsigned char **pp) if (pp != NULL) { if (lenbytes == 1) { - *(*pp)++ = len; + *(*pp)++ = (unsigned char)len; } else { - *(*pp)++ = lenbytes - 1; + *(*pp)++ = (unsigned char)(lenbytes - 1); if (lenbytes == 2) { - *(*pp)++ = 0x80 | len; + *(*pp)++ = (unsigned char)(0x80 | len); } else { - *(*pp)++ = 0x80 | (len >> 8); - *(*pp)++ = len & 0xff; + *(*pp)++ = (unsigned char)(0x80 | (len >> 8)); + *(*pp)++ = (unsigned char)(len); } } } @@ -672,7 +672,7 @@ static int do_decode_custom(const TEST_CUSTOM_DATA *custom_data, { unsigned char *encoding = NULL; /* - * We force the defaults to be explicitely encoded to make sure we test + * We force the defaults to be explicitly encoded to make sure we test * for defaults that shouldn't be present (i.e. we check for failure) */ size_t encoding_length = make_custom_der(custom_data, &encoding, 1); @@ -709,15 +709,18 @@ static int do_encode_custom(EXPECTED *input, static int do_print_item(const TEST_PACKAGE *package) { #define DATA_BUF_SIZE 256 - unsigned char buf[DATA_BUF_SIZE]; const ASN1_ITEM *i = ASN1_ITEM_ptr(package->asn1_type); - ASN1_VALUE *o = (ASN1_VALUE *)&buf; + ASN1_VALUE *o; int ret; OPENSSL_assert(package->encode_expectations_elem_size <= DATA_BUF_SIZE); + if ((o = OPENSSL_malloc(DATA_BUF_SIZE)) == NULL) + return 0; - (void)RAND_bytes(buf, (int)package->encode_expectations_elem_size); - ret = ASN1_item_print(bio_out, o, 0, i, NULL); + (void)RAND_bytes((unsigned char*)o, + (int)package->encode_expectations_elem_size); + ret = ASN1_item_print(bio_err, o, 0, i, NULL); + OPENSSL_free(o); return ret; } @@ -821,7 +824,7 @@ static int test_intern(const TEST_PACKAGE *package) return fail == 0; } -#if OPENSSL_API_COMPAT < 0x10200000L +#ifndef OPENSSL_NO_DEPRECATED_3_0 static int test_long_32bit(void) { return test_intern(&long_test_package_32bit); @@ -853,9 +856,9 @@ static int test_uint64(void) return test_intern(&uint64_test_package); } -void register_tests(void) +int setup_tests(void) { -#if OPENSSL_API_COMPAT < 0x10200000L +#ifndef OPENSSL_NO_DEPRECATED_3_0 ADD_TEST(test_long_32bit); ADD_TEST(test_long_64bit); #endif @@ -863,4 +866,5 @@ void register_tests(void) ADD_TEST(test_uint32); ADD_TEST(test_int64); ADD_TEST(test_uint64); + return 1; }