8#include <Quotient/converters.h>
9#include <Quotient/expected.h>
11#include <QtCore/QMetaType>
12#include <QtCore/QStringBuilder>
38 MegolmV1AesSha2AlgoKey };
42 return std::ranges::find(SupportedAlgorithms, algorithm) != SupportedAlgorithms.cend();
45#define QOLM_INTERNAL_ERROR_X(Message_, LastError_)
46 qFatal("%s, internal error: %s", QUO_CSTR(Message_), LastError_)
48#define QOLM_INTERNAL_ERROR(Message_)
51#define QOLM_FAIL_OR_LOG_X(InternalCondition_, Message_, LastErrorText_)
53 if (InternalCondition_)
55 qWarning(E2EE).nospace() << (Message_) << ": " << (LastErrorText_);
58#define QOLM_FAIL_OR_LOG(InternalFailureValue_, Message_)
59 QOLM_FAIL_OR_LOG_X(lastErrorCode() == (InternalFailureValue_), (Message_), lastError())
96 QUOTIENT_API void checkForSpanShortfall(QByteArray::size_type inputSize,
int neededSize);
98 template <
typename SpanT>
99 inline auto spanFromBytes(
auto& byteArray)
102 Q_ASSERT_X(std::in_range<
int>(std::size(byteArray)),
__func__,
"Too long array for OpenSSL");
103 if constexpr (SpanT::extent != std::dynamic_extent) {
104 static_assert(std::in_range<
int>(SpanT::extent));
105 checkForSpanShortfall(std::size(byteArray),
static_cast<
int>(SpanT::extent));
107 return SpanT(std::bit_cast<
typename SpanT::pointer>(std::data(byteArray)),
108 std::min(SpanT::extent, unsignedSize(byteArray)));
124 return _impl::spanFromBytes<byte_view_t<N>>(buf);
131 return _impl::spanFromBytes<byte_span_t<N>>(buf);
247 return FixedBuffer<>{ bytes, FixedBufferBase::FillWithRandom };
250template <size_t SizeN>
253 return FixedBuffer<SizeN>{ FixedBufferBase::FillWithRandom };
269 explicit PicklingKey(InitOptions options) : FixedBuffer(options)
271 Q_ASSERT(options != FillWithZeros);
279 k.fillFrom(std::move(keySource));
A minimal subset of std::expected from C++23.
static PicklingKey fromByteArray(QByteArray &&keySource)
static PicklingKey mock()
static PicklingKey generate()
#define QOLM_FAIL_OR_LOG_X(InternalCondition_, Message_, LastErrorText_)
#define QOLM_INTERNAL_ERROR_X(Message_, LastError_)
auto asWritableCBytes(auto &buf)
Obtain a std::span<byte_t, N> looking into the passed buffer.
constexpr auto Ed25519Key
constexpr auto OlmV1Curve25519AesSha2AlgoKey
auto getRandom(size_t bytes)
bool isSupportedAlgorithm(const QString &algorithm)
constexpr auto SignedCurve25519Key
constexpr auto RotationPeriodMsKeyL
constexpr auto MegolmV1AesSha2AlgoKey
constexpr auto AlgorithmKey
constexpr auto Curve25519Key
constexpr auto RotationPeriodMsgsKeyL
auto asCBytes(const auto &buf)
Obtain a std::span<const byte_t, N> looking into the passed buffer.
constexpr auto RotationPeriodMsgsKey
constexpr auto AlgorithmKeyL
QUOTIENT_API void fillFromSecureRng(std::span< byte_t > bytes)
Fill the buffer with the securely generated random bytes.
constexpr std::array SupportedAlgorithms
constexpr auto RotationPeriodMsKey
Struct representing the one-time keys.
QHash< QString, QString > curve25519() const
Get the HashMap containing the curve25519 one-time keys.
QHash< QString, QHash< QString, QString > > keys
#define QUO_CSTR(StringConvertible_)
q(Utf8)Printable that can handle more than just QStrings