* Remove unused options from rublon default config * Remove safe|secure options * Allow 9 digits long passcode for passcode bypass * Change name of 'Mobile Passcode' to 'Passcode' * Do not display any prompt when user is waiting * remove unused alloca.h header * Add autopushPrompt option * Change name OTP method * Change enrolement message handling * ad static string ctor * Addded postrm script * Rename 01_rublon_ssh.conf to 01-rublon-ssh.conf * restart sshd service after rublon package instalation * Fix sshd not restarting bug on ubuntu 24.04 * disable logging from websocket-io * change package name to match old package name * Fix compilation issue when using non owning ptr * Set version to 2.0.0
73 lines
1.8 KiB
C++
73 lines
1.8 KiB
C++
#pragma once
|
|
|
|
#include <array>
|
|
#include <cstddef>
|
|
#include <cstring>
|
|
#include <utility>
|
|
|
|
template <typename T, std::size_t N, std::size_t... Idx>
|
|
constexpr std::array<T, N> toStdArray(T (&arr)[N], std::index_sequence<Idx...>)
|
|
{
|
|
return {arr[Idx]...};
|
|
}
|
|
|
|
template <std::size_t NewSize, typename T, std::size_t OldSize, std::size_t... Indexes>
|
|
constexpr std::array<T, NewSize> resize(const std::array<T, OldSize>& arr, std::index_sequence<Indexes...>)
|
|
{
|
|
return {arr[Indexes]...};
|
|
}
|
|
|
|
template <std::size_t NewSize, typename T, std::size_t OldSize>
|
|
constexpr std::array<T, NewSize> resize(const std::array<T, OldSize>& arr)
|
|
{
|
|
constexpr std::size_t minSize = std::min(OldSize, NewSize);
|
|
return resize(arr, std::make_index_sequence<minSize>());
|
|
}
|
|
|
|
// statically allocates a string buffer of (N+1) chars
|
|
template < size_t N >
|
|
class StaticString {
|
|
public:
|
|
constexpr StaticString() = default;
|
|
constexpr StaticString(const char (&chars)[N])
|
|
: m_str(toStdArray(chars))
|
|
{
|
|
}
|
|
|
|
constexpr StaticString(std::array<const char, N> chars)
|
|
: m_str(std::move(chars))
|
|
{
|
|
}
|
|
constexpr StaticString(const char * str) {
|
|
std::strncpy(m_str.data(), str, N);
|
|
}
|
|
|
|
void operator=(const char * str) {
|
|
std::strncpy(m_str.data(), str, N);
|
|
}
|
|
|
|
const char * c_str() const noexcept {
|
|
return m_str.data();
|
|
}
|
|
|
|
const char * data() const noexcept {
|
|
return m_str.data();
|
|
}
|
|
|
|
std::size_t size() const {
|
|
return strlen(m_str.data());
|
|
}
|
|
|
|
template <std::size_t M>
|
|
constexpr StaticString<N + M - 1> operator+(const StaticString<M> &rhs) const
|
|
{
|
|
return join(resize<N-1>(m_str), rhs.m_str);
|
|
}
|
|
|
|
template <std::size_t M>
|
|
friend class StaticString;
|
|
private:
|
|
std::array< char, N + 1 > m_str{};
|
|
};
|
|
|