File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -4496,6 +4496,53 @@ WOLFSSL_METHOD* wolfSSLv23_client_method(void);
44964496*/
44974497int wolfSSL_BIO_get_mem_data(WOLFSSL_BIO* bio,void* p);
44984498
4499+ /*!
4500+ \ingroup IO
4501+
4502+ \brief This is used to set the init flag of a BIO, indicating whether
4503+ the BIO has been initialised and is ready for use. Typically called
4504+ from a custom BIO create callback.
4505+
4506+ \param bio WOLFSSL_BIO structure to set the init flag on.
4507+ \param init value to set (0 = not initialised, 1 = initialised).
4508+
4509+ _Example_
4510+ \code
4511+ WOLFSSL_BIO* bio;
4512+ // inside a custom BIO create callback
4513+ wolfSSL_BIO_set_init(bio, 1);
4514+ \endcode
4515+
4516+ \sa wolfSSL_BIO_get_init
4517+ \sa wolfSSL_BIO_new
4518+ */
4519+ void wolfSSL_BIO_set_init(WOLFSSL_BIO* bio, int init);
4520+
4521+ /*!
4522+ \ingroup IO
4523+
4524+ \brief This is used to retrieve the init flag of a BIO, indicating
4525+ whether the BIO has been initialised and is ready for use.
4526+
4527+ \return 1 if the BIO has been initialised.
4528+ \return 0 if the BIO has not been initialised or bio is NULL.
4529+
4530+ \param bio WOLFSSL_BIO structure to query.
4531+
4532+ _Example_
4533+ \code
4534+ WOLFSSL_BIO* bio;
4535+ // create bio with custom method
4536+ if (wolfSSL_BIO_get_init(bio)) {
4537+ // bio is ready
4538+ }
4539+ \endcode
4540+
4541+ \sa wolfSSL_BIO_set_init
4542+ \sa wolfSSL_BIO_new
4543+ */
4544+ int wolfSSL_BIO_get_init(WOLFSSL_BIO* bio);
4545+
44994546/*!
45004547 \ingroup IO
45014548
Original file line number Diff line number Diff line change @@ -2032,6 +2032,12 @@ void wolfSSL_BIO_set_init(WOLFSSL_BIO* bio, int init)
20322032 bio -> init = (byte )(init != 0 );
20332033}
20342034
2035+ int wolfSSL_BIO_get_init (WOLFSSL_BIO * bio )
2036+ {
2037+ WOLFSSL_ENTER ("wolfSSL_BIO_get_init" );
2038+ return bio != NULL && bio -> init ;
2039+ }
2040+
20352041/* If flag is 0 then blocking is set, if 1 then non blocking.
20362042 * Always returns WOLFSSL_SUCCESS.
20372043 */
Original file line number Diff line number Diff line change @@ -1803,5 +1803,41 @@ int test_wolfSSL_BIO_meth_type_large(void)
18031803 return EXPECT_RESULT ();
18041804}
18051805
1806+ int test_wolfSSL_BIO_get_init (void )
1807+ {
1808+ EXPECT_DECLS ;
1809+ #if defined(OPENSSL_EXTRA )
1810+ BIO_METHOD * method = NULL ;
1811+ BIO * bio = NULL ;
1812+
1813+ /* BIO_new with a custom method that calls BIO_set_init(bio, 1) */
1814+ ExpectNotNull (method = BIO_meth_new (WOLFSSL_BIO_UNDEF , "get_init_test" ));
1815+ ExpectIntEQ (BIO_meth_set_create (method , custom_bio_createCb ),
1816+ WOLFSSL_SUCCESS );
1817+ ExpectIntEQ (BIO_meth_set_destroy (method , custom_bio_destroyCb ),
1818+ WOLFSSL_SUCCESS );
1819+
1820+ ExpectNotNull (bio = BIO_new (method ));
1821+
1822+ /* createCb calls BIO_set_init(bio, 1), so get_init should return 1 */
1823+ ExpectIntEQ (BIO_get_init (bio ), 1 );
1824+
1825+ /* Clear init and verify it returns 0 */
1826+ BIO_set_init (bio , 0 );
1827+ ExpectIntEQ (BIO_get_init (bio ), 0 );
1828+
1829+ /* Set init back and verify */
1830+ BIO_set_init (bio , 1 );
1831+ ExpectIntEQ (BIO_get_init (bio ), 1 );
1832+
1833+ /* NULL should return 0 */
1834+ ExpectIntEQ (BIO_get_init (NULL ), 0 );
1835+
1836+ BIO_free (bio );
1837+ BIO_meth_free (method );
1838+ #endif
1839+ return EXPECT_RESULT ();
1840+ }
1841+
18061842#endif /* !NO_BIO */
18071843
Original file line number Diff line number Diff line change @@ -46,6 +46,7 @@ int test_wolfSSL_BIO_custom_method(void);
4646int test_wolfSSL_BIO_set_conn_hostname (void );
4747int test_wolfSSL_BIO_ctrl_pending_chain (void );
4848int test_wolfSSL_BIO_meth_type_large (void );
49+ int test_wolfSSL_BIO_get_init (void );
4950
5051#define TEST_OSSL_BIO_DECLS \
5152 TEST_DECL_GROUP("ossl_bio", test_wolfSSL_BIO_gets), \
@@ -64,7 +65,8 @@ int test_wolfSSL_BIO_meth_type_large(void);
6465 TEST_DECL_GROUP("ossl_bio", test_wolfSSL_BIO_custom_method), \
6566 TEST_DECL_GROUP("ossl_bio", test_wolfSSL_BIO_set_conn_hostname), \
6667 TEST_DECL_GROUP("ossl_bio", test_wolfSSL_BIO_ctrl_pending_chain), \
67- TEST_DECL_GROUP("ossl_bio", test_wolfSSL_BIO_meth_type_large)
68+ TEST_DECL_GROUP("ossl_bio", test_wolfSSL_BIO_meth_type_large), \
69+ TEST_DECL_GROUP("ossl_bio", test_wolfSSL_BIO_get_init)
6870
6971#define TEST_OSSL_BIO_TLS_DECLS \
7072 TEST_DECL_GROUP("ossl_bio_tls", test_wolfSSL_BIO_connect), \
Original file line number Diff line number Diff line change 159159
160160/* BIO for 1.1.0 or later */
161161#define BIO_set_init wolfSSL_BIO_set_init
162+ #define BIO_get_init wolfSSL_BIO_get_init
162163#define BIO_get_data wolfSSL_BIO_get_data
163164#define BIO_set_data wolfSSL_BIO_set_data
164165#define BIO_get_shutdown wolfSSL_BIO_get_shutdown
Original file line number Diff line number Diff line change @@ -2120,6 +2120,7 @@ WOLFSSL_API long wolfSSL_BIO_set_nbio(WOLFSSL_BIO* bio, long on);
21202120WOLFSSL_API int wolfSSL_BIO_get_mem_data (WOLFSSL_BIO * bio ,void * p );
21212121
21222122WOLFSSL_API void wolfSSL_BIO_set_init (WOLFSSL_BIO * bio , int init );
2123+ WOLFSSL_API int wolfSSL_BIO_get_init (WOLFSSL_BIO * bio );
21232124WOLFSSL_API void wolfSSL_BIO_set_data (WOLFSSL_BIO * bio , void * ptr );
21242125WOLFSSL_API void * wolfSSL_BIO_get_data (WOLFSSL_BIO * bio );
21252126WOLFSSL_API void wolfSSL_BIO_set_shutdown (WOLFSSL_BIO * bio , int shut );
You can’t perform that action at this time.
0 commit comments