From: Nikola Pajkovsky Date: Thu, 18 Sep 2025 08:42:42 +0000 (+0200) Subject: Move handy test functions to testutil X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=0955904db17f1589dc920cd7c6103f2246e2d163;p=thirdparty%2Fopenssl.git Move handy test functions to testutil Signed-off-by: Nikola Pajkovsky Reviewed-by: Neil Horman Reviewed-by: Saša Nedvědický (Merged from https://github.com/openssl/openssl/pull/28599) --- diff --git a/test/crltest.c b/test/crltest.c index 07ccddd4779..cb35c15d9c8 100644 --- a/test/crltest.c +++ b/test/crltest.c @@ -275,60 +275,6 @@ static X509 *test_leaf = NULL; static X509 *test_root2 = NULL; static X509 *test_leaf2 = NULL; -/* - * Glue an array of strings together. Return a BIO and put the string - * into |*out| so we can free it. - */ -static BIO *glue2bio(const char **pem, char **out) -{ - size_t s = 0; - - *out = glue_strings(pem, &s); - return BIO_new_mem_buf(*out, (int)s); -} - -/* - * Create a CRL from an array of strings. - */ -static X509_CRL *CRL_from_strings(const char **pem) -{ - X509_CRL *crl; - char *p; - BIO *b = glue2bio(pem, &p); - - if (b == NULL) { - OPENSSL_free(p); - return NULL; - } - - crl = PEM_read_bio_X509_CRL(b, NULL, NULL, NULL); - - OPENSSL_free(p); - BIO_free(b); - return crl; -} - -/* - * Create an X509 from an array of strings. - */ -static X509 *X509_from_strings(const char **pem) -{ - X509 *x; - char *p; - BIO *b = glue2bio(pem, &p); - - if (b == NULL) { - OPENSSL_free(p); - return NULL; - } - - x = PEM_read_bio_X509(b, NULL, NULL, NULL); - - OPENSSL_free(p); - BIO_free(b); - return x; -} - /* * Verify |leaf| certificate (chained up to |root|). |crls| if * not NULL, is a list of CRLs to include in the verification. It is diff --git a/test/testutil.h b/test/testutil.h index a262d937195..01535b85f8e 100644 --- a/test/testutil.h +++ b/test/testutil.h @@ -652,6 +652,19 @@ X509 *load_cert_der(const unsigned char *bytes, int len); STACK_OF(X509) *load_certs_pem(const char *file); X509_REQ *load_csr_der(const char *file, OSSL_LIB_CTX *libctx); time_t test_asn1_string_to_time_t(const char *asn1_string); - int compare_with_reference_file(BIO *membio, const char *reffile); +/* + * Create an X509 from an array of strings. + */ +X509 *X509_from_strings(const char **pem); +/* + * Create a CRL from an array of strings. + */ +X509_CRL *CRL_from_strings(const char **pem); +/* + * Glue an array of strings together. Return a BIO and put the string + * into |*out| so we can free it. + */ +BIO *glue2bio(const char **pem, char **out); + #endif /* OSSL_TESTUTIL_H */ diff --git a/test/testutil/load.c b/test/testutil/load.c index 982e0a39a9b..e630c54abd8 100644 --- a/test/testutil/load.c +++ b/test/testutil/load.c @@ -103,3 +103,57 @@ X509_REQ *load_csr_der(const char *file, OSSL_LIB_CTX *libctx) BIO_free(bio); return csr; } + +/* + * Glue an array of strings together. Return a BIO and put the string + * into |*out| so we can free it. + */ +BIO *glue2bio(const char **pem, char **out) +{ + size_t s = 0; + + *out = glue_strings(pem, &s); + return BIO_new_mem_buf(*out, (int)s); +} + +/* + * Create a CRL from an array of strings. + */ +X509_CRL *CRL_from_strings(const char **pem) +{ + X509_CRL *crl; + char *p; + BIO *b = glue2bio(pem, &p); + + if (b == NULL) { + OPENSSL_free(p); + return NULL; + } + + crl = PEM_read_bio_X509_CRL(b, NULL, NULL, NULL); + + OPENSSL_free(p); + BIO_free(b); + return crl; +} + +/* + * Create an X509 from an array of strings. + */ +X509 *X509_from_strings(const char **pem) +{ + X509 *x; + char *p; + BIO *b = glue2bio(pem, &p); + + if (b == NULL) { + OPENSSL_free(p); + return NULL; + } + + x = PEM_read_bio_X509(b, NULL, NULL, NULL); + + OPENSSL_free(p); + BIO_free(b); + return x; +}