Skip to content

Commit 97d86b8

Browse files
Merge pull request #8628 from douzzer/20250402-WOLFSSL_TEST_API
20250402-WOLFSSL_TEST_API
2 parents 827516c + 96118b4 commit 97d86b8

5 files changed

Lines changed: 59 additions & 25 deletions

File tree

tests/api.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42578,7 +42578,7 @@ static int test_wolfSSL_TXT_DB(void)
4257842578

4257942579
/* Test index */
4258042580
ExpectIntEQ(TXT_DB_create_index(db, 3, NULL,
42581-
(wolf_sk_hash_cb)(long unsigned int)TXT_DB_hash,
42581+
(wolf_sk_hash_cb)(wc_ptr_t)TXT_DB_hash,
4258242582
(wolf_lh_compare_cb)TXT_DB_cmp), 1);
4258342583
ExpectNotNull(TXT_DB_get_by_index(db, 3, (WOLFSSL_STRING*)fields));
4258442584
fields[3] = "12DA";

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_VIS_FOR_TESTS
27+
2628
#ifdef HAVE_CONFIG_H
2729
#include <config.h>
2830
#endif

wolfssl/internal.h

Lines changed: 19 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -2435,8 +2435,7 @@ 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+
WOLFSSL_TEST_VIS void InitSuitesHashSigAlgo(byte* hashSigAlgo, int have,
24402439
int tls1_2, int keySz, word16* len);
24412440
WOLFSSL_LOCAL int AllocateCtxSuites(WOLFSSL_CTX* ctx);
24422441
WOLFSSL_LOCAL int AllocateSuites(WOLFSSL* ssl);
@@ -3396,7 +3395,7 @@ WOLFSSL_LOCAL int TLSX_CSR2_ForceRequest(WOLFSSL* ssl);
33963395
#if defined(WOLFSSL_PUBLIC_ASN) && defined(HAVE_PK_CALLBACKS)
33973396
/* Internal callback guarded by WOLFSSL_PUBLIC_ASN because of DecodedCert. */
33983397
typedef int (*CallbackProcessPeerCert)(WOLFSSL* ssl, DecodedCert* p_cert);
3399-
WOLFSSL_API void wolfSSL_CTX_SetProcessPeerCertCb(WOLFSSL_CTX* ctx,
3398+
WOLFSSL_TEST_VIS void wolfSSL_CTX_SetProcessPeerCertCb(WOLFSSL_CTX* ctx,
34003399
CallbackProcessPeerCert cb);
34013400
#endif /* DecodedCert && HAVE_PK_CALLBACKS */
34023401

@@ -4700,8 +4699,7 @@ WOLFSSL_LOCAL WOLFSSL_SESSION* wolfSSL_GetSession(
47004699
WOLFSSL* ssl, byte* masterSecret, byte restoreSessionCerts);
47014700
WOLFSSL_LOCAL void SetupSession(WOLFSSL* ssl);
47024701
WOLFSSL_LOCAL void AddSession(WOLFSSL* ssl);
4703-
/* use wolfSSL_API visibility to be able to test in tests/api.c */
4704-
WOLFSSL_API int AddSessionToCache(WOLFSSL_CTX* ctx,
4702+
WOLFSSL_TEST_VIS int AddSessionToCache(WOLFSSL_CTX* ctx,
47054703
WOLFSSL_SESSION* addSession, const byte* id, byte idSz, int* sessionIndex,
47064704
int side, word16 useTicket, ClientSession** clientCacheEntry);
47074705
#ifndef NO_CLIENT_CACHE
@@ -4717,8 +4715,8 @@ WOLFSSL_LOCAL int TlsSessionCacheGetAndRdLock(const byte *id,
47174715
WOLFSSL_LOCAL int TlsSessionCacheGetAndWrLock(const byte *id,
47184716
WOLFSSL_SESSION **sess, word32 *lockedRow, byte side);
47194717
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);
4718+
/* WOLFSSL_TEST_VIS to test it in tests/api.c */
4719+
WOLFSSL_TEST_VIS int wolfSSL_GetSessionFromCache(WOLFSSL* ssl, WOLFSSL_SESSION* output);
47224720
WOLFSSL_LOCAL int wolfSSL_SetSession(WOLFSSL* ssl, WOLFSSL_SESSION* session);
47234721
WOLFSSL_LOCAL void wolfSSL_FreeSession(WOLFSSL_CTX* ctx,
47244722
WOLFSSL_SESSION* session);
@@ -6382,7 +6380,7 @@ WOLFSSL_LOCAL int SetSSL_CTX(WOLFSSL* ssl, WOLFSSL_CTX* ctx, int writeDup);
63826380
WOLFSSL_LOCAL int InitSSL(WOLFSSL* ssl, WOLFSSL_CTX* ctx, int writeDup);
63836381
WOLFSSL_LOCAL int ReinitSSL(WOLFSSL* ssl, WOLFSSL_CTX* ctx, int writeDup);
63846382
WOLFSSL_LOCAL void FreeSSL(WOLFSSL* ssl, void* heap);
6385-
WOLFSSL_API void wolfSSL_ResourceFree(WOLFSSL* ssl); /* Micrium uses */
6383+
WOLFSSL_TEST_VIS void wolfSSL_ResourceFree(WOLFSSL* ssl); /* Micrium uses */
63866384
#ifndef OPENSSL_COEXIST
63876385
#define SSL_ResourceFree wolfSSL_ResourceFree
63886386
#endif
@@ -6748,18 +6746,18 @@ WOLFSSL_LOCAL word32 MacSize(const WOLFSSL* ssl);
67486746
#ifdef WOLFSSL_DTLS
67496747
WOLFSSL_LOCAL DtlsMsg* DtlsMsgNew(word32 sz, byte tx, void* heap);
67506748
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);
6749+
/* Use WOLFSSL_TEST_VIS to enable src/api.c testing */
6750+
WOLFSSL_TEST_VIS void DtlsMsgListDelete(DtlsMsg* head, void* heap);
67536751
WOLFSSL_LOCAL void DtlsTxMsgListClean(WOLFSSL* ssl);
67546752
WOLFSSL_LOCAL int DtlsMsgSet(DtlsMsg* msg, word32 seq, word16 epoch,
67556753
const byte* data, byte type,
67566754
word32 fragOffset, word32 fragSz, void* heap,
67576755
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);
6756+
/* Use WOLFSSL_TEST_VIS to enable src/api.c testing */
6757+
WOLFSSL_TEST_VIS DtlsMsg* DtlsMsgFind(DtlsMsg* head, word16 epoch, word32 seq);
67606758

6761-
/* Use WOLFSSL_API to enable src/api.c testing */
6762-
WOLFSSL_API void DtlsMsgStore(WOLFSSL* ssl, word16 epoch, word32 seq,
6759+
/* Use WOLFSSL_TEST_VIS to enable src/api.c testing */
6760+
WOLFSSL_TEST_VIS void DtlsMsgStore(WOLFSSL* ssl, word16 epoch, word32 seq,
67636761
const byte* data, word32 dataSz, byte type,
67646762
word32 fragOffset, word32 fragSz,
67656763
void* heap);
@@ -6949,8 +6947,8 @@ WOLFSSL_LOCAL int BuildMessage(WOLFSSL* ssl, byte* output, int outSz,
69496947
int sizeOnly, int asyncOkay, int epochOrder);
69506948

69516949
#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,
6950+
/* Use WOLFSSL_TEST_VIS to use this function in tests/api.c */
6951+
WOLFSSL_TEST_VIS int BuildTls13Message(WOLFSSL* ssl, byte* output, int outSz, const byte* input,
69546952
int inSz, int type, int hashOutput, int sizeOnly, int asyncOkay);
69556953
WOLFSSL_LOCAL int Tls13UpdateKeys(WOLFSSL* ssl);
69566954
#endif
@@ -7007,7 +7005,7 @@ WOLFSSL_LOCAL word32 nid2oid(int nid, int grp);
70077005
#endif
70087006

70097007
#ifdef WOLFSSL_DTLS
7010-
WOLFSSL_API int wolfSSL_DtlsUpdateWindow(word16 cur_hi, word32 cur_lo,
7008+
WOLFSSL_TEST_VIS int wolfSSL_DtlsUpdateWindow(word16 cur_hi, word32 cur_lo,
70117009
word16* next_hi, word32* next_lo, word32 *window);
70127010
WOLFSSL_LOCAL int DtlsUpdateWindow(WOLFSSL* ssl);
70137011
WOLFSSL_LOCAL void DtlsResetState(WOLFSSL *ssl);
@@ -7017,8 +7015,8 @@ WOLFSSL_LOCAL void DtlsSetSeqNumForReply(WOLFSSL* ssl);
70177015

70187016
#ifdef WOLFSSL_DTLS13
70197017

7020-
/* Use WOLFSSL_API to use this function in tests/api.c */
7021-
WOLFSSL_API struct Dtls13Epoch* Dtls13GetEpoch(WOLFSSL* ssl,
7018+
/* Use WOLFSSL_TEST_VIS to use this function in tests/api.c */
7019+
WOLFSSL_TEST_VIS struct Dtls13Epoch* Dtls13GetEpoch(WOLFSSL* ssl,
70227020
w64wrapper epochNumber);
70237021
WOLFSSL_LOCAL void Dtls13SetOlderEpochSide(WOLFSSL* ssl, w64wrapper epochNumber,
70247022
int side);
@@ -7108,9 +7106,8 @@ typedef struct CRYPTO_EX_cb_ctx {
71087106
struct CRYPTO_EX_cb_ctx* next;
71097107
} CRYPTO_EX_cb_ctx;
71107108

7111-
/* 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);
7109+
WOLFSSL_TEST_VIS extern CRYPTO_EX_cb_ctx* crypto_ex_cb_ctx_session;
7110+
WOLFSSL_TEST_VIS void crypto_ex_cb_free(CRYPTO_EX_cb_ctx* cb_ctx);
71147111
WOLFSSL_LOCAL void crypto_ex_cb_setup_new_data(void *new_obj,
71157112
CRYPTO_EX_cb_ctx* cb_ctx, WOLFSSL_CRYPTO_EX_DATA* ex_data);
71167113
WOLFSSL_LOCAL void crypto_ex_cb_free_data(void *obj, CRYPTO_EX_cb_ctx* cb_ctx,

wolfssl/wolfcrypt/visibility.h

Lines changed: 18 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_PRIVATE_TEST_VIS
55+
#define WOLFSSL_TEST_VIS WOLFSSL_LOCAL
56+
#else
57+
#define WOLFSSL_TEST_VIS 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,17 @@
7076
#define WOLFSSL_API
7177
#define WOLFSSL_LOCAL
7278
#endif
73-
#endif /* BUILDING_WOLFSSL */
79+
80+
#if defined(WOLFSSL_VIS_FOR_TESTS)
81+
#ifdef WOLFSSL_PRIVATE_TEST_VIS
82+
#error WOLFSSL_VIS_FOR_TESTS is unavailable in WOLFSSL_PRIVATE_TEST_VIS builds.
83+
#endif
84+
#define WOLFSSL_TEST_VIS WOLFSSL_API
85+
#else
86+
#define WOLFSSL_TEST_VIS WOLFSSL_API WC_DEPRECATED("internal use only")
87+
#endif
88+
89+
#endif /* !BUILDING_WOLFSSL */
7490

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

wolfssl/wolfcrypt/wc_port.h

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

85+
#ifndef WC_DEPRECATED
86+
#ifdef WOLFSSL_ZEPHYR
87+
#define WC_DEPRECATED(msg) /* null expansion */
88+
#elif ((defined(__GNUC__) && \
89+
((__GNUC__ >= 5) || \
90+
((__GNUC__ == 4) && (__GNUC_MINOR__ > 5))))) || \
91+
defined(__clang__)
92+
#define WC_DEPRECATED(msg) __attribute__((deprecated(msg)))
93+
#elif defined(_MSC_VER) || defined(__MINGW32__) || defined(__CYGWIN__) || \
94+
defined(_WIN32_WCE) || defined(__WATCOMC__)
95+
#define WC_DEPRECATED(msg) __declspec(deprecated(msg))
96+
#elif (defined(__GNUC__) && (__GNUC__ >= 4)) || \
97+
defined(__IAR_SYSTEMS_ICC__)
98+
#define WC_DEPRECATED(msg) __attribute__((deprecated))
99+
#else
100+
#define WC_DEPRECATED(msg) /* null expansion */
101+
#endif
102+
#endif /* !WC_MAYBE_UNUSED */
103+
85104
/* use inlining if compiler allows */
86105
#ifndef WC_INLINE
87106
#ifndef NO_INLINE

0 commit comments

Comments
 (0)