Skip to content

Commit ce73c1d

Browse files
committed
Add WC_DEPRECATED, WOLFSSL_TEST_API, WOLFSSL_ALLOW_TEST_APIS, and WOLFSSL_LOCALIZE_TEST_APIS, and use them to control export and usability of internal functions needed by unit tests.
1 parent 47ed447 commit ce73c1d

4 files changed

Lines changed: 48 additions & 22 deletions

File tree

tests/unit.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@
2323
#ifndef TESTS_UNIT_H
2424
#define TESTS_UNIT_H
2525

26+
#define WOLFSSL_ALLOW_TEST_APIS
27+
2628
#ifdef HAVE_CONFIG_H
2729
#include <config.h>
2830
#endif

wolfssl/internal.h

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -2435,8 +2435,8 @@ typedef struct CipherSuite {
24352435
#endif
24362436
} CipherSuite;
24372437

2438-
/* use wolfSSL_API visibility to be able to test in tests/api.c */
2439-
WOLFSSL_API void InitSuitesHashSigAlgo(byte* hashSigAlgo, int have,
2438+
/* use wolfSSL_TEST_API visibility to be able to test in tests/api.c */
2439+
WOLFSSL_TEST_API void InitSuitesHashSigAlgo(byte* hashSigAlgo, int have,
24402440
int tls1_2, int keySz, word16* len);
24412441
WOLFSSL_LOCAL int AllocateCtxSuites(WOLFSSL_CTX* ctx);
24422442
WOLFSSL_LOCAL int AllocateSuites(WOLFSSL* ssl);
@@ -3396,7 +3396,7 @@ WOLFSSL_LOCAL int TLSX_CSR2_ForceRequest(WOLFSSL* ssl);
33963396
#if defined(WOLFSSL_PUBLIC_ASN) && defined(HAVE_PK_CALLBACKS)
33973397
/* Internal callback guarded by WOLFSSL_PUBLIC_ASN because of DecodedCert. */
33983398
typedef int (*CallbackProcessPeerCert)(WOLFSSL* ssl, DecodedCert* p_cert);
3399-
WOLFSSL_API void wolfSSL_CTX_SetProcessPeerCertCb(WOLFSSL_CTX* ctx,
3399+
WOLFSSL_TEST_API void wolfSSL_CTX_SetProcessPeerCertCb(WOLFSSL_CTX* ctx,
34003400
CallbackProcessPeerCert cb);
34013401
#endif /* DecodedCert && HAVE_PK_CALLBACKS */
34023402

@@ -4701,7 +4701,7 @@ WOLFSSL_LOCAL WOLFSSL_SESSION* wolfSSL_GetSession(
47014701
WOLFSSL_LOCAL void SetupSession(WOLFSSL* ssl);
47024702
WOLFSSL_LOCAL void AddSession(WOLFSSL* ssl);
47034703
/* use wolfSSL_API visibility to be able to test in tests/api.c */
4704-
WOLFSSL_API int AddSessionToCache(WOLFSSL_CTX* ctx,
4704+
WOLFSSL_TEST_API int AddSessionToCache(WOLFSSL_CTX* ctx,
47054705
WOLFSSL_SESSION* addSession, const byte* id, byte idSz, int* sessionIndex,
47064706
int side, word16 useTicket, ClientSession** clientCacheEntry);
47074707
#ifndef NO_CLIENT_CACHE
@@ -4717,8 +4717,8 @@ WOLFSSL_LOCAL int TlsSessionCacheGetAndRdLock(const byte *id,
47174717
WOLFSSL_LOCAL int TlsSessionCacheGetAndWrLock(const byte *id,
47184718
WOLFSSL_SESSION **sess, word32 *lockedRow, byte side);
47194719
WOLFSSL_LOCAL void EvictSessionFromCache(WOLFSSL_SESSION* session);
4720-
/* WOLFSSL_API to test it in tests/api.c */
4721-
WOLFSSL_API int wolfSSL_GetSessionFromCache(WOLFSSL* ssl, WOLFSSL_SESSION* output);
4720+
/* WOLFSSL_TEST_API to test it in tests/api.c */
4721+
WOLFSSL_TEST_API int wolfSSL_GetSessionFromCache(WOLFSSL* ssl, WOLFSSL_SESSION* output);
47224722
WOLFSSL_LOCAL int wolfSSL_SetSession(WOLFSSL* ssl, WOLFSSL_SESSION* session);
47234723
WOLFSSL_LOCAL void wolfSSL_FreeSession(WOLFSSL_CTX* ctx,
47244724
WOLFSSL_SESSION* session);
@@ -6382,7 +6382,7 @@ WOLFSSL_LOCAL int SetSSL_CTX(WOLFSSL* ssl, WOLFSSL_CTX* ctx, int writeDup);
63826382
WOLFSSL_LOCAL int InitSSL(WOLFSSL* ssl, WOLFSSL_CTX* ctx, int writeDup);
63836383
WOLFSSL_LOCAL int ReinitSSL(WOLFSSL* ssl, WOLFSSL_CTX* ctx, int writeDup);
63846384
WOLFSSL_LOCAL void FreeSSL(WOLFSSL* ssl, void* heap);
6385-
WOLFSSL_API void wolfSSL_ResourceFree(WOLFSSL* ssl); /* Micrium uses */
6385+
WOLFSSL_TEST_API void wolfSSL_ResourceFree(WOLFSSL* ssl); /* Micrium uses */
63866386
#ifndef OPENSSL_COEXIST
63876387
#define SSL_ResourceFree wolfSSL_ResourceFree
63886388
#endif
@@ -6748,18 +6748,18 @@ WOLFSSL_LOCAL word32 MacSize(const WOLFSSL* ssl);
67486748
#ifdef WOLFSSL_DTLS
67496749
WOLFSSL_LOCAL DtlsMsg* DtlsMsgNew(word32 sz, byte tx, void* heap);
67506750
WOLFSSL_LOCAL void DtlsMsgDelete(DtlsMsg* item, void* heap);
6751-
/* Use WOLFSSL_API to enable src/api.c testing */
6752-
WOLFSSL_API void DtlsMsgListDelete(DtlsMsg* head, void* heap);
6751+
/* Use WOLFSSL_TEST_API to enable src/api.c testing */
6752+
WOLFSSL_TEST_API void DtlsMsgListDelete(DtlsMsg* head, void* heap);
67536753
WOLFSSL_LOCAL void DtlsTxMsgListClean(WOLFSSL* ssl);
67546754
WOLFSSL_LOCAL int DtlsMsgSet(DtlsMsg* msg, word32 seq, word16 epoch,
67556755
const byte* data, byte type,
67566756
word32 fragOffset, word32 fragSz, void* heap,
67576757
word32 totalLen, byte encrypted);
6758-
/* Use WOLFSSL_API to enable src/api.c testing */
6759-
WOLFSSL_API DtlsMsg* DtlsMsgFind(DtlsMsg* head, word16 epoch, word32 seq);
6758+
/* Use WOLFSSL_TEST_API to enable src/api.c testing */
6759+
WOLFSSL_TEST_API DtlsMsg* DtlsMsgFind(DtlsMsg* head, word16 epoch, word32 seq);
67606760

6761-
/* Use WOLFSSL_API to enable src/api.c testing */
6762-
WOLFSSL_API void DtlsMsgStore(WOLFSSL* ssl, word16 epoch, word32 seq,
6761+
/* Use WOLFSSL_TEST_API to enable src/api.c testing */
6762+
WOLFSSL_TEST_API void DtlsMsgStore(WOLFSSL* ssl, word16 epoch, word32 seq,
67636763
const byte* data, word32 dataSz, byte type,
67646764
word32 fragOffset, word32 fragSz,
67656765
void* heap);
@@ -6949,8 +6949,8 @@ WOLFSSL_LOCAL int BuildMessage(WOLFSSL* ssl, byte* output, int outSz,
69496949
int sizeOnly, int asyncOkay, int epochOrder);
69506950

69516951
#ifdef WOLFSSL_TLS13
6952-
/* Use WOLFSSL_API to use this function in tests/api.c */
6953-
WOLFSSL_API int BuildTls13Message(WOLFSSL* ssl, byte* output, int outSz, const byte* input,
6952+
/* Use WOLFSSL_TEST_API to use this function in tests/api.c */
6953+
WOLFSSL_TEST_API int BuildTls13Message(WOLFSSL* ssl, byte* output, int outSz, const byte* input,
69546954
int inSz, int type, int hashOutput, int sizeOnly, int asyncOkay);
69556955
WOLFSSL_LOCAL int Tls13UpdateKeys(WOLFSSL* ssl);
69566956
#endif
@@ -7007,7 +7007,7 @@ WOLFSSL_LOCAL word32 nid2oid(int nid, int grp);
70077007
#endif
70087008

70097009
#ifdef WOLFSSL_DTLS
7010-
WOLFSSL_API int wolfSSL_DtlsUpdateWindow(word16 cur_hi, word32 cur_lo,
7010+
WOLFSSL_TEST_API int wolfSSL_DtlsUpdateWindow(word16 cur_hi, word32 cur_lo,
70117011
word16* next_hi, word32* next_lo, word32 *window);
70127012
WOLFSSL_LOCAL int DtlsUpdateWindow(WOLFSSL* ssl);
70137013
WOLFSSL_LOCAL void DtlsResetState(WOLFSSL *ssl);
@@ -7017,8 +7017,8 @@ WOLFSSL_LOCAL void DtlsSetSeqNumForReply(WOLFSSL* ssl);
70177017

70187018
#ifdef WOLFSSL_DTLS13
70197019

7020-
/* Use WOLFSSL_API to use this function in tests/api.c */
7021-
WOLFSSL_API struct Dtls13Epoch* Dtls13GetEpoch(WOLFSSL* ssl,
7020+
/* Use WOLFSSL_TEST_API to use this function in tests/api.c */
7021+
WOLFSSL_TEST_API struct Dtls13Epoch* Dtls13GetEpoch(WOLFSSL* ssl,
70227022
w64wrapper epochNumber);
70237023
WOLFSSL_LOCAL void Dtls13SetOlderEpochSide(WOLFSSL* ssl, w64wrapper epochNumber,
70247024
int side);
@@ -7109,8 +7109,8 @@ typedef struct CRYPTO_EX_cb_ctx {
71097109
} CRYPTO_EX_cb_ctx;
71107110

71117111
/* use wolfSSL_API visibility to be able to clear in tests/api.c */
7112-
WOLFSSL_API extern CRYPTO_EX_cb_ctx* crypto_ex_cb_ctx_session;
7113-
WOLFSSL_API void crypto_ex_cb_free(CRYPTO_EX_cb_ctx* cb_ctx);
7112+
WOLFSSL_TEST_API extern CRYPTO_EX_cb_ctx* crypto_ex_cb_ctx_session;
7113+
WOLFSSL_TEST_API void crypto_ex_cb_free(CRYPTO_EX_cb_ctx* cb_ctx);
71147114
WOLFSSL_LOCAL void crypto_ex_cb_setup_new_data(void *new_obj,
71157115
CRYPTO_EX_cb_ctx* cb_ctx, WOLFSSL_CRYPTO_EX_DATA* ex_data);
71167116
WOLFSSL_LOCAL void crypto_ex_cb_free_data(void *obj, CRYPTO_EX_cb_ctx* cb_ctx,

wolfssl/wolfcrypt/visibility.h

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,13 @@
5050
#define WOLFSSL_API
5151
#define WOLFSSL_LOCAL
5252
#endif /* HAVE_VISIBILITY */
53-
#else /* BUILDING_WOLFSSL */
53+
54+
#ifdef WOLFSSL_LOCALIZE_TEST_APIS
55+
#define WOLFSSL_TEST_API WOLFSSL_LOCAL
56+
#else
57+
#define WOLFSSL_TEST_API WOLFSSL_API
58+
#endif
59+
#else /* !BUILDING_WOLFSSL */
5460
#if defined(__WATCOMC__)
5561
#if defined(WOLFSSL_DLL) && defined(__NT__)
5662
#define WOLFSSL_API __declspec(dllimport)
@@ -70,7 +76,16 @@
7076
#define WOLFSSL_API
7177
#define WOLFSSL_LOCAL
7278
#endif
73-
#endif /* BUILDING_WOLFSSL */
79+
80+
#ifdef WOLFSSL_LOCALIZE_TEST_APIS
81+
#define WOLFSSL_TEST_API WOLFSSL_LOCAL WC_DEPRECATED
82+
#elif defined(WOLFSSL_ALLOW_TEST_APIS)
83+
#define WOLFSSL_TEST_API WOLFSSL_API
84+
#else
85+
#define WOLFSSL_TEST_API WOLFSSL_API WC_DEPRECATED
86+
#endif
87+
88+
#endif /* !BUILDING_WOLFSSL */
7489

7590
/* WOLFSSL_ABI is used for public API symbols that must not change
7691
* their signature. This tag is used for all APIs that are a

wolfssl/wolfcrypt/wc_port.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,15 @@
8282
#endif
8383
#endif /* !WC_MAYBE_UNUSED */
8484

85+
#ifndef WC_DEPRECATED
86+
#if (defined(__GNUC__) && (__GNUC__ >= 4)) || defined(__clang__) || \
87+
defined(__IAR_SYSTEMS_ICC__)
88+
#define WC_DEPRECATED __attribute__((deprecated))
89+
#else
90+
#define WC_DEPRECATED
91+
#endif
92+
#endif /* !WC_MAYBE_UNUSED */
93+
8594
/* use inlining if compiler allows */
8695
#ifndef WC_INLINE
8796
#ifndef NO_INLINE

0 commit comments

Comments
 (0)