diff --git a/src/ui/util/stringutil.cpp b/src/ui/util/stringutil.cpp index af3ff737..98eda7db 100644 --- a/src/ui/util/stringutil.cpp +++ b/src/ui/util/stringutil.cpp @@ -9,17 +9,30 @@ QString StringUtil::capitalize(const QString &text) return firstChar.toUpper() + text.mid(1); } +QByteArray StringUtil::cryptoSha1(const QByteArray &data) +{ + return QCryptographicHash::hash(data, QCryptographicHash::Sha1); +} + QString StringUtil::cryptoHash(const QString &text) { if (text.isEmpty()) return QString(); const QByteArray data = text.toUtf8(); - const QByteArray hash = QCryptographicHash::hash(data, QCryptographicHash::Sha1); + const QByteArray hash = cryptoSha1(data); return QString::fromLatin1(hash.toHex()); } +QByteArray StringUtil::serviceSid(const QString &serviceName) +{ + const auto name = serviceName.toUpper(); + const QByteArray nameData((const char *) name.utf16(), name.size() * sizeof(wchar_t)); + + return StringUtil::cryptoSha1(nameData); +} + int StringUtil::lineStart(const QString &text, int pos, int badPos) { const int startPos = text.lastIndexOf(QLatin1Char('\n'), pos); diff --git a/src/ui/util/stringutil.h b/src/ui/util/stringutil.h index 52ad4f21..fddcd9b2 100644 --- a/src/ui/util/stringutil.h +++ b/src/ui/util/stringutil.h @@ -11,8 +11,11 @@ class StringUtil public: static QString capitalize(const QString &text); + static QByteArray cryptoSha1(const QByteArray &data); static QString cryptoHash(const QString &text); + static QByteArray serviceSid(const QString &serviceName); + static int lineStart(const QString &text, int pos, int badPos = -1); static int lineEnd(const QString &text, int pos, int badPos = -1);