7#include "dkimkeyrecord.h"
8#include "messageviewer_dkimcheckerdebug.h"
10using namespace MessageViewer;
12DKIMKeyRecord::DKIMKeyRecord() =
default;
14bool DKIMKeyRecord::parseKey(
const QString &key)
19 qCWarning(MESSAGEVIEWER_DKIMCHECKER_LOG) <<
"Error: trying to parse empty key";
22 newKey.
replace(QLatin1StringView(
"; "), QLatin1StringView(
";"));
23 const QStringList items = newKey.
split(QLatin1Char(
';'));
24 for (
int i = 0; i < items.
count(); ++i) {
25 const QString elem = items.
at(i).trimmed();
26 if (elem.
startsWith(QLatin1StringView(
"v="))) {
28 }
else if (elem.
startsWith(QLatin1StringView(
"h="))) {
31 }
else if (elem.
startsWith(QLatin1StringView(
"k="))) {
33 }
else if (elem.
startsWith(QLatin1StringView(
"n="))) {
35 }
else if (elem.
startsWith(QLatin1StringView(
"p="))) {
37 }
else if (elem.
startsWith(QLatin1StringView(
"s="))) {
43 const QStringList lst = elem.
right(elem.
length() - 2).
split(QLatin1Char(
':'));
44 for (
const QString &service : lst) {
45 if (service == QLatin1Char(
'*') || service == QLatin1StringView(
"email")) {
49 }
else if (elem.
startsWith(QLatin1StringView(
"t="))) {
67 if (mVersion.isEmpty()) {
68 mVersion = QStringLiteral(
"DKIM1");
70 if (mKeyType.isEmpty()) {
71 mKeyType = QStringLiteral(
"rsa");
73 if (mService.isEmpty()) {
74 mService = QLatin1Char(
'*');
79QString DKIMKeyRecord::version()
const
84void DKIMKeyRecord::setVersion(
const QString &version)
89QString DKIMKeyRecord::keyType()
const
94void DKIMKeyRecord::setKeyType(
const QString &keyType)
99QString DKIMKeyRecord::note()
const
104void DKIMKeyRecord::setNote(
const QString ¬e)
109QString DKIMKeyRecord::publicKey()
const
114void DKIMKeyRecord::setPublicKey(
const QString &publicKey)
116 mPublicKey = publicKey;
119QString DKIMKeyRecord::service()
const
124void DKIMKeyRecord::setService(
const QString &service)
129QStringList DKIMKeyRecord::flags()
const
134void DKIMKeyRecord::setFlags(
const QStringList &flags)
139bool DKIMKeyRecord::operator==(
const DKIMKeyRecord &other)
const
141 return mVersion == other.version() && mNote == other.note() && mPublicKey == other.publicKey() && mService == other.service()
142 && mHashAlgorithm == other.hashAlgorithm() && mFlags == other.flags();
145QStringList DKIMKeyRecord::hashAlgorithm()
const
147 return mHashAlgorithm;
150void DKIMKeyRecord::setHashAlgorithm(
const QStringList &hashAlgorithm)
152 mHashAlgorithm = hashAlgorithm;
157 d <<
"mVersion " << t.version();
158 d <<
"mKeyType " << t.keyType();
159 d <<
"mNote " << t.note();
160 d <<
"mPublicKey " << t.publicKey();
161 d <<
"mService " << t.service();
162 d <<
"mHashAlgorithm " << t.hashAlgorithm();
163 d <<
"mFlags " << t.flags();
KTEXTEDITOR_EXPORT QDebug operator<<(QDebug s, const MovingCursor &cursor)
const_reference at(qsizetype i) const const
qsizetype count() const const
bool isEmpty() const const
qsizetype length() const const
QString & remove(QChar ch, Qt::CaseSensitivity cs)
QString & replace(QChar before, QChar after, Qt::CaseSensitivity cs)
QString right(qsizetype n) const const
QStringList split(QChar sep, Qt::SplitBehavior behavior, Qt::CaseSensitivity cs) const const
bool startsWith(QChar c, Qt::CaseSensitivity cs) const const