Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 8 additions & 10 deletions src/AsyncWebServerRequest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,6 @@ void AsyncWebServerRequest::send(FS &fs, const String &path, const char *content
* @return true if the ETag was successfully generated, false otherwise (e.g., file too short or seek failed).
*/
bool AsyncWebServerRequest::_getEtag(File gzFile, char *etag) {
static constexpr char hexChars[] = "0123456789ABCDEF";

if (!gzFile.seek(gzFile.size() - 8)) {
return false;
}
Expand All @@ -81,14 +79,14 @@ bool AsyncWebServerRequest::_getEtag(File gzFile, char *etag) {
gzFile.read(reinterpret_cast<uint8_t *>(&crc), sizeof(crc));

etag[0] = '"';
etag[1] = hexChars[(crc >> 4) & 0x0F];
etag[2] = hexChars[crc & 0x0F];
etag[3] = hexChars[(crc >> 12) & 0x0F];
etag[4] = hexChars[(crc >> 8) & 0x0F];
etag[5] = hexChars[(crc >> 20) & 0x0F];
etag[6] = hexChars[(crc >> 16) & 0x0F];
etag[7] = hexChars[(crc >> 28)];
etag[8] = hexChars[(crc >> 24) & 0x0F];
etag[1] = asyncsrv::T_hex_chars[(crc >> 4) & 0x0F];
etag[2] = asyncsrv::T_hex_chars[crc & 0x0F];
etag[3] = asyncsrv::T_hex_chars[(crc >> 12) & 0x0F];
etag[4] = asyncsrv::T_hex_chars[(crc >> 8) & 0x0F];
etag[5] = asyncsrv::T_hex_chars[(crc >> 20) & 0x0F];
etag[6] = asyncsrv::T_hex_chars[(crc >> 16) & 0x0F];
etag[7] = asyncsrv::T_hex_chars[(crc >> 28)];
etag[8] = asyncsrv::T_hex_chars[(crc >> 24) & 0x0F];
etag[9] = '"';
etag[10] = '\0';

Expand Down
11 changes: 10 additions & 1 deletion src/WebAuthentication.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,16 @@

#include <cstring>

// platform classification for the MD5 backend used in this file:
// - HAS_MD5_BUILDER: the MD5Builder wrapper class exists (ESP32 arduino, RP2040, HOST)
// - everything else (ESP8266, LibreTiny): low-level md5_context_t C API from <md5.h>
#if defined(ESP32) || defined(TARGET_RP2040) || defined(TARGET_RP2350) || defined(PICO_RP2040) || defined(PICO_RP2350) || defined(HOST)
#define HAS_MD5_BUILDER 1
#else
#define HAS_MD5_BUILDER 0
#endif

#if HAS_MD5_BUILDER
#include <MD5Builder.h>
#else
#include <md5.h>
Expand Down Expand Up @@ -71,7 +80,7 @@ String generateBasicHash(const char *username, const char *password) {
}

static bool getMD5(uint8_t *data, uint16_t len, char *output) { // 33 bytes or more
#if defined(ESP32) || defined(TARGET_RP2040) || defined(TARGET_RP2350) || defined(PICO_RP2040) || defined(PICO_RP2350) || defined(HOST)
#if HAS_MD5_BUILDER
MD5Builder md5;
md5.begin();
md5.add(data, len);
Expand Down
9 changes: 4 additions & 5 deletions src/WebResponses.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -476,11 +476,10 @@ size_t AsyncAbstractResponse::write_send_buffs(AsyncWebServerRequest *request, s
_fillBufferAndProcessTemplates(_send_buffer->data() + 6, std::min(_send_buffer->size(), tcp_win) - 8); // reserve 8 bytes for chunk size data
if (readLen != RESPONSE_TRY_AGAIN) {
// Write 4 hex digits directly without null terminator
static constexpr char hexChars[] = "0123456789abcdef";
_send_buffer->data()[0] = hexChars[(readLen >> 12) & 0xF];
_send_buffer->data()[1] = hexChars[(readLen >> 8) & 0xF];
_send_buffer->data()[2] = hexChars[(readLen >> 4) & 0xF];
_send_buffer->data()[3] = hexChars[readLen & 0xF];
_send_buffer->data()[0] = asyncsrv::T_hex_chars[(readLen >> 12) & 0xF];
_send_buffer->data()[1] = asyncsrv::T_hex_chars[(readLen >> 8) & 0xF];
_send_buffer->data()[2] = asyncsrv::T_hex_chars[(readLen >> 4) & 0xF];
_send_buffer->data()[3] = asyncsrv::T_hex_chars[readLen & 0xF];
_send_buffer->data()[4] = '\r';
_send_buffer->data()[5] = '\n';
// data (readLen bytes) is already there
Expand Down
1 change: 1 addition & 0 deletions src/literals.h
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@ static constexpr const char T_TRUE[] = "true";
static constexpr const char T_UPGRADE[] = "Upgrade";
static constexpr const char T_uri[] = "uri";
static constexpr const char T_username[] = "username";
static constexpr const char T_hex_chars[] = "0123456789abcdef";
static constexpr const char T_WS[] = "websocket";
static constexpr const char T_WWW_AUTH[] = "WWW-Authenticate";
static constexpr const char T_X_Expected_Entity_Length[] = "X-Expected-Entity-Length";
Expand Down
Loading