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

source code of qtbase/src/plugins/tls/shared/qx509_base.cpp