forked from chris2511/xca
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathheaderlist.h
275 lines (256 loc) · 5.38 KB
/
headerlist.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
/* vi: set sw=4 ts=4:
*
* Copyright (C) 2010 - 2015 Christian Hohnstaedt.
*
* All rights reserved.
*/
#ifndef __HEADERLIST_H
#define __HEADERLIST_H
#include <QString>
#include <QList>
#include <QAction>
#include <QHeaderView>
#include <QDebug>
#include <openssl/objects.h>
#include "settings.h"
#include "pki_base.h"
#include "func.h"
#define HD_undef NID_undef
#define HD_internal_name -2
#define HD_subject_name -3
#define HD_subject_hash -4
#define HD_x509key_name -5
#define HD_counter -6
#define HD_x509_sigalg -7
#define HD_creation -8
#define HD_comment -9
#define HD_source -100
#define HD_primary_key -101
#define HD_cert_serial -10
#define HD_cert_notBefore -11
#define HD_cert_notAfter -12
//#define HD_cert_trust -13
#define HD_cert_revocation -14
#define HD_cert_ca -15
#define HD_cert_md5fp -16
#define HD_cert_sha1fp -17
#define HD_cert_sha256fp -18
#define HD_cert_crl_expire -19
#define HD_req_signed -20
#define HD_req_unstr_name -21
#define HD_req_chall_pass -22
#define HD_req_certs -23
//#define HD_temp_type -30
#define HD_crl_signer -40
#define HD_crl_revoked -42
#define HD_crl_lastUpdate -43
#define HD_crl_nextUpdate -44
#define HD_crl_crlnumber -45
#define HD_key_type -50
#define HD_key_size -51
#define HD_key_use -52
#define HD_key_passwd -53
#define HD_key_curve -54
class dbheader
{
protected:
QString name{}, tooltip{};
public:
enum hdr_type {
hd_default,
hd_x509name,
hd_v3ext,
hd_v3ext_ns,
hd_number,
hd_asn1time,
hd_key,
};
int id{ HD_undef };
bool show{ false };
bool showDefault{ false };
QAction *action{};
int size{ -1 };
int visualIndex{ -1 };
int sortIndicator{ -1 };
enum hdr_type type{ hd_default };
virtual QString getName() { return name; }
virtual QString getTooltip() { return tooltip; }
dbheader(QString aname = QString()) : name(aname) { }
dbheader(int aid, bool ashow = false,
QString aname = QString(), QString atip = QString())
: name(aname), tooltip(atip), id(aid), show(ashow), showDefault(ashow)
{
}
virtual ~dbheader() { }
bool mustSave()
{
return size != -1 ||
visualIndex != -1 ||
sortIndicator != -1 ||
show != showDefault;
}
bool operator == (const dbheader *h) const
{
if (h->id == HD_undef)
return name == h->name;
return id == h->id;
}
bool isNumeric()
{
switch (id) {
case NID_subject_key_identifier:
case NID_authority_key_identifier:
case HD_key_size:
return true;
}
return type == hd_number;
}
QString toData()
{
QStringList sl{
QString::number(visualIndex),
QString::number(sortIndicator),
QString::number(size),
QString::number(show)
};
return sl.join(" ");
}
void fromData(QString s)
{
QStringList sl = s.split(" ");
if (sl.count() != 4) {
qCritical() << "Invalid header data for" <<
id << name << s;
return;
}
visualIndex = sl[0].toInt();
if (visualIndex < -1)
visualIndex = -1;
sortIndicator = sl[1].toInt();
if (sortIndicator != Qt::AscendingOrder &&
sortIndicator != Qt::DescendingOrder)
sortIndicator = -1;
size = sl[2].toInt();
if (size == 0)
size = -1;
show = sl[3].toInt();
}
void setupHeaderView(int sect, QHeaderView *hv)
{
hv->setSectionHidden(sect, !show);
if (size != -1)
hv->resizeSection(sect, size);
if (sortIndicator != -1) {
hv->setSortIndicator(sect, sortIndicator ?
Qt::DescendingOrder : Qt::AscendingOrder);
}
}
void reset()
{
action = NULL;
show = showDefault;
size = -1;
visualIndex = -1;
sortIndicator = -1;
}
};
class nid_dbheader : public dbheader
{
private:
QString sn{};
public:
nid_dbheader(int aid, enum hdr_type atype)
: dbheader(aid, aid == NID_commonName)
{
type = atype;
tooltip = dn_translations[id];
name = OBJ_nid2ln(id);
sn = OBJ_nid2sn(id);
if (tooltip.isEmpty())
tooltip = name;
}
QString getName()
{
return Settings["translate_dn"] ? tooltip : name;
}
QString getTooltip()
{
return QString("[%1] %2").arg(sn)
.arg(Settings["translate_dn"] ? name : tooltip);
}
};
class num_dbheader : public dbheader
{
public:
num_dbheader(int aid, bool ashow = false,
QString aname = QString(), QString atip = QString())
: dbheader(aid, ashow, aname, atip)
{
type = hd_number;
}
};
class date_dbheader : public dbheader
{
public:
date_dbheader(int aid, bool ashow = false,
QString aname = QString(), QString atip = QString())
: dbheader(aid, ashow, aname, atip)
{
type = hd_asn1time;
}
};
class key_dbheader : public dbheader
{
public:
key_dbheader(int aid, QString aname)
: dbheader(aid, false, aname)
{
type = hd_key;
}
};
class dbheaderList: public QList<dbheader*>
{
public:
dbheaderList(dbheader *h) :QList<dbheader*>() {
append(h);
}
dbheaderList() :QList<dbheader*>() {
}
QString toData()
{
QStringList sl;
for (int i=0; i<count(); i++) {
QStringList seq;
dbheader *h = at(i);
if (!h->mustSave())
continue;
seq << QString("%1").arg(h->id);
if (h->id > 0) {
seq << OBJ_obj2QString(
OBJ_nid2obj(h->id), 1);
}
seq << h->toData();
sl << seq.join(":");
}
return sl.join(",");
}
void fromData(QString s)
{
QStringList sl = s.split(",");
foreach(QString hd, sl) {
QStringList sl1 = hd.split(":");
int id = sl1.takeFirst().toInt();
if (id > 0) {
id = OBJ_txt2nid(CCHAR(sl1.takeFirst()));
}
for (int i=0; i<count(); i++) {
dbheader *h = at(i);
if (h->id == id) {
h->fromData(sl1.takeFirst());
break;
}
}
}
}
};
#endif