swift
Loading...
Searching...
No Matches
obfuscation.cpp
1// SPDX-FileCopyrightText: Copyright (C) 2018 swift Project Community / Contributors
2// SPDX-License-Identifier: GPL-3.0-or-later OR LicenseRef-swift-pilot-client-1
3
4#include "misc/obfuscation.h"
5
6#include <QStringBuilder>
7
8#include "simplecrypt/simplecrypt.h"
9
10namespace swift::misc
11{
12 QString CObfuscation::decode(const QString &inString, bool trimmed)
13 {
14 if (!inString.startsWith(prefix()))
15 {
16 return trimmed ? inString.trimmed() : inString;
17 }
18 if (inString.length() == prefix().length())
19 {
20 return {};
21 }
22 SimpleCrypt simpleCrypt(Key);
23 const QString decoded = simpleCrypt.decryptToString(inString.mid(prefix().length()));
24 return trimmed ? decoded.trimmed() : decoded;
25 }
26
27 QString CObfuscation::encode(const QString &inString, bool trimmed)
28 {
29 SimpleCrypt simpleCrypt(Key);
30 const QString encrypted = simpleCrypt.encryptToString(trimmed ? inString.trimmed() : inString);
31 return prefix() % encrypted;
32 }
33
35 {
36 static const QString obfuscated("OBF:");
37 return obfuscated;
38 }
39} // namespace swift::misc
static QString decode(const QString &inString, bool trimmed=true)
Decode string if it has the prefix, otherwise do nothing with it.
static const QString & prefix()
Prefix to be used with obfuscated string.
static QString encode(const QString &inString, bool trimmed=true)
Encode string and return with prefix.
Free functions in swift::misc.
qsizetype length() const const
QString mid(qsizetype position, qsizetype n) &&
bool startsWith(QChar c, Qt::CaseSensitivity cs) const const
QString trimmed() const const