aboutsummaryrefslogtreecommitdiff
path: root/src/base/QXmppBitsOfBinaryData.cpp
diff options
context:
space:
mode:
authorLinus Jahn <lnj@kaidan.im>2022-09-14 20:16:59 +0200
committerLinus Jahn <lnj@kaidan.im>2022-09-14 22:28:32 +0200
commitf48aedd89fc7654a8435367aa50a124724dfcd0c (patch)
treee30432f1f0a5625eb89b0bb3b32cbe8a9031fa81 /src/base/QXmppBitsOfBinaryData.cpp
parent50be94233ad615ef8061e344f4123745714339c7 (diff)
BitsOfBinaryData: Add fromByteArray() utility function
It automatically hashes the data and creates a content ID.
Diffstat (limited to 'src/base/QXmppBitsOfBinaryData.cpp')
-rw-r--r--src/base/QXmppBitsOfBinaryData.cpp23
1 files changed, 23 insertions, 0 deletions
diff --git a/src/base/QXmppBitsOfBinaryData.cpp b/src/base/QXmppBitsOfBinaryData.cpp
index 1592a2e5..6f9226de 100644
--- a/src/base/QXmppBitsOfBinaryData.cpp
+++ b/src/base/QXmppBitsOfBinaryData.cpp
@@ -41,6 +41,29 @@ QXmppBitsOfBinaryDataPrivate::QXmppBitsOfBinaryDataPrivate()
///
///
+/// Creates bits of binary data from a QByteArray.
+///
+/// This hashes the data to generate a content ID. The MIME type is not set.
+///
+/// \note This blocks while hashing the data. You may want to run this via QtConcurrent or a
+/// QThreadPool to run this on for large amounts of data.
+///
+/// \since QXmpp 1.5
+///
+QXmppBitsOfBinaryData QXmppBitsOfBinaryData::fromByteArray(QByteArray data)
+{
+ QXmppBitsOfBinaryContentId cid;
+ cid.setHash(QCryptographicHash::hash(data, QCryptographicHash::Sha1));
+ cid.setAlgorithm(QCryptographicHash::Sha1);
+
+ QXmppBitsOfBinaryData bobData;
+ bobData.d->cid = std::move(cid);
+ bobData.d->data = std::move(data);
+
+ return bobData;
+}
+
+///
/// Default constructor
///
QXmppBitsOfBinaryData::QXmppBitsOfBinaryData()