summaryrefslogtreecommitdiffstats
path: root/test/ec_internal_test.c
diff options
context:
space:
mode:
authorNicola Tuveri <nic.tuv@gmail.com>2020-07-16 01:57:09 +0300
committerNicola Tuveri <nic.tuv@gmail.com>2021-08-30 15:18:08 +0300
commitea1128e94e36fa9fa25278dc6b3f5b42d8735782 (patch)
treef71d5b23051b5b93b435e0bc38e0e25bbd68c556 /test/ec_internal_test.c
parente8e1f6d1a9e599d575431f559200018b8f822e0f (diff)
Add tests for i2d_TYPE_fp and d2i_TYPE_fp
These functions are part of the public API but we don't have tests covering their usage. They are actually implemented as macros and the absence of tests has caused them to fall out-of-sync with the latest changes to ASN1 related functions and cause compilation warnings. @@ Note: This commit limits to ECPKParameters as a type. Reviewed-by: Tomas Mraz <tomas@openssl.org> (Merged from https://github.com/openssl/openssl/pull/16355)
Diffstat (limited to 'test/ec_internal_test.c')
-rw-r--r--test/ec_internal_test.c43
1 files changed, 43 insertions, 0 deletions
diff --git a/test/ec_internal_test.c b/test/ec_internal_test.c
index e0e6a859cb..57092942a1 100644
--- a/test/ec_internal_test.c
+++ b/test/ec_internal_test.c
@@ -359,6 +359,47 @@ static int decoded_flag_test(void)
return testresult;
}
+static
+int ecpkparams_i2d2i_test(int n)
+{
+ EC_GROUP *g1 = NULL, *g2 = NULL;
+ FILE *fp = NULL;
+ int nid = curves[n].nid;
+ int testresult = 0;
+
+ /* create group */
+ if (!TEST_ptr(g1 = EC_GROUP_new_by_curve_name(nid)))
+ goto end;
+
+ /* encode params to file */
+ if (!TEST_ptr(fp = fopen("params.der", "wb"))
+ || !TEST_true(i2d_ECPKParameters_fp(fp, g1)))
+ goto end;
+
+ /* flush and close file */
+ if (!TEST_int_eq(fclose(fp), 0)) {
+ fp = NULL;
+ goto end;
+ }
+ fp = NULL;
+
+ /* decode params from file */
+ if (!TEST_ptr(fp = fopen("params.der", "rb"))
+ || !TEST_ptr(g2 = d2i_ECPKParameters_fp(fp, NULL)))
+ goto end;
+
+ testresult = 1; /* PASS */
+
+end:
+ if (fp != NULL)
+ fclose(fp);
+
+ EC_GROUP_free(g1);
+ EC_GROUP_free(g2);
+
+ return testresult;
+}
+
int setup_tests(void)
{
crv_len = EC_get_builtin_curves(NULL, 0);
@@ -376,6 +417,8 @@ int setup_tests(void)
ADD_TEST(underflow_test);
#endif
ADD_TEST(decoded_flag_test);
+ ADD_ALL_TESTS(ecpkparams_i2d2i_test, crv_len);
+
return 1;
}