Coverage Report

Created: 2026-03-12 07:14

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/qtbase/src/plugins/tls/shared/qx509_base.cpp
Line
Count
Source
1
// Copyright (C) 2021 The Qt Company Ltd.
2
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
3
// Qt-Security score:significant reason:default
4
5
#include "qx509_base_p.h"
6
7
QT_BEGIN_NAMESPACE
8
9
namespace QTlsPrivate {
10
11
QByteArray X509CertificateBase::subjectInfoToString(QSslCertificate::SubjectInfo info)
12
0
{
13
0
    QByteArray str;
14
0
    switch (info) {
15
0
    case QSslCertificate::Organization: str = QByteArray("O"); break;
16
0
    case QSslCertificate::CommonName: str = QByteArray("CN"); break;
17
0
    case QSslCertificate::LocalityName: str = QByteArray("L"); break;
18
0
    case QSslCertificate::OrganizationalUnitName: str = QByteArray("OU"); break;
19
0
    case QSslCertificate::CountryName: str = QByteArray("C"); break;
20
0
    case QSslCertificate::StateOrProvinceName: str = QByteArray("ST"); break;
21
0
    case QSslCertificate::DistinguishedNameQualifier: str = QByteArray("dnQualifier"); break;
22
0
    case QSslCertificate::SerialNumber: str = QByteArray("serialNumber"); break;
23
0
    case QSslCertificate::EmailAddress: str = QByteArray("emailAddress"); break;
24
0
    }
25
26
0
    return str;
27
0
}
28
29
bool X509CertificateBase::matchLineFeed(const QByteArray &pem, int *offset)
30
0
{
31
0
    Q_ASSERT(offset);
32
33
0
    char ch = 0;
34
    // ignore extra whitespace at the end of the line
35
0
    while (*offset < pem.size() && (ch = pem.at(*offset)) == ' ')
36
0
        ++*offset;
37
38
0
    if (ch == '\n') {
39
0
        *offset += 1;
40
0
        return true;
41
0
    }
42
43
0
    if (ch == '\r' && pem.size() > (*offset + 1) && pem.at(*offset + 1) == '\n') {
44
0
        *offset += 2;
45
0
        return true;
46
0
    }
47
48
0
    return false;
49
0
}
50
51
bool X509CertificateBase::isNull() const
52
0
{
53
0
    return null;
54
0
}
55
56
QByteArray X509CertificateBase::version() const
57
0
{
58
0
    return versionString;
59
0
}
60
61
QByteArray X509CertificateBase::serialNumber() const
62
0
{
63
0
    return serialNumberString;
64
0
}
65
66
QStringList X509CertificateBase::issuerInfo(QSslCertificate::SubjectInfo info) const
67
0
{
68
0
    return issuerInfo(subjectInfoToString(info));
69
0
}
70
71
QStringList X509CertificateBase::issuerInfo(const QByteArray &attribute) const
72
0
{
73
0
    return issuerInfoEntries.values(attribute);
74
0
}
75
76
QStringList X509CertificateBase::subjectInfo(QSslCertificate::SubjectInfo info) const
77
0
{
78
0
    return subjectInfo(subjectInfoToString(info));
79
0
}
80
81
QStringList X509CertificateBase::subjectInfo(const QByteArray &attribute) const
82
0
{
83
0
    return subjectInfoEntries.values(attribute);
84
0
}
85
86
QList<QByteArray> X509CertificateBase::subjectInfoAttributes() const
87
0
{
88
0
    return subjectInfoEntries.uniqueKeys();
89
0
}
90
91
QList<QByteArray> X509CertificateBase::issuerInfoAttributes() const
92
0
{
93
0
    return issuerInfoEntries.uniqueKeys();
94
0
}
95
96
QDateTime X509CertificateBase::effectiveDate() const
97
0
{
98
0
    return notValidBefore;
99
0
}
100
101
QDateTime X509CertificateBase::expiryDate() const
102
0
{
103
0
    return notValidAfter;
104
0
}
105
106
qsizetype X509CertificateBase::numberOfExtensions() const
107
0
{
108
0
    return extensions.size();
109
0
}
110
111
QString X509CertificateBase::oidForExtension(qsizetype index) const
112
0
{
113
0
    Q_ASSERT(validIndex(index));
114
0
    return extensions[index].oid;
115
0
}
116
117
QString X509CertificateBase::nameForExtension(qsizetype index) const
118
0
{
119
0
    Q_ASSERT(validIndex(index));
120
0
    return extensions[index].name;
121
0
}
122
123
QVariant X509CertificateBase::valueForExtension(qsizetype index) const
124
0
{
125
0
    Q_ASSERT(validIndex(index));
126
0
    return extensions[index].value;
127
0
}
128
129
bool X509CertificateBase::isExtensionCritical(qsizetype index) const
130
0
{
131
0
    Q_ASSERT(validIndex(index));
132
0
    return extensions[index].critical;
133
0
}
134
135
bool X509CertificateBase::isExtensionSupported(qsizetype index) const
136
0
{
137
    Q_ASSERT(validIndex(index));
138
0
    return extensions[index].supported;
139
0
}
140
141
} // namespace QTlsPrivate
142
143
QT_END_NAMESPACE