From 649d56de33f7dd495f3935f3b02a43b5bd2a2069 Mon Sep 17 00:00:00 2001 From: Linus Jahn Date: Mon, 5 Sep 2022 17:18:20 +0200 Subject: Implement XEP-0300: Use of Cryptographic Hash Functions in XMPP Parsing and serialization for XEP-0300 https://xmpp.org/extensions/xep-0300.html in version 1.0. --- src/base/QXmppHash.h | 75 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 75 insertions(+) create mode 100644 src/base/QXmppHash.h (limited to 'src/base/QXmppHash.h') diff --git a/src/base/QXmppHash.h b/src/base/QXmppHash.h new file mode 100644 index 00000000..96293f80 --- /dev/null +++ b/src/base/QXmppHash.h @@ -0,0 +1,75 @@ +// SPDX-FileCopyrightText: 2022 Linus Jahn +// +// SPDX-License-Identifier: LGPL-2.1-or-later + +#ifndef QXMPPHASH_H +#define QXMPPHASH_H + +#include "QXmppGlobal.h" + +#include + +class QDomElement; +class QXmlStreamWriter; + +namespace QXmpp { + +enum class HashAlgorithm : uint32_t { + Unknown, + Md2, + Md5, + Shake128, + Shake256, + Sha1, + Sha224, + Sha256, + Sha384, + Sha512, + Sha3_256, + Sha3_512, + Blake2b_256, + Blake2b_512, +}; + +} + +class QXMPP_EXPORT QXmppHash +{ +public: + QXmppHash(); + + /// \cond + bool parse(const QDomElement &el); + void toXml(QXmlStreamWriter *writer) const; + /// \endcond + + QXmpp::HashAlgorithm algorithm() const; + void setAlgorithm(QXmpp::HashAlgorithm algorithm); + + QByteArray hash() const; + void setHash(const QByteArray &data); + +private: + QXmpp::HashAlgorithm m_algorithm = QXmpp::HashAlgorithm::Unknown; + QByteArray m_hash; +}; + +class QXMPP_EXPORT QXmppHashUsed +{ +public: + QXmppHashUsed(); + QXmppHashUsed(QXmpp::HashAlgorithm algorithm); + + /// \cond + bool parse(const QDomElement &el); + void toXml(QXmlStreamWriter *writer) const; + /// \endcond + + QXmpp::HashAlgorithm algorithm() const; + void setAlgorithm(QXmpp::HashAlgorithm algorithm); + +private: + QXmpp::HashAlgorithm m_algorithm = QXmpp::HashAlgorithm::Unknown; +}; + +#endif // QXMPPHASH_H -- cgit v1.2.3