8#include "../converters.h"
9#include "../expected.h"
11#include <QtCore/QMetaType>
12#include <QtCore/QStringBuilder>
37 MegolmV1AesSha2AlgoKey };
41 return std::ranges::find(SupportedAlgorithms, algorithm) != SupportedAlgorithms.cend();
44#define QOLM_INTERNAL_ERROR_X(Message_, LastError_)
45 qFatal("%s, internal error: %s", QUO_CSTR(Message_), LastError_)
47#define QOLM_INTERNAL_ERROR(Message_)
50#define QOLM_FAIL_OR_LOG_X(InternalCondition_, Message_, LastErrorText_)
52 if (InternalCondition_)
54 qWarning(E2EE).nospace() << (Message_) << ": " << (LastErrorText_);
57#define QOLM_FAIL_OR_LOG(InternalFailureValue_, Message_)
58 QOLM_FAIL_OR_LOG_X(lastErrorCode() == (InternalFailureValue_), (Message_), lastError())
95 QUOTIENT_API void checkForSpanShortfall(QByteArray::size_type inputSize,
int neededSize);
97 template <
typename SpanT>
98 inline auto spanFromBytes(
auto& byteArray)
101 Q_ASSERT_X(std::in_range<
int>(std::size(byteArray)),
__func__,
"Too long array for OpenSSL");
102 if constexpr (SpanT::extent != std::dynamic_extent) {
103 static_assert(std::in_range<
int>(SpanT::extent));
104 checkForSpanShortfall(std::size(byteArray),
static_cast<
int>(SpanT::extent));
106 return SpanT(std::bit_cast<
typename SpanT::pointer>(std::data(byteArray)),
107 std::min(SpanT::extent, unsignedSize(byteArray)));
123 return _impl::spanFromBytes<byte_view_t<N>>(buf);
130 return _impl::spanFromBytes<byte_span_t<N>>(buf);
246 return FixedBuffer<>{ bytes, FixedBufferBase::FillWithRandom };
249template <size_t SizeN>
252 return FixedBuffer<SizeN>{ FixedBufferBase::FillWithRandom };
268 explicit PicklingKey(InitOptions options) : FixedBuffer(options)
270 Q_ASSERT(options != FillWithZeros);
278 k.fillFrom(std::move(keySource));
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 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