mirror of
https://github.com/binary-kitchen/doorlockd
synced 2024-12-22 18:34:25 +01:00
9c549d1d27
Make token size dynamically adjustable. Shorter tokens are absolutely sufficient and simplify the manual copying of tokens Signed-off-by: Ralf Ramsauer <ralf@ramses-pyramidenbau.de>
29 lines
591 B
C++
29 lines
591 B
C++
#ifndef UTIL_H
|
|
#define UTIL_H
|
|
|
|
#include <algorithm>
|
|
#include <exception>
|
|
#include <json/json.h>
|
|
|
|
template <typename T>
|
|
T getJson(const Json::Value &root, const std::string &key);
|
|
|
|
template <typename T>
|
|
static T getJsonOrFail(const Json::Value &root, const std::string &key)
|
|
{
|
|
if (root.isObject() == false)
|
|
{
|
|
throw std::runtime_error("Invalid Json Object");
|
|
}
|
|
|
|
if (root.isMember(key) == false) {
|
|
throw std::runtime_error("Json key \"" + key + "\" not existing");
|
|
}
|
|
|
|
return getJson<T>(root, key);
|
|
}
|
|
|
|
std::string randHexString(unsigned int len);
|
|
|
|
#endif
|