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 {
46 Invalid,
47 Md5,
48 Sha256
49 };
50 Hash();
51 explicit Hash(const QByteArray &data, Type type);
52
53 bool operator==(const Hash &other) const;
54
55 bool isValid() const;
56
57 Type type() const;
58 Hash128 md5() const;
59 Hash256 sha256() const;
60
61 QString hexString() const;
62
63private:
64 friend size_t qHash(const Hash &h, size_t seed) noexcept;
65 union {
66 Hash128 md5;
67 Hash256 sha256;
68 } m_hash;
69 Type m_type;
70};
71}
KCALENDARCORE_EXPORT size_t qHash(const KCalendarCore::Period &key, size_t seed=0)
KIOCORE_EXPORT bool operator==(const UDSEntry &entry, const UDSEntry &other)
bool isValid(QStringView ifopt)
VehicleSection::Type type(QStringView coachNumber, QStringView coachClassification)
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Mon Nov 4 2024 16:39:41 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.