From 9aae6f5ec2350eb41aee90863a2cef3ddbef88a2 Mon Sep 17 00:00:00 2001 From: Stefan Oberhumer Date: Fri, 19 Jan 2024 16:21:50 +0100 Subject: [PATCH] change(MD5Builder): Const-correctness. (#9104) * 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> --- cores/esp32/HashBuilder.h | 12 ++---------- cores/esp32/MD5Builder.cpp | 2 +- cores/esp32/MD5Builder.h | 2 +- cores/esp32/SHA1Builder.cpp | 2 +- cores/esp32/SHA1Builder.h | 2 +- 5 files changed, 6 insertions(+), 14 deletions(-) diff --git a/cores/esp32/HashBuilder.h b/cores/esp32/HashBuilder.h index ce6f1f1af42..86013bd65a2 100644 --- a/cores/esp32/HashBuilder.h +++ b/cores/esp32/HashBuilder.h @@ -26,14 +26,10 @@ 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) { @@ -41,10 +37,6 @@ class HashBuilder : public HEXBuilder } 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()); diff --git a/cores/esp32/MD5Builder.cpp b/cores/esp32/MD5Builder.cpp index 2198d06a27e..f27b2dc7846 100644 --- a/cores/esp32/MD5Builder.cpp +++ b/cores/esp32/MD5Builder.cpp @@ -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); } diff --git a/cores/esp32/MD5Builder.h b/cores/esp32/MD5Builder.h index 25dd8c49ec9..70f23cebb05 100644 --- a/cores/esp32/MD5Builder.h +++ b/cores/esp32/MD5Builder.h @@ -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; diff --git a/cores/esp32/SHA1Builder.cpp b/cores/esp32/SHA1Builder.cpp index 34f93271321..0f67d1086fd 100644 --- a/cores/esp32/SHA1Builder.cpp +++ b/cores/esp32/SHA1Builder.cpp @@ -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; diff --git a/cores/esp32/SHA1Builder.h b/cores/esp32/SHA1Builder.h index 4a0dfe0c100..2ab876f6411 100644 --- a/cores/esp32/SHA1Builder.h +++ b/cores/esp32/SHA1Builder.h @@ -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;