Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 47 additions & 0 deletions doc/dox_comments/header_files/ssl.h
Original file line number Diff line number Diff line change
Expand Up @@ -4496,6 +4496,53 @@ WOLFSSL_METHOD* wolfSSLv23_client_method(void);
*/
int wolfSSL_BIO_get_mem_data(WOLFSSL_BIO* bio,void* p);

/*!
\ingroup IO

\brief This is used to set the init flag of a BIO, indicating whether
the BIO has been initialised and is ready for use. Typically called
from a custom BIO create callback.

\param bio WOLFSSL_BIO structure to set the init flag on.
\param init value to set (0 = not initialised, 1 = initialised).

_Example_
\code
WOLFSSL_BIO* bio;
// inside a custom BIO create callback
wolfSSL_BIO_set_init(bio, 1);
\endcode

\sa wolfSSL_BIO_get_init
\sa wolfSSL_BIO_new
*/
void wolfSSL_BIO_set_init(WOLFSSL_BIO* bio, int init);

/*!
\ingroup IO

\brief This is used to retrieve the init flag of a BIO, indicating
whether the BIO has been initialised and is ready for use.

\return 1 if the BIO has been initialised.
\return 0 if the BIO has not been initialised or bio is NULL.

\param bio WOLFSSL_BIO structure to query.

_Example_
\code
WOLFSSL_BIO* bio;
// create bio with custom method
if (wolfSSL_BIO_get_init(bio)) {
// bio is ready
}
\endcode

\sa wolfSSL_BIO_set_init
\sa wolfSSL_BIO_new
*/
int wolfSSL_BIO_get_init(WOLFSSL_BIO* bio);

/*!
\ingroup IO

Expand Down
6 changes: 6 additions & 0 deletions src/bio.c
Original file line number Diff line number Diff line change
Expand Up @@ -2032,6 +2032,12 @@ void wolfSSL_BIO_set_init(WOLFSSL_BIO* bio, int init)
bio->init = (byte)(init != 0);
}

int wolfSSL_BIO_get_init(WOLFSSL_BIO* bio)
{
WOLFSSL_ENTER("wolfSSL_BIO_get_init");
return bio != NULL && bio->init;
}

/* If flag is 0 then blocking is set, if 1 then non blocking.
* Always returns WOLFSSL_SUCCESS.
*/
Expand Down
36 changes: 36 additions & 0 deletions tests/api/test_ossl_bio.c
Original file line number Diff line number Diff line change
Expand Up @@ -1803,5 +1803,41 @@ int test_wolfSSL_BIO_meth_type_large(void)
return EXPECT_RESULT();
}

int test_wolfSSL_BIO_get_init(void)
{
EXPECT_DECLS;
#if defined(OPENSSL_EXTRA)
BIO_METHOD* method = NULL;
BIO* bio = NULL;

/* BIO_new with a custom method that calls BIO_set_init(bio, 1) */
ExpectNotNull(method = BIO_meth_new(WOLFSSL_BIO_UNDEF, "get_init_test"));
ExpectIntEQ(BIO_meth_set_create(method, custom_bio_createCb),
WOLFSSL_SUCCESS);
ExpectIntEQ(BIO_meth_set_destroy(method, custom_bio_destroyCb),
WOLFSSL_SUCCESS);

ExpectNotNull(bio = BIO_new(method));

/* createCb calls BIO_set_init(bio, 1), so get_init should return 1 */
ExpectIntEQ(BIO_get_init(bio), 1);

/* Clear init and verify it returns 0 */
BIO_set_init(bio, 0);
ExpectIntEQ(BIO_get_init(bio), 0);

/* Set init back and verify */
BIO_set_init(bio, 1);
ExpectIntEQ(BIO_get_init(bio), 1);

/* NULL should return 0 */
ExpectIntEQ(BIO_get_init(NULL), 0);

BIO_free(bio);
BIO_meth_free(method);
#endif
return EXPECT_RESULT();
}

#endif /* !NO_BIO */

4 changes: 3 additions & 1 deletion tests/api/test_ossl_bio.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ int test_wolfSSL_BIO_custom_method(void);
int test_wolfSSL_BIO_set_conn_hostname(void);
int test_wolfSSL_BIO_ctrl_pending_chain(void);
int test_wolfSSL_BIO_meth_type_large(void);
int test_wolfSSL_BIO_get_init(void);

#define TEST_OSSL_BIO_DECLS \
TEST_DECL_GROUP("ossl_bio", test_wolfSSL_BIO_gets), \
Expand All @@ -64,7 +65,8 @@ int test_wolfSSL_BIO_meth_type_large(void);
TEST_DECL_GROUP("ossl_bio", test_wolfSSL_BIO_custom_method), \
TEST_DECL_GROUP("ossl_bio", test_wolfSSL_BIO_set_conn_hostname), \
TEST_DECL_GROUP("ossl_bio", test_wolfSSL_BIO_ctrl_pending_chain), \
TEST_DECL_GROUP("ossl_bio", test_wolfSSL_BIO_meth_type_large)
TEST_DECL_GROUP("ossl_bio", test_wolfSSL_BIO_meth_type_large), \
TEST_DECL_GROUP("ossl_bio", test_wolfSSL_BIO_get_init)

#define TEST_OSSL_BIO_TLS_DECLS \
TEST_DECL_GROUP("ossl_bio_tls", test_wolfSSL_BIO_connect), \
Expand Down
1 change: 1 addition & 0 deletions wolfssl/openssl/bio.h
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,7 @@

/* BIO for 1.1.0 or later */
#define BIO_set_init wolfSSL_BIO_set_init
#define BIO_get_init wolfSSL_BIO_get_init
#define BIO_get_data wolfSSL_BIO_get_data
#define BIO_set_data wolfSSL_BIO_set_data
#define BIO_get_shutdown wolfSSL_BIO_get_shutdown
Expand Down
1 change: 1 addition & 0 deletions wolfssl/ssl.h
Original file line number Diff line number Diff line change
Expand Up @@ -2120,6 +2120,7 @@ WOLFSSL_API long wolfSSL_BIO_set_nbio(WOLFSSL_BIO* bio, long on);
WOLFSSL_API int wolfSSL_BIO_get_mem_data(WOLFSSL_BIO* bio,void* p);

WOLFSSL_API void wolfSSL_BIO_set_init(WOLFSSL_BIO* bio, int init);
WOLFSSL_API int wolfSSL_BIO_get_init(WOLFSSL_BIO* bio);
WOLFSSL_API void wolfSSL_BIO_set_data(WOLFSSL_BIO* bio, void* ptr);
WOLFSSL_API void* wolfSSL_BIO_get_data(WOLFSSL_BIO* bio);
WOLFSSL_API void wolfSSL_BIO_set_shutdown(WOLFSSL_BIO* bio, int shut);
Expand Down
Loading