Krita Source Code Documentation
Loading...
Searching...
No Matches
KoMD5Generator.cpp
Go to the documentation of this file.
1/*
2 * SPDX-FileCopyrightText: 2015 Stefano Bonicatti <smjert@gmail.com>
3 *
4 * SPDX-License-Identifier: LGPL-2.1-or-later
5*/
6#include "KoMD5Generator.h"
7
8#include <QIODevice>
9#include <QFile>
10#include <QCryptographicHash>
11
12QString KoMD5Generator::generateHash(const QByteArray &array)
13{
14 QString result;
15
16 if (!array.isEmpty()) {
17 QCryptographicHash md5(QCryptographicHash::Md5);
18 md5.addData(array);
19 result = md5.result().toHex();
20 }
21
22 return result;
23}
24
25QString KoMD5Generator::generateHash(const QString &filename)
26{
27 QString result;
28
29 QFile f(filename);
30 if (f.exists() && f.open(QIODevice::ReadOnly)) {
31 QCryptographicHash md5(QCryptographicHash::Md5);
32 md5.addData(&f);
33 result = md5.result().toHex();
34 }
35
36 return result;
37}
38
39QString KoMD5Generator::generateHash(QIODevice *device)
40{
41 QString result;
42
43 QCryptographicHash md5(QCryptographicHash::Md5);
44 md5.addData(device);
45 result = md5.result().toHex();
46
47 return result;
48}
static QString generateHash(const QString &filename)
generateHash reads the given file and generates a hex-encoded md5sum for the file.