Skip to content

Commit

Permalink
Fix Raspberry Pi Pico compilation error
Browse files Browse the repository at this point in the history
  • Loading branch information
mobizt committed Oct 29, 2024
1 parent 8278335 commit 57820f2
Show file tree
Hide file tree
Showing 9 changed files with 253 additions and 145 deletions.
2 changes: 1 addition & 1 deletion library.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "ESP Mail Client",
"version": "3.4.21",
"version": "3.4.22",
"keywords": "communication, email, imap, smtp, esp32, esp8266, samd, arduino",
"description": "Arduino E-Mail Client Library to send, read and get incoming email notification for ESP32, ESP8266 and SAMD21 devices. The library also supported other Arduino Devices using Clients interfaces e.g. WiFiClient, EthernetClient, and GSMClient.",
"repository": {
Expand Down
2 changes: 1 addition & 1 deletion library.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name=ESP Mail Client

version=3.4.21
version=3.4.22

author=Mobizt

Expand Down
4 changes: 2 additions & 2 deletions src/ESP_Mail_Client_Version.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@

#ifndef ESP_MAIL_VERSION

#define ESP_MAIL_VERSION "3.4.21"
#define ESP_MAIL_VERSION_NUM 30421
#define ESP_MAIL_VERSION "3.4.22"
#define ESP_MAIL_VERSION_NUM 30422

/* The inconsistent file version checking to prevent mixed versions compilation. */
//#define VALID_VERSION_CHECK(ver) (ver == ESP_MAIL_VERSION_NUM)
Expand Down
96 changes: 49 additions & 47 deletions src/client/SSLClient/client/BSSL_Helper.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
/*
Updated June 12, 2004.
WiFiClientBearSSL- SSL client/server for esp8266 using BearSSL libraries
- Mostly compatible with Arduino WiFi shield library and standard
WiFiClient/ServerSecure (except for certificate handling).
Expand Down Expand Up @@ -121,7 +123,7 @@ namespace key_bssl
vec->reserve(vec->size() + len); // Allocate extra space all at once
for (size_t i = 0; i < len; i++)
{
vec->push_back(((uint8_t *)buff)[i]);
vec->push_back((reinterpret_cast<const uint8_t *>(buff))[i]);
}
}

Expand All @@ -134,7 +136,7 @@ namespace key_bssl
// Clear everything in the Trust Anchor
memset(ta, 0, sizeof(*ta));

br_x509_decoder_init(dc.get(), byte_vector_append, (void *)&vdn);
br_x509_decoder_init(dc.get(), byte_vector_append, reinterpret_cast<void *>(&vdn));
br_x509_decoder_push(dc.get(), xc->data, xc->data_len);
pk = br_x509_decoder_get_pkey(dc.get());
if (pk == nullptr)
Expand All @@ -143,7 +145,7 @@ namespace key_bssl
}

// Copy the raw certificate data
ta->dn.data = (uint8_t *)malloc(vdn.size());
ta->dn.data = reinterpret_cast<uint8_t *>(malloc(vdn.size()));
if (!ta->dn.data)
{
return false; // OOM, but nothing yet allocated
Expand All @@ -161,8 +163,8 @@ namespace key_bssl
{
case BR_KEYTYPE_RSA:
ta->pkey.key_type = BR_KEYTYPE_RSA;
ta->pkey.key.rsa.n = (uint8_t *)malloc(pk->key.rsa.nlen);
ta->pkey.key.rsa.e = (uint8_t *)malloc(pk->key.rsa.elen);
ta->pkey.key.rsa.n = reinterpret_cast<uint8_t *>(malloc(pk->key.rsa.nlen));
ta->pkey.key.rsa.e = reinterpret_cast<uint8_t *>(malloc(pk->key.rsa.elen));
if ((ta->pkey.key.rsa.n == nullptr) || (ta->pkey.key.rsa.e == nullptr))
{
free_ta_contents(ta); // OOM, so clean up
Expand All @@ -176,7 +178,7 @@ namespace key_bssl
case BR_KEYTYPE_EC:
ta->pkey.key_type = BR_KEYTYPE_EC;
ta->pkey.key.ec.curve = pk->key.ec.curve;
ta->pkey.key.ec.q = (uint8_t *)malloc(pk->key.ec.qlen);
ta->pkey.key.ec.q = reinterpret_cast<uint8_t *>(malloc(pk->key.ec.qlen));
if (ta->pkey.key.ec.q == nullptr)
{
free_ta_contents(ta); // OOM, so clean up
Expand All @@ -196,7 +198,7 @@ namespace key_bssl

br_x509_trust_anchor *certificate_to_trust_anchor(const br_x509_certificate *xc)
{
br_x509_trust_anchor *ta = (br_x509_trust_anchor *)malloc(sizeof(br_x509_trust_anchor));
br_x509_trust_anchor *ta = reinterpret_cast<br_x509_trust_anchor *>(malloc(sizeof(br_x509_trust_anchor)));
if (!ta)
{
return nullptr;
Expand Down Expand Up @@ -287,7 +289,7 @@ namespace key_bssl
char *strdupImpl(const char *s)
{
size_t slen = strlen(s);
char *result = (char *)malloc(slen + 1);
char *result = reinterpret_cast<char *>(malloc(slen + 1));
if (!result)
return NULL;
memcpy(result, s, slen + 1);
Expand All @@ -305,13 +307,13 @@ namespace key_bssl
{
return nullptr;
}
pem_object po, *pos;
const unsigned char *buff;
pem_object po, *pos = nullptr;
const unsigned char *buff = nullptr;
std::vector<uint8_t> bv;

*num = 0;
br_pem_decoder_init(pc.get());
buff = (const unsigned char *)src;
buff = reinterpret_cast<const unsigned char *>(src);
po.name = nullptr;
po.data = nullptr;
po.data_len = 0;
Expand All @@ -337,7 +339,7 @@ namespace key_bssl
if (inobj)
{
// Stick data into the vector
po.data = (uint8_t *)malloc(bv.size());
po.data = reinterpret_cast<uint8_t *>(malloc(bv.size()));
if (po.data)
{
memcpy(po.data, &bv[0], bv.size());
Expand Down Expand Up @@ -369,7 +371,7 @@ namespace key_bssl
if (len == 0 && extra_nl)
{
extra_nl = false;
buff = (const unsigned char *)"\n";
buff = reinterpret_cast<const unsigned char *>("\n");
len = 1;
}
}
Expand All @@ -384,7 +386,7 @@ namespace key_bssl
return nullptr;
}

pos = (pem_object *)malloc((1 + pem_list.size()) * sizeof(*pos));
pos = reinterpret_cast<pem_object *>(malloc((1 + pem_list.size()) * sizeof(*pos)));
if (pos)
{
*num = pem_list.size();
Expand All @@ -399,21 +401,21 @@ namespace key_bssl
br_x509_certificate *read_certificates(const char *buff, size_t len, size_t *num)
{
std::vector<br_x509_certificate> cert_list;
pem_object *pos;
size_t u, num_pos;
br_x509_certificate *xcs;
pem_object *pos = nullptr;
size_t u = 0, num_pos = 0;
br_x509_certificate *xcs = nullptr;
br_x509_certificate dummy;

*num = 0;

if (looks_like_DER((const unsigned char *)buff, len))
if (looks_like_DER(reinterpret_cast<const unsigned char *>(buff), len))
{
xcs = (br_x509_certificate *)malloc(2 * sizeof(*xcs));
xcs = reinterpret_cast<br_x509_certificate *>(malloc(2 * sizeof(*xcs)));
if (!xcs)
{
return nullptr;
}
xcs[0].data = (uint8_t *)malloc(len);
xcs[0].data = reinterpret_cast<uint8_t *>(malloc(len));
if (!xcs[0].data)
{
free(xcs);
Expand Down Expand Up @@ -457,7 +459,7 @@ namespace key_bssl
dummy.data = nullptr;
dummy.data_len = 0;
cert_list.push_back(dummy);
xcs = (br_x509_certificate *)malloc(cert_list.size() * sizeof(*xcs));
xcs = reinterpret_cast<br_x509_certificate *>(malloc(cert_list.size() * sizeof(*xcs)));
if (!xcs)
{
for (size_t i = 0; i < cert_list.size(); i++)
Expand Down Expand Up @@ -508,14 +510,14 @@ namespace key_bssl
{
case BR_KEYTYPE_RSA:
rk = br_pkey_decoder_get_rsa(dc.get());
pk = (public_key *)malloc(sizeof *pk);
pk = reinterpret_cast<public_key *>(malloc(sizeof *pk));
if (!pk)
{
return nullptr;
}
pk->key_type = BR_KEYTYPE_RSA;
pk->key.rsa.n = (uint8_t *)malloc(rk->nlen);
pk->key.rsa.e = (uint8_t *)malloc(rk->elen);
pk->key.rsa.n = reinterpret_cast<uint8_t *>(malloc(rk->nlen));
pk->key.rsa.e = reinterpret_cast<uint8_t *>(malloc(rk->elen));
if (!pk->key.rsa.n || !pk->key.rsa.e)
{
free(pk->key.rsa.n);
Expand All @@ -531,13 +533,13 @@ namespace key_bssl

case BR_KEYTYPE_EC:
ek = br_pkey_decoder_get_ec(dc.get());
pk = (public_key *)malloc(sizeof *pk);
pk = reinterpret_cast<public_key *>(malloc(sizeof *pk));
if (!pk)
{
return nullptr;
}
pk->key_type = BR_KEYTYPE_EC;
pk->key.ec.q = (uint8_t *)malloc(ek->qlen);
pk->key.ec.q = reinterpret_cast<uint8_t *>(malloc(ek->qlen));
if (!pk->key.ec.q)
{
free(pk);
Expand Down Expand Up @@ -594,17 +596,17 @@ namespace key_bssl
{
case BR_KEYTYPE_RSA:
rk = br_skey_decoder_get_rsa(dc.get());
sk = (private_key *)malloc(sizeof *sk);
sk = reinterpret_cast<private_key *>(malloc(sizeof *sk));
if (!sk)
{
return nullptr;
}
sk->key_type = BR_KEYTYPE_RSA;
sk->key.rsa.p = (uint8_t *)malloc(rk->plen);
sk->key.rsa.q = (uint8_t *)malloc(rk->qlen);
sk->key.rsa.dp = (uint8_t *)malloc(rk->dplen);
sk->key.rsa.dq = (uint8_t *)malloc(rk->dqlen);
sk->key.rsa.iq = (uint8_t *)malloc(rk->iqlen);
sk->key.rsa.p = reinterpret_cast<uint8_t *>(malloc(rk->plen));
sk->key.rsa.q = reinterpret_cast<uint8_t *>(malloc(rk->qlen));
sk->key.rsa.dp = reinterpret_cast<uint8_t *>(malloc(rk->dplen));
sk->key.rsa.dq = reinterpret_cast<uint8_t *>(malloc(rk->dqlen));
sk->key.rsa.iq = reinterpret_cast<uint8_t *>(malloc(rk->iqlen));
if (!sk->key.rsa.p || !sk->key.rsa.q || !sk->key.rsa.dp || !sk->key.rsa.dq || !sk->key.rsa.iq)
{
free_private_key(sk);
Expand All @@ -625,14 +627,14 @@ namespace key_bssl

case BR_KEYTYPE_EC:
ek = br_skey_decoder_get_ec(dc.get());
sk = (private_key *)malloc(sizeof *sk);
sk = reinterpret_cast<private_key *>(malloc(sizeof *sk));
if (!sk)
{
return nullptr;
}
sk->key_type = BR_KEYTYPE_EC;
sk->key.ec.curve = ek->curve;
sk->key.ec.x = (uint8_t *)malloc(ek->xlen);
sk->key.ec.x = reinterpret_cast<uint8_t *>(malloc(ek->xlen));
if (!sk->key.ec.x)
{
free_private_key(sk);
Expand Down Expand Up @@ -688,9 +690,9 @@ namespace key_bssl
private_key *sk = nullptr;
pem_object *pos = nullptr;

if (looks_like_DER((const unsigned char *)buff, len))
if (looks_like_DER(reinterpret_cast<const unsigned char *>(buff), len))
{
sk = decode_private_key((const unsigned char *)buff, len);
sk = decode_private_key(reinterpret_cast<const unsigned char *>(buff), len);
return sk;
}

Expand Down Expand Up @@ -720,9 +722,9 @@ namespace key_bssl
public_key *pk = nullptr;
pem_object *pos = nullptr;

if (looks_like_DER((const unsigned char *)buff, len))
if (looks_like_DER(reinterpret_cast<const unsigned char *>(buff), len))
{
pk = decode_public_key((const unsigned char *)buff, len);
pk = decode_public_key(reinterpret_cast<const unsigned char *>(buff), len);
return pk;
}
size_t num;
Expand All @@ -749,7 +751,7 @@ namespace key_bssl

static uint8_t *loadStream(Stream &stream, size_t size)
{
uint8_t *dest = (uint8_t *)malloc(size);
uint8_t *dest = reinterpret_cast<uint8_t *>(malloc(size));
if (!dest)
{
return nullptr; // OOM error
Expand Down Expand Up @@ -806,7 +808,7 @@ namespace bssl

bool PublicKey::parse(const char *pemKey)
{
return parse((const uint8_t *)pemKey, strlen_P(pemKey));
return parse(reinterpret_cast<const uint8_t *>(pemKey), strlen_P(pemKey));
}

bool PublicKey::parse(const uint8_t *derKey, size_t derLen)
Expand All @@ -816,7 +818,7 @@ namespace bssl
key_bssl::free_public_key(_key);
_key = nullptr;
}
_key = key_bssl::read_public_key((const char *)derKey, derLen);
_key = key_bssl::read_public_key(reinterpret_cast<const char *>(derKey), derLen);
return _key ? true : false;
}

Expand Down Expand Up @@ -896,7 +898,7 @@ namespace bssl

bool PrivateKey::parse(const char *pemKey)
{
return parse((const uint8_t *)pemKey, strlen_P(pemKey));
return parse(reinterpret_cast<const uint8_t *>(pemKey), strlen_P(pemKey));
}

bool PrivateKey::parse(const uint8_t *derKey, size_t derLen)
Expand All @@ -906,7 +908,7 @@ namespace bssl
key_bssl::free_private_key(_key);
_key = nullptr;
}
_key = key_bssl::read_private_key((const char *)derKey, derLen);
_key = key_bssl::read_private_key(reinterpret_cast<const char *>(derKey), derLen);
return _key ? true : false;
}

Expand Down Expand Up @@ -996,21 +998,21 @@ namespace bssl

bool X509List::append(const char *pemCert)
{
return append((const uint8_t *)pemCert, strlen_P(pemCert));
return append(reinterpret_cast<const uint8_t *>(pemCert), strlen_P(pemCert));
}

bool X509List::append(const uint8_t *derCert, size_t derLen)
{
size_t numCerts;
br_x509_certificate *newCerts = key_bssl::read_certificates((const char *)derCert, derLen, &numCerts);
br_x509_certificate *newCerts = key_bssl::read_certificates(reinterpret_cast<const char *>(derCert), derLen, &numCerts);
if (!newCerts)
{
return false;
}

// Add in the certificates
br_x509_certificate *saveCert = _cert;
_cert = (br_x509_certificate *)realloc(_cert, (numCerts + _count) * sizeof(br_x509_certificate));
_cert = reinterpret_cast<br_x509_certificate *>(realloc(_cert, (numCerts + _count) * sizeof(br_x509_certificate)));
if (!_cert)
{
free(newCerts);
Expand All @@ -1022,7 +1024,7 @@ namespace bssl

// Build TAs for each certificate
br_x509_trust_anchor *saveTa = _ta;
_ta = (br_x509_trust_anchor *)realloc(_ta, (numCerts + _count) * sizeof(br_x509_trust_anchor));
_ta = reinterpret_cast<br_x509_trust_anchor *>(realloc(_ta, (numCerts + _count) * sizeof(br_x509_trust_anchor)));
if (!_ta)
{
_ta = saveTa;
Expand Down
Loading

0 comments on commit 57820f2

Please sign in to comment.