Skip to content

Commit

Permalink
Address code review
Browse files Browse the repository at this point in the history
  • Loading branch information
julek-wolfssl committed Aug 20, 2024
1 parent b693127 commit 3260a9b
Show file tree
Hide file tree
Showing 6 changed files with 55 additions and 42 deletions.
2 changes: 1 addition & 1 deletion src/ocsp.c
Original file line number Diff line number Diff line change
Expand Up @@ -1587,7 +1587,7 @@ int wolfSSL_OCSP_REQ_CTX_set1_req(WOLFSSL_OCSP_REQ_CTX *ctx, OcspRequest *req)

static int OCSP_REQ_CTX_bio_cb(char *buf, int sz, void *ctx)
{
return BioReceive((WOLFSSL_BIO*)ctx, NULL, buf, sz);
return BioReceiveInternal((WOLFSSL_BIO*)ctx, NULL, buf, sz);
}

int wolfSSL_OCSP_REQ_CTX_nbio(WOLFSSL_OCSP_REQ_CTX *ctx)
Expand Down
15 changes: 13 additions & 2 deletions src/wolfio.c
Original file line number Diff line number Diff line change
Expand Up @@ -260,7 +260,18 @@ static int TranslateIoReturnCode(int err, SOCKET_T sd, int direction)
#ifdef OPENSSL_EXTRA
#ifndef NO_BIO

int BioReceive(WOLFSSL_BIO* biord, WOLFSSL_BIO* biowr, char* buf, int sz)
int BioSend(WOLFSSL* ssl, char *buf, int sz, void *ctx)
{
return SslBioSend(ssl, buf, sz, ctx);
}

int BioReceive(WOLFSSL* ssl, char* buf, int sz, void* ctx)
{
return SslBioReceive(ssl, buf, sz, ctx);
}

