20 #ifndef CS_CRYPTO_SYM_SECRET_KEY_H
21 #define CS_CRYPTO_SYM_SECRET_KEY_H
23 #include <util/conversions/byte.h>
24 #include <util/tools/crypto_traits.h>
31 #include <type_traits>
33 namespace cs_crypto::cipher {
35 template <std::size_t SIZE>
40 constexpr explicit secret_key(
const T (&key)[SIZE])
42 if constexpr (cs_crypto::traits::is_uniquely_represented_byte_v<T>) {
43 std::copy_n(util::to_byte_ptr(key), SIZE, m_key_data.begin());
45 static_assert(cs_crypto::traits::always_false<T>{},
"Unable to construct secret key from array of type T");
49 ~secret_key() =
default;
51 constexpr secret_key(
const secret_key &other) =
delete;
52 constexpr secret_key &operator=(
const secret_key &other) & =
delete;
54 constexpr secret_key(secret_key &&other) =
default;
55 constexpr secret_key &operator=(secret_key &&other) & =
default;
58 constexpr static std::optional<secret_key> from_string(
const std::string &key_data)
60 if (key_data.size() < SIZE) {
64 secret_key retval = {};
65 std::copy_n(util::to_byte_ptr(key_data.data()), SIZE, retval.m_key_data.data());
67 return std::optional<secret_key>(std::move(retval));
70 constexpr std::size_t size()
const
75 constexpr auto data()
const &
77 return m_key_data.data();
81 std::array<std::byte, SIZE> m_key_data = {};
83 constexpr secret_key()