Add HMAC-MD5 component tests (#12459)

This commit is contained in:
David Woodhouse
2025-12-13 10:19:31 +09:00
committed by GitHub
parent 1a43a06dd4
commit ff7651875e
6 changed files with 42 additions and 0 deletions

View File

@@ -1,2 +1,6 @@
import esphome.config_validation as cv
AUTO_LOAD = ["md5"]
CODEOWNERS = ["@dwmw2"]
CONFIG_SCHEMA = cv.Schema({})

View File

@@ -0,0 +1,34 @@
esphome:
on_boot:
- lambda: |-
// Test HMAC-MD5 functionality
#ifdef USE_MD5
using esphome::hmac_md5::HmacMD5;
HmacMD5 hmac;
// Test with key "key" and message "The quick brown fox jumps over the lazy dog"
const char* key = "key";
const char* message = "The quick brown fox jumps over the lazy dog";
hmac.init(key, strlen(key));
hmac.add(message, strlen(message));
hmac.calculate();
char hex_output[33];
hmac.get_hex(hex_output);
hex_output[32] = '\0';
ESP_LOGD("HMAC_MD5", "HMAC-MD5('%s', '%s') = %s", key, message, hex_output);
// Expected: 80070713463e7749b90c2dc24911e275
const char* expected = "80070713463e7749b90c2dc24911e275";
if (strcmp(hex_output, expected) == 0) {
ESP_LOGI("HMAC_MD5", "Test PASSED");
} else {
ESP_LOGE("HMAC_MD5", "Test FAILED. Expected %s", expected);
}
#else
ESP_LOGW("HMAC_MD5", "HMAC-MD5 not available on this platform");
#endif
hmac_md5:

View File

@@ -0,0 +1 @@
<<: !include common.yaml

View File

@@ -0,0 +1 @@
<<: !include common.yaml

View File

@@ -0,0 +1 @@
<<: !include common.yaml

View File

@@ -0,0 +1 @@
<<: !include common.yaml