SPSP
Simple publish-subscribe protocol. Connects low power IoT clients to MQTT.
All Classes Files Functions Variables Typedefs Enumerations
linux/spsp/random.hpp
Go to the documentation of this file.
1 
10 #pragma once
11 
12 #include <cstdlib>
13 #include <sys/random.h>
14 
15 #include "spsp/random_if.hpp"
16 
17 namespace SPSP
18 {
24  class Random : public IRandom
25  {
26  public:
34  inline void bytes(void* buf, size_t len) const
35  {
36  if (getrandom(buf, len, 0) != len) {
37  throw RandomGeneratorError("Generation failed");
38  }
39  }
40  };
41 } // namespace SPSP
random_if.hpp
Platform-dependent random generator interface.
SPSP::Random::bytes
void bytes(void *buf, size_t len) const
Generates len truly random bytes in buf
Definition: linux/spsp/random.hpp:34
SPSP::RandomGeneratorError
Random generator error.
Definition: random_if.hpp:22