summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/corelib/tools/qcryptographichash.cpp23
-rw-r--r--src/corelib/tools/qcryptographichash.h2
2 files changed, 25 insertions, 0 deletions
diff --git a/src/corelib/tools/qcryptographichash.cpp b/src/corelib/tools/qcryptographichash.cpp
index 89b3bab7c6..e5ac73c3f5 100644
--- a/src/corelib/tools/qcryptographichash.cpp
+++ b/src/corelib/tools/qcryptographichash.cpp
@@ -50,6 +50,7 @@
#include "../../3rdparty/md4/md4.h"
#include "../../3rdparty/md4/md4.cpp"
#include "../../3rdparty/sha1/sha1.cpp"
+#include <qiodevice.h>
QT_BEGIN_NAMESPACE
@@ -155,6 +156,28 @@ void QCryptographicHash::addData(const QByteArray &data)
}
/*!
+ Reads the data from the open QIODevice \a device until it ends
+ and hashes it. Returns true if reading was successful.
+ */
+bool QCryptographicHash::addData(QIODevice* device)
+{
+ if (!device->isReadable())
+ return false;
+
+ if (!device->isOpen())
+ return false;
+
+ char buffer[1024];
+ int length;
+
+ while ((length = device->read(buffer,sizeof(buffer))) > 0)
+ addData(buffer,length);
+
+ return device->atEnd();
+}
+
+
+/*!
Returns the final hash value.
\sa QByteArray::toHex()
diff --git a/src/corelib/tools/qcryptographichash.h b/src/corelib/tools/qcryptographichash.h
index b40e8cc25b..15ebd22418 100644
--- a/src/corelib/tools/qcryptographichash.h
+++ b/src/corelib/tools/qcryptographichash.h
@@ -51,6 +51,7 @@ QT_BEGIN_NAMESPACE
QT_MODULE(Core)
class QCryptographicHashPrivate;
+class QIODevice;
class Q_CORE_EXPORT QCryptographicHash
{
@@ -68,6 +69,7 @@ public:
void addData(const char *data, int length);
void addData(const QByteArray &data);
+ bool addData(QIODevice* device);
QByteArray result() const;