mirror of
https://github.com/esphome/esphome.git
synced 2026-05-31 17:06:40 +08:00
Add HMAC-MD5 component tests (#12459)
This commit is contained in:
@@ -1,2 +1,6 @@
|
|||||||
|
import esphome.config_validation as cv
|
||||||
|
|
||||||
AUTO_LOAD = ["md5"]
|
AUTO_LOAD = ["md5"]
|
||||||
CODEOWNERS = ["@dwmw2"]
|
CODEOWNERS = ["@dwmw2"]
|
||||||
|
|
||||||
|
CONFIG_SCHEMA = cv.Schema({})
|
||||||
|
|||||||
@@ -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:
|
||||||
@@ -0,0 +1 @@
|
|||||||
|
<<: !include common.yaml
|
||||||
@@ -0,0 +1 @@
|
|||||||
|
<<: !include common.yaml
|
||||||
@@ -0,0 +1 @@
|
|||||||
|
<<: !include common.yaml
|
||||||
@@ -0,0 +1 @@
|
|||||||
|
<<: !include common.yaml
|
||||||
Reference in New Issue
Block a user