Skip to content

Commit

Permalink
change(MD5Builder): Const-correctness. (#9104)
Browse files Browse the repository at this point in the history
* change(HashBuilder): Const-correctness

Propagate 'const' of buffer variable from underlying functions.

* Remove char* methods

---------

Co-authored-by: Lucas Saavedra Vaz <32426024+lucasssvaz@users.noreply.github.com>
  • Loading branch information
StefanOberhumer and lucasssvaz authored Jan 19, 2024
1 parent 2e5c932 commit 9aae6f5
Show file tree
Hide file tree
Showing 5 changed files with 6 additions and 14 deletions.
12 changes: 2 additions & 10 deletions cores/esp32/HashBuilder.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,25 +26,17 @@ class HashBuilder : public HEXBuilder
virtual ~HashBuilder() {}
virtual void begin() = 0;

virtual void add(uint8_t* data, size_t len) = 0;
virtual void add(const uint8_t* data, size_t len) = 0;
virtual void add(const char* data)
{
add((uint8_t*)data, strlen(data));
}
virtual void add(char* data)
{
add((const char*)data);
add((const uint8_t*)data, strlen(data));
}
virtual void add(String data)
{
add(data.c_str());
}

virtual void addHexString(const char* data) = 0;
virtual void addHexString(char* data)
{
addHexString((const char*)data);
}
virtual void addHexString(String data)
{
addHexString(data.c_str());
Expand Down
2 changes: 1 addition & 1 deletion cores/esp32/MD5Builder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ void MD5Builder::begin(void)
esp_rom_md5_init(&_ctx);
}

void MD5Builder::add(uint8_t * data, size_t len)
void MD5Builder::add(const uint8_t * data, size_t len)
{
esp_rom_md5_update(&_ctx, data, len);
}
Expand Down
2 changes: 1 addition & 1 deletion cores/esp32/MD5Builder.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ class MD5Builder : public HashBuilder
void begin(void) override;

using HashBuilder::add;
void add(uint8_t * data, size_t len) override;
void add(const uint8_t * data, size_t len) override;

using HashBuilder::addHexString;
void addHexString(const char * data) override;
Expand Down
2 changes: 1 addition & 1 deletion cores/esp32/SHA1Builder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,7 @@ void SHA1Builder::begin(void)
memset(hash, 0x00, sizeof(hash));
}

void SHA1Builder::add(uint8_t* data, size_t len)
void SHA1Builder::add(const uint8_t* data, size_t len)
{
size_t fill;
uint32_t left;
Expand Down
2 changes: 1 addition & 1 deletion cores/esp32/SHA1Builder.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ class SHA1Builder : public HashBuilder
void begin() override;

using HashBuilder::add;
void add(uint8_t* data, size_t len) override;
void add(const uint8_t* data, size_t len) override;

using HashBuilder::addHexString;
void addHexString(const char* data) override;
Expand Down

0 comments on commit 9aae6f5

Please sign in to comment.