#include "whitening.h" #include "esphome/core/log.h" #include "esphome/core/helpers.h" namespace { constexpr auto TAG = "brmesh.whitening"; } // namespace esphome { namespace brmesh { Whitening::State Whitening::use(bool encode, const LUT &lut, State state, std::span bytes) { const bool log = (bytes.size() > 1 || bytes[0] != 0x00); if (log) ESP_LOGV(TAG, "%s: input: %s", encode ? "encode" : "decode", format_hex_pretty(&bytes[0], bytes.size()).c_str()); else ESP_LOGVV(TAG, "%s: input: %s", encode ? "encode" : "decode", format_hex_pretty(&bytes[0], bytes.size()).c_str()); for (auto &byte:bytes) { auto &next = lut[state]; byte = next.lut[byte]; state = next.state; } if (log) ESP_LOGV(TAG, "%s: output: %s", encode ? "encode" : "decode", format_hex_pretty(&bytes[0], bytes.size()).c_str()); else ESP_LOGVV(TAG, "%s: output: %s", encode ? "encode" : "decode", format_hex_pretty(&bytes[0], bytes.size()).c_str()); return state; } } // brmesh } // esphome