From 9e4dcfb66ce20f1271c02a56ee74fe050040019c Mon Sep 17 00:00:00 2001 From: TakayukiMatsuo Date: Tue, 23 Feb 2021 11:12:12 +0900 Subject: [PATCH 1/3] Add wolfSSL_BIO_tell --- src/bio.c | 19 +++++++++++++++++++ tests/api.c | 6 ++++++ wolfssl/openssl/bio.h | 1 + wolfssl/ssl.h | 1 + 4 files changed, 27 insertions(+) diff --git a/src/bio.c b/src/bio.c index d80b7c096..74535614e 100644 --- a/src/bio.c +++ b/src/bio.c @@ -1439,6 +1439,25 @@ int wolfSSL_BIO_seek(WOLFSSL_BIO *bio, int ofs) return 0; } +int wolfSSL_BIO_tell(WOLFSSL_BIO* bio) +{ + WOLFSSL_ENTER("wolfSSL_BIO_tell"); + int pos; + + if (bio == NULL) { + return -1; + } + + if (bio->type != WOLFSSL_BIO_FILE) { + return 0; + } + + pos =(int) XFTELL((XFILE)bio->ptr); + if(pos < 0) + return -1; + else + return pos; +} #endif /* NO_FILESYSTEM */ diff --git a/tests/api.c b/tests/api.c index 6a2283663..08c4ddf01 100644 --- a/tests/api.c +++ b/tests/api.c @@ -29222,12 +29222,18 @@ static void test_wolfSSL_BIO(void) WOLFSSL_SUCCESS); AssertIntEQ(BIO_read(f_bio1, cert, sizeof(cert)), sizeof(cert)); + AssertIntEQ(BIO_tell(f_bio1),sizeof(cert)); AssertIntEQ(BIO_write(f_bio2, msg, sizeof(msg)), sizeof(msg)); + AssertIntEQ(BIO_tell(f_bio2),sizeof(msg)); AssertIntEQ(BIO_write(f_bio2, cert, sizeof(cert)), sizeof(cert)); + AssertIntEQ(BIO_tell(f_bio2),sizeof(cert) + sizeof(msg)); AssertIntEQ((int)BIO_get_fp(f_bio2, &f2), WOLFSSL_SUCCESS); AssertIntEQ(BIO_reset(f_bio2), 0); + AssertIntEQ(BIO_tell(NULL),-1); + AssertIntEQ(BIO_tell(f_bio2),0); AssertIntEQ(BIO_seek(f_bio2, 4), 0); + AssertIntEQ(BIO_tell(f_bio2),4); BIO_free(f_bio1); BIO_free(f_bio2); diff --git a/wolfssl/openssl/bio.h b/wolfssl/openssl/bio.h index c5786b73a..edafd2152 100644 --- a/wolfssl/openssl/bio.h +++ b/wolfssl/openssl/bio.h @@ -68,6 +68,7 @@ #define BIO_set_fp wolfSSL_BIO_set_fp #define BIO_get_fp wolfSSL_BIO_get_fp #define BIO_seek wolfSSL_BIO_seek +#define BIO_tell wolfSSL_BIO_tell #define BIO_write_filename wolfSSL_BIO_write_filename #define BIO_set_mem_eof_return wolfSSL_BIO_set_mem_eof_return diff --git a/wolfssl/ssl.h b/wolfssl/ssl.h index 0c81c9b77..d1b70c0cd 100644 --- a/wolfssl/ssl.h +++ b/wolfssl/ssl.h @@ -1336,6 +1336,7 @@ WOLFSSL_API int wolfSSL_BIO_nwrite(WOLFSSL_BIO *bio, char **buf, int num); WOLFSSL_API int wolfSSL_BIO_reset(WOLFSSL_BIO *bio); WOLFSSL_API int wolfSSL_BIO_seek(WOLFSSL_BIO *bio, int ofs); +WOLFSSL_API int wolfSSL_BIO_tell(WOLFSSL_BIO* bio); WOLFSSL_API int wolfSSL_BIO_write_filename(WOLFSSL_BIO *bio, char *name); WOLFSSL_API long wolfSSL_BIO_set_mem_eof_return(WOLFSSL_BIO *bio, int v); WOLFSSL_API long wolfSSL_BIO_get_mem_ptr(WOLFSSL_BIO *bio, WOLFSSL_BUF_MEM **m); From 362d2a2d6837b22feac393223c151508de6362d7 Mon Sep 17 00:00:00 2001 From: TakayukiMatsuo Date: Wed, 24 Feb 2021 01:07:45 +0900 Subject: [PATCH 2/3] Moved int pos declaration at the top the func --- src/bio.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/bio.c b/src/bio.c index 74535614e..d3bf6e4fe 100644 --- a/src/bio.c +++ b/src/bio.c @@ -1441,9 +1441,10 @@ int wolfSSL_BIO_seek(WOLFSSL_BIO *bio, int ofs) } int wolfSSL_BIO_tell(WOLFSSL_BIO* bio) { - WOLFSSL_ENTER("wolfSSL_BIO_tell"); int pos; + WOLFSSL_ENTER("wolfSSL_BIO_tell"); + if (bio == NULL) { return -1; } @@ -1452,8 +1453,8 @@ int wolfSSL_BIO_tell(WOLFSSL_BIO* bio) return 0; } - pos =(int) XFTELL((XFILE)bio->ptr); - if(pos < 0) + pos = (int)XFTELL((XFILE)bio->ptr); + if (pos < 0) return -1; else return pos; From 871933e3e8e3ccef3ee18540035da30f23868ed8 Mon Sep 17 00:00:00 2001 From: TakayukiMatsuo Date: Thu, 4 Mar 2021 15:41:03 +0900 Subject: [PATCH 3/3] Add s comment to wolfSSL_BIO_tell --- src/bio.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/bio.c b/src/bio.c index d3bf6e4fe..17541ea2d 100644 --- a/src/bio.c +++ b/src/bio.c @@ -1439,6 +1439,11 @@ int wolfSSL_BIO_seek(WOLFSSL_BIO *bio, int ofs) return 0; } +/* wolfSSL_BIO_tell is provided as compatible API with + * BIO_tell which returns the current file position of a file related BIO. + * Returns the current file position on success and -1 for failure. + * Returns 0 for a BIOs except file related BIO. + */ int wolfSSL_BIO_tell(WOLFSSL_BIO* bio) { int pos;