From 125b6085fc593a37acf521d1834395ff8d33145e Mon Sep 17 00:00:00 2001
From: Johannes Schindelin <johannes.schindelin@gmx.de>
Date: Wed, 21 Nov 2018 17:53:41 +0100
Subject: [PATCH 3/3] tls13secretstest: work around "multiple definition of
 ..."

The way some functions are mocked does not find the favor of current
mingw-w64's ld.exe. So let's work around it by mocking them differently.

Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
---
 test/build.info         |  1 -
 test/tls13secretstest.c | 39 +++++++++++++++++++++++++++------------
 2 files changed, 27 insertions(+), 13 deletions(-)

diff --git a/test/build.info b/test/build.info
index b6bb711..9ee1cbb 100644
--- a/test/build.info
+++ b/test/build.info
@@ -530,7 +530,6 @@ INCLUDE_MAIN___test_libtestutil_OLB = /INCLUDE=MAIN
   IF[{- !$disabled{shared} -}]
     PROGRAMS_NO_INST=tls13secretstest
     SOURCE[tls13secretstest]=tls13secretstest.c
-    SOURCE[tls13secretstest]= ../ssl/tls13_enc.c ../ssl/packet.c
     INCLUDE[tls13secretstest]=.. ../include
     DEPEND[tls13secretstest]=../libcrypto ../libssl libtestutil.a
   ENDIF
diff --git a/test/tls13secretstest.c b/test/tls13secretstest.c
index 724c170..2357751 100644
--- a/test/tls13secretstest.c
+++ b/test/tls13secretstest.c
@@ -136,7 +136,8 @@ static unsigned char server_ats_iv[] = {
 };
 
 /* Mocked out implementations of various functions */
-int ssl3_digest_cached_records(SSL *s, int keep)
+#define ssl3_digest_cached_records mock_ssl3_digest_cached_records
+static int mock_ssl3_digest_cached_records(SSL *s, int keep)
 {
     return 1;
 }
@@ -144,7 +145,8 @@ int ssl3_digest_cached_records(SSL *s, int keep)
 static int full_hash = 0;
 
 /* Give a hash of the currently set handshake */
-int ssl_handshake_hash(SSL *s, unsigned char *out, size_t outlen,
+#define ssl_handshake_hash mock_ssl_handshake_hash
+static int mock_ssl_handshake_hash(SSL *s, unsigned char *out, size_t outlen,
                        size_t *hashlen)
 {
     if (sizeof(hs_start_hash) > outlen
@@ -162,20 +164,24 @@ int ssl_handshake_hash(SSL *s, unsigned char *out, size_t outlen,
     return 1;
 }
 
-const EVP_MD *ssl_handshake_md(SSL *s)
+#define ssl_handshake_md mock_ssl_handshake_md
+static const EVP_MD *mock_ssl_handshake_md(SSL *s)
 {
     return EVP_sha256();
 }
 
-void RECORD_LAYER_reset_read_sequence(RECORD_LAYER *rl)
+#define RECORD_LAYER_reset_read_sequence mock_RECORD_LAYER_reset_read_sequence
+static void mock_RECORD_LAYER_reset_read_sequence(RECORD_LAYER *rl)
 {
 }
 
-void RECORD_LAYER_reset_write_sequence(RECORD_LAYER *rl)
+#define RECORD_LAYER_reset_write_sequence mock_RECORD_LAYER_reset_write_sequence
+static void mock_RECORD_LAYER_reset_write_sequence(RECORD_LAYER *rl)
 {
 }
 
-int ssl_cipher_get_evp(const SSL_SESSION *s, const EVP_CIPHER **enc,
+#define ssl_cipher_get_evp mock_ssl_cipher_get_evp
+static int mock_ssl_cipher_get_evp(const SSL_SESSION *s, const EVP_CIPHER **enc,
                        const EVP_MD **md, int *mac_pkey_type,
                        size_t *mac_secret_size, SSL_COMP **comp, int use_etm)
 
@@ -183,12 +189,14 @@ int ssl_cipher_get_evp(const SSL_SESSION *s, const EVP_CIPHER **enc,
     return 0;
 }
 
-int tls1_alert_code(int code)
+#define tls1_alert_code mock_tls1_alert_code
+static int mock_tls1_alert_code(int code)
 {
     return code;
 }
 
-int ssl_log_secret(SSL *ssl,
+#define ssl_log_secret mock_ssl_log_secret
+static int mock_ssl_log_secret(SSL *ssl,
                    const char *label,
                    const uint8_t *secret,
                    size_t secret_len)
@@ -196,22 +204,26 @@ int ssl_log_secret(SSL *ssl,
     return 1;
 }
 
-const EVP_MD *ssl_md(int idx)
+#define ssl_md mock_ssl_md
+static const EVP_MD *mock_ssl_md(int idx)
 {
     return EVP_sha256();
 }
 
-void ossl_statem_fatal(SSL *s, int al, int func, int reason, const char *file,
+#define ossl_statem_fatal mock_ossl_statem_fatal
+static void mock_ossl_statem_fatal(SSL *s, int al, int func, int reason, const char *file,
                            int line)
 {
 }
 
-int ossl_statem_export_allowed(SSL *s)
+#define ossl_statem_export_allowed mock_ossl_statem_export_allowed
+static int mock_ossl_statem_export_allowed(SSL *s)
 {
     return 1;
 }
 
-int ossl_statem_export_early_allowed(SSL *s)
+#define ossl_statem_export_early_allowed mock_ossl_statem_export_early_allowed
+static int mock_ossl_statem_export_early_allowed(SSL *s)
 {
     return 1;
 }
@@ -398,3 +410,6 @@ int setup_tests(void)
     ADD_TEST(test_handshake_secrets);
     return 1;
 }
+
+#include "../ssl/tls13_enc.c"
+#include "../ssl/packet.c"
-- 
2.19.1

