Przeglądaj źródła

Merge pull request #3801 from TakayukiMatsuo/os_bio

Add wolfSSL_BIO_tell
Chris Conlon 3 lat temu
rodzic
commit
7b2aa54044
4 zmienionych plików z 33 dodań i 0 usunięć
  1. 25 0
      src/bio.c
  2. 6 0
      tests/api.c
  3. 1 0
      wolfssl/openssl/bio.h
  4. 1 0
      wolfssl/ssl.h

+ 25 - 0
src/bio.c

@@ -1439,6 +1439,31 @@ 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;
+
+    WOLFSSL_ENTER("wolfSSL_BIO_tell");
+
+    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 */
 
 

+ 6 - 0
tests/api.c

@@ -29345,12 +29345,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);

+ 1 - 0
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
 

+ 1 - 0
wolfssl/ssl.h

@@ -1353,6 +1353,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);