FreeRTOS-Plus/ThirdParty/WolfSSL-FIPS-Ready/src/bio.c
/* similar to wolfSSL_BIO_nread0 but advances the read index */
similar to wolfSSL_BIO_nread0 but advances the read index
similar to wolfSSL_BIO_nread0 but advances the read index
int wolfSSL_BIO_nread(WOLFSSL_BIO *bio, char **buf, int num)
{
    int sz = WOLFSSL_BIO_UNSET;
    WOLFSSL_ENTER("wolfSSL_BIO_nread");
    if (bio == NULL || buf == NULL) {
        WOLFSSL_MSG("NULL argument passed in");
        return WOLFSSL_FAILURE;
    }
    if (bio->type == WOLFSSL_BIO_MEMORY) {
        return SSL_FAILURE;
    }
    if (bio->pair != NULL) {
        if (num == 0) {
            *buf = (char*)bio->pair->ptr + bio->pair->rdIdx;
            return 0;
        }
        sz = wolfSSL_BIO_nread0(bio, buf);
        if (sz == 0) {
            return WOLFSSL_BIO_ERROR;
        }
        if (num < sz) {
            sz = num;
        }
        bio->pair->rdIdx += sz;
        if (bio->pair->rdIdx == bio->pair->wrSz) {
            bio->pair->rdIdx = 0;
            if (bio->pair->wrIdx == bio->pair->wrSz) {
                bio->pair->wrIdx = 0;
            }
        }
        if (bio->pair->rdIdx == bio->pair->wrIdx) {
            bio->pair->rdIdx = 0;
            bio->pair->wrIdx = 0;
        }
    }
    return sz;
}
int wolfSSL_BIO_nread ( WOLFSSL_BIO * bio , char * * buf , int num ) { int sz = WOLFSSL_BIO_UNSET ; WOLFSSL_ENTER ( " " ) ; if ( bio == NULL || buf == NULL ) { WOLFSSL_MSG ( " " ) ; return WOLFSSL_FAILURE ; } if ( bio -> type == WOLFSSL_BIO_MEMORY ) { return SSL_FAILURE ; } if ( bio -> pair != NULL ) { if ( num == 0 ) { * buf = ( char * ) bio -> pair -> ptr + bio -> pair -> rdIdx ; return 0 ; } sz = wolfSSL_BIO_nread0 ( bio , buf ) ; if ( sz == 0 ) { return WOLFSSL_BIO_ERROR ; } if ( num < sz ) { sz = num ; } bio -> pair -> rdIdx += sz ; if ( bio -> pair -> rdIdx == bio -> pair -> wrSz ) { bio -> pair -> rdIdx = 0 ; if ( bio -> pair -> wrIdx == bio -> pair -> wrSz ) { bio -> pair -> wrIdx = 0 ; } } if ( bio -> pair -> rdIdx == bio -> pair -> wrIdx ) { bio -> pair -> rdIdx = 0 ; bio -> pair -> wrIdx = 0 ; } } return sz ; }
similar to wolfSSL_BIO_nread0 but advances the read index
similar to wolfSSL_BIO_nread0 but advances the read index
/* special case if asking to read 0 bytes */ /* get amount able to read and set buffer pointer */ /* check if have read to the end of the buffer and need to reset */ /* check if read up to write index, if so then reset index */