AlteriomPainlessMesh v2.1.1
Easy ESP32/ESP8266 mesh networking with Alteriom IoT extensions
Loading...
Searching...
No Matches
validation.hpp
Go to the documentation of this file.
1#ifndef _PAINLESS_MESH_VALIDATION_HPP_
2#define _PAINLESS_MESH_VALIDATION_HPP_
3
11#ifndef ARDUINO
12#include <chrono>
13#endif
15
16namespace painlessmesh {
17namespace validation {
18
32
37 size_t max_message_size = 8192; // Maximum message size in bytes
38 size_t max_string_length = 1024; // Maximum string field length
39 uint32_t min_node_id = 1; // Minimum valid node ID
40 uint32_t max_node_id = 0xFFFFFFFF; // Maximum valid node ID
41 size_t max_nesting_depth = 10; // Maximum JSON nesting depth
42 bool strict_type_checking = true; // Enable strict type validation
43};
44
49 public:
54 static uint32_t generate() {
55#ifdef ESP32
56 return esp_random();
57#elif defined(ESP8266)
58 return RANDOM_REG32;
59#else
60 // Fallback for other platforms - use system rand with better seeding
61 static bool seeded = false;
62 if (!seeded) {
63#ifdef ARDUINO
64 // Arduino-compatible seeding
65 srand(millis() ^ analogRead(A0));
66#else
67 // Non-Arduino platforms with std::chrono
68 auto now = std::chrono::steady_clock::now();
69 auto duration = now.time_since_epoch();
70 uint32_t seed =
71 std::chrono::duration_cast<std::chrono::microseconds>(duration)
72 .count();
73 srand(seed);
74#endif
75 seeded = true;
76 }
77 return ((uint32_t)rand() << 16) | rand();
78#endif
79 }
80
84 static void generate_bytes(uint8_t* buffer, size_t length) {
85 for (size_t i = 0; i < length; i += sizeof(uint32_t)) {
86 uint32_t random_val = generate();
87 size_t copy_len = std::min(sizeof(uint32_t), length - i);
88 memcpy(buffer + i, &random_val, copy_len);
89 }
90 }
91};
92
93} // namespace validation
94} // namespace painlessmesh
95
96#endif // _PAINLESS_MESH_VALIDATION_HPP_
Definition validation.hpp:48
static void generate_bytes(uint8_t *buffer, size_t length)
Definition validation.hpp:84
static uint32_t generate()
Definition validation.hpp:54
ValidationResult
Definition validation.hpp:22
Definition wifi.hpp:34
Definition validation.hpp:36
size_t max_nesting_depth
Definition validation.hpp:41
size_t max_message_size
Definition validation.hpp:37
size_t max_string_length
Definition validation.hpp:38
uint32_t min_node_id
Definition validation.hpp:39
uint32_t max_node_id
Definition validation.hpp:40
bool strict_type_checking
Definition validation.hpp:42