Gravatar

hash.h
1/*
2 SPDX-FileCopyrightText: 2017 Volker Krause <vkrause@kde.org>
3
4 SPDX-License-Identifier: LGPL-2.0-or-later
5*/
6
7#pragma once
8
9#include "gravatar_private_export.h"
10
11#include <cstdint>
12#include <cstring>
13
14class QByteArray;
15class QString;
16
17namespace Gravatar
18{
19template<int Size>
20struct UnsignedInt {
21 bool operator<(const UnsignedInt<Size> &other) const
22 {
23 return memcmp(data, other.data, Size) < 0;
24 }
25
26 bool operator==(const UnsignedInt<Size> &other) const
27 {
28 return memcmp(data, other.data, Size) == 0;
29 }
30
31 uint8_t data[Size];
32};
33struct Hash128 : public UnsignedInt<16> {
34};
35struct Hash256 : public UnsignedInt<32> {
36};
37
38class Hash;
39size_t qHash(const Hash &h, size_t seed = 0) noexcept;
40
41// exported for unit tests only
42class GRAVATAR_TESTS_EXPORT Hash
43{
44public:
45 enum Type { Invalid, Md5, Sha256 };
46 Hash();
47 explicit Hash(const QByteArray &data, Type type);
48
49 bool operator==(const Hash &other) const;
50
51 bool isValid() const;
52
53 Type type() const;
54 Hash128 md5() const;
55 Hash256 sha256() const;
56
57 QString hexString() const;
58
59private:
60 friend size_t qHash(const Hash &h, size_t seed) noexcept;
61 union {
62 Hash128 md5;
63 Hash256 sha256;
64 } m_hash;
65 Type m_type;
66};
67}
Type type(const QSqlDatabase &db)
bool isValid(QStringView ifopt)
KTEXTEDITOR_EXPORT size_t qHash(KTextEditor::Cursor cursor, size_t seed=0) noexcept
bool operator==(const QGraphicsApiFilter &reference, const QGraphicsApiFilter &sample)
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Sat Apr 27 2024 22:06:15 by doxygen 1.10.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.