int BioReceiveInternal(WOLFSSL_BIO* biord, WOLFSSL_BIO* biowr, char* buf,
int sz)
{
int recvd = WOLFSSL_CBIO_ERR_GENERAL;

Expand Down Expand Up @@ -325,7 +336,7 @@ int SslBioReceive(WOLFSSL* ssl, char* buf, int sz, void* ctx)
{
WOLFSSL_ENTER("SslBioReceive");
(void)ctx;
return BioReceive(ssl->biord, ssl->biowr, buf, sz);
return BioReceiveInternal(ssl->biord, ssl->biowr, buf, sz);
}


Expand Down
2 changes: 1 addition & 1 deletion wolfcrypt/src/asn.c
Original file line number Diff line number Diff line change
Expand Up @@ -13543,7 +13543,7 @@ static int AddDNSEntryToList(DNS_entry** lst, DNS_entry* entry)

/* Allocate a DNS entry and set the fields.
*
* @param [in] cert Certificate object.
* @param [in] heap Heap hint.
* @param [in] str DNS name string.
* @param [in] strLen Length of DNS name string.
* @param [in] type Type of DNS name string.
Expand Down
64 changes: 32 additions & 32 deletions wolfssl/openssl/asn1.h
Original file line number Diff line number Diff line change
Expand Up @@ -125,17 +125,17 @@ WOLFSSL_API WOLFSSL_ASN1_OBJECT *wolfSSL_c2i_ASN1_OBJECT(WOLFSSL_ASN1_OBJECT **a
* we don't use this. Some projects use OpenSSL to implement ASN1 types and
* this section is only to provide those projects with ASN1 functionality. */

typedef void* (*wolfssl_asn1_new)(void);
typedef void (*wolfssl_asn1_free)(void*);
typedef int (*wolfssl_asn1_i2d)(const void*, unsigned char**);
typedef void* (*wolfssl_asn1_d2i)(void**, const byte **, long);
typedef void* (*WolfsslAsn1NewCb)(void);
typedef void (*WolfsslAsn1FreeCb)(void*);
typedef int (*WolfsslAsn1i2dCb)(const void*, unsigned char**);
typedef void* (*WolfsslAsn1d2iCb)(void**, const byte **, long);

struct WOLFSSL_ASN1_TEMPLATE {
/* Type functions */
wolfssl_asn1_new new_func;
wolfssl_asn1_free free_func;
wolfssl_asn1_i2d i2d_func;
wolfssl_asn1_d2i d2i_func;
WolfsslAsn1NewCb new_func;
WolfsslAsn1FreeCb free_func;
WolfsslAsn1i2dCb i2d_func;
WolfsslAsn1d2iCb d2i_func;
/* Member info */
size_t offset; /* Offset of this field in structure */
/* DER info */
Expand Down Expand Up @@ -232,45 +232,45 @@ static WC_MAYBE_UNUSED const byte ASN1_BIT_STRING_FIRST_BYTE = ASN_BIT_STRING;
* incorrectly expand the type. Ex: ASN1_INTEGER -> WOLFSSL_ASN1_INTEGER */

#define ASN1_SIMPLE(type, member, member_type) \
{ (wolfssl_asn1_new)member_type##_new, \
(wolfssl_asn1_free)member_type##_free, \
(wolfssl_asn1_i2d)i2d_##member_type, \
(wolfssl_asn1_d2i)d2i_##member_type, \
{ (WolfsslAsn1NewCb)member_type##_new, \
(WolfsslAsn1FreeCb)member_type##_free, \
(WolfsslAsn1i2dCb)i2d_##member_type, \
(WolfsslAsn1d2iCb)d2i_##member_type, \
ASN1_TYPE(type, member, -1, 0, 0, 0) }

#define ASN1_IMP(type, member, member_type, tag) \
{ (wolfssl_asn1_new)member_type##_new, \
(wolfssl_asn1_free)member_type##_free, \
(wolfssl_asn1_i2d)i2d_##member_type, \
(wolfssl_asn1_d2i)d2i_##member_type, \
{ (WolfsslAsn1NewCb)member_type##_new, \
(WolfsslAsn1FreeCb)member_type##_free, \
(WolfsslAsn1i2dCb)i2d_##member_type, \
(WolfsslAsn1d2iCb)d2i_##member_type, \
ASN1_TYPE(type, member, tag, member_type##_FIRST_BYTE, 0, 0) }

#define ASN1_EXP(type, member, member_type, tag) \
{ (wolfssl_asn1_new)member_type##_new, \
(wolfssl_asn1_free)member_type##_free, \
(wolfssl_asn1_i2d)i2d_##member_type, \
(wolfssl_asn1_d2i)d2i_##member_type, \
{ (WolfsslAsn1NewCb)member_type##_new, \
(WolfsslAsn1FreeCb)member_type##_free, \
(WolfsslAsn1i2dCb)i2d_##member_type, \
(WolfsslAsn1d2iCb)d2i_##member_type, \
ASN1_TYPE(type, member, tag, 0, 1, 0) }

#define ASN1_SEQUENCE_OF(type, member, member_type) \
{ (wolfssl_asn1_new)member_type##_new, \
(wolfssl_asn1_free)member_type##_free, \
(wolfssl_asn1_i2d)i2d_##member_type, \
(wolfssl_asn1_d2i)d2i_##member_type, \
{ (WolfsslAsn1NewCb)member_type##_new, \
(WolfsslAsn1FreeCb)member_type##_free, \
(WolfsslAsn1i2dCb)i2d_##member_type, \
(WolfsslAsn1d2iCb)d2i_##member_type, \
ASN1_TYPE(type, member, -1, 0, 0, 1) }

#define ASN1_EXP_SEQUENCE_OF(type, member, member_type, tag) \
{ (wolfssl_asn1_new)member_type##_new, \
(wolfssl_asn1_free)member_type##_free, \
(wolfssl_asn1_i2d)i2d_##member_type, \
(wolfssl_asn1_d2i)d2i_##member_type, \
{ (WolfsslAsn1NewCb)member_type##_new, \
(WolfsslAsn1FreeCb)member_type##_free, \
(WolfsslAsn1i2dCb)i2d_##member_type, \
(WolfsslAsn1d2iCb)d2i_##member_type, \
ASN1_TYPE(type, member, tag, 0, 1, 1) }

#define ASN1_EX_TEMPLATE_TYPE(flags, tag, name, member_type) \
{ (wolfssl_asn1_new)member_type##_new, \
(wolfssl_asn1_free)member_type##_free, \
(wolfssl_asn1_i2d)i2d_##member_type, \
(wolfssl_asn1_d2i)d2i_##member_type, \
{ (WolfsslAsn1NewCb)member_type##_new, \
(WolfsslAsn1FreeCb)member_type##_free, \
(WolfsslAsn1i2dCb)i2d_##member_type, \
(WolfsslAsn1d2iCb)d2i_##member_type, \
0, flags & ASN1_TFLG_TAG_MASK ? tag : -1, 0, \
!!(flags & ASN1_TFLG_EXPLICIT), TRUE }

Expand Down
1 change: 0 additions & 1 deletion wolfssl/wolfcrypt/types.h
Original file line number Diff line number Diff line change
Expand Up @@ -723,7 +723,6 @@ typedef struct w64wrapper {
#define XMEMMOVE(d,s,l) memmove((d),(s),(l))

#define XSTRLEN(s1) strlen((s1))
#define XSTRCPY(s1,s2) strcpy((s1),(s2))
#define XSTRNCPY(s1,s2,n) strncpy((s1),(s2),(n))
/* strstr, strncmp, strcmp, and strncat only used by wolfSSL proper,
* not required for wolfCrypt only */
Expand Down
13 changes: 8 additions & 5 deletions wolfssl/wolfio.h
Original file line number Diff line number Diff line change
Expand Up @@ -520,11 +520,14 @@ WOLFSSL_API int wolfIO_RecvFrom(SOCKET_T sd, WOLFSSL_BIO_ADDR *addr, char *buf,
#endif
#endif /* WOLFSSL_NO_SOCK */


WOLFSSL_API int SslBioSend(WOLFSSL* ssl, char *buf, int sz, void *ctx);
WOLFSSL_API int BioReceive(WOLFSSL_BIO* biord, WOLFSSL_BIO* biowr, char* buf,
int sz);
WOLFSSL_API int SslBioReceive(WOLFSSL* ssl, char* buf, int sz, void* ctx);
/* Preseve API previously exposed */
WOLFSSL_API int BioSend(WOLFSSL* ssl, char *buf, int sz, void *ctx);
WOLFSSL_API int BioReceive(WOLFSSL* ssl, char* buf, int sz, void* ctx);

WOLFSSL_LOCAL int SslBioSend(WOLFSSL* ssl, char *buf, int sz, void *ctx);
WOLFSSL_LOCAL int BioReceiveInternal(WOLFSSL_BIO* biord, WOLFSSL_BIO* biowr,
char* buf, int sz);
WOLFSSL_LOCAL int SslBioReceive(WOLFSSL* ssl, char* buf, int sz, void* ctx);
#if defined(USE_WOLFSSL_IO)
/* default IO callbacks */
WOLFSSL_API int EmbedReceive(WOLFSSL* ssl, char* buf, int sz, void* ctx);
Expand Down

0 comments on commit 3260a9b

Please sign in to comment.