FreeRTOS-Plus/ThirdParty/WolfSSL-FIPS-Ready/src/bio.c
/* Handles reading from a memory type BIO and advancing the state.
 *
 * bio  WOLFSSL_BIO to read from
 * buf  buffer to put data from bio in
 * len  amount of data to be read
 *
 * returns size read on success
 */
Handles reading from a memory type BIO and advancing the state.
bio  WOLFSSL_BIO to read from
buf  buffer to put data from bio in
len  amount of data to be read

returns size read on success
Handles reading from a memory type BIO and advancing the state . bio WOLFSSL_BIO to read from buf buffer to put data from bio in len amount of data to be read returns size read on success
static int wolfSSL_BIO_MEMORY_read(WOLFSSL_BIO* bio, void* buf, int len)
{
    int   sz;
    WOLFSSL_ENTER("wolfSSL_BIO_MEMORY_read");
    sz = wolfSSL_BIO_pending(bio);
    if (sz > 0) {
        const unsigned char* pt = NULL;
        int memSz;
        if (sz > len) {
            sz = len;
        }
        memSz = wolfSSL_BIO_get_mem_data(bio, (void*)&pt);
        if (memSz >= sz && pt != NULL) {
            byte* tmp;
            XMEMCPY(buf, (void*)pt, sz);
            if (memSz - sz > 0) {
                tmp = (byte*)XMALLOC(memSz-sz, bio->heap, DYNAMIC_TYPE_OPENSSL);
                if (tmp == NULL) {
                    WOLFSSL_MSG("Memory error");
                    return WOLFSSL_BIO_ERROR;
                }
                XMEMCPY(tmp, (void*)(pt + sz), memSz - sz);
                XFREE(bio->ptr, bio->heap, DYNAMIC_TYPE_OPENSSL);
                bio->ptr    = tmp;
                bio->num = memSz-sz;
                if (bio->mem_buf != NULL) {
                    bio->mem_buf->data = (char*)bio->ptr;
                    bio->mem_buf->length = bio->num;
                }
            }
            bio->wrSz  -= sz;
        }
        else {
            WOLFSSL_MSG("Issue with getting bio mem pointer");
            return 0;
        }
    }
    else {
        return WOLFSSL_BIO_ERROR;
    }
    return sz;
}
static int wolfSSL_BIO_MEMORY_read ( WOLFSSL_BIO * bio , void * buf , int len ) { int sz ; WOLFSSL_ENTER ( " " ) ; sz = wolfSSL_BIO_pending ( bio ) ; if ( sz > 0 ) { const unsigned char * pt = NULL ; int memSz ; if ( sz > len ) { sz = len ; } memSz = wolfSSL_BIO_get_mem_data ( bio , ( void * ) & pt ) ; if ( memSz >= sz && pt != NULL ) { byte * tmp ; XMEMCPY ( buf , ( void * ) pt , sz ) ; if ( memSz - sz > 0 ) { tmp = ( byte * ) XMALLOC ( memSz - sz , bio -> heap , DYNAMIC_TYPE_OPENSSL ) ; if ( tmp == NULL ) { WOLFSSL_MSG ( " " ) ; return WOLFSSL_BIO_ERROR ; } XMEMCPY ( tmp , ( void * ) ( pt + sz ) , memSz - sz ) ; XFREE ( bio -> ptr , bio -> heap , DYNAMIC_TYPE_OPENSSL ) ; bio -> ptr = tmp ; bio -> num = memSz - sz ; if ( bio -> mem_buf != NULL ) { bio -> mem_buf -> data = ( char * ) bio -> ptr ; bio -> mem_buf -> length = bio -> num ; } } bio -> wrSz -= sz ; } else { WOLFSSL_MSG ( " " ) ; return 0 ; } } else { return WOLFSSL_BIO_ERROR ; } return sz ; }
Handles reading from a memory type BIO and advancing the state.
Handles reading from a memory type BIO and advancing the state .
/* reset internal bio->mem */