From 4eeb856c73fafabb8e12fc768cccfd90f5ea9a33 Mon Sep 17 00:00:00 2001 From: Christian Hohnstaedt Date: Sun, 11 Mar 2018 10:02:14 +0100 Subject: [PATCH] Make hex the default input / output qstring of asn1integer --- lib/asn1int.cpp | 11 +++++++++++ lib/asn1int.h | 2 ++ lib/pki_x509.cpp | 2 +- widgets/CertDetail.cpp | 2 +- widgets/CrlDetail.cpp | 2 +- widgets/RevocationList.cpp | 24 +++++++++--------------- 6 files changed, 25 insertions(+), 18 deletions(-) diff --git a/lib/asn1int.cpp b/lib/asn1int.cpp index d9717daa..9457c6b0 100644 --- a/lib/asn1int.cpp +++ b/lib/asn1int.cpp @@ -42,6 +42,12 @@ a1int::a1int(const a1int &a) in = dup(a.in); } +a1int::a1int(const QString &hex) +{ + in = ASN1_INTEGER_new(); + check_oom(in); + setHex(hex); +} a1int::a1int(long l) { @@ -202,6 +208,11 @@ bool a1int::operator != (const a1int &a) const return (ASN1_INTEGER_cmp(in, a.in) != 0); } +a1int::operator QString() const +{ + return toHex(); +} + QByteArray a1int::i2d() { return i2d_bytearray(I2D_VOID(i2d_ASN1_INTEGER), in); diff --git a/lib/asn1int.h b/lib/asn1int.h index 9228faad..b048ba0d 100644 --- a/lib/asn1int.h +++ b/lib/asn1int.h @@ -23,6 +23,7 @@ class a1int a1int(const ASN1_INTEGER *i); a1int(const a1int &a); a1int(long l); + a1int(const QString &hex); ~a1int(); a1int &set(const ASN1_INTEGER *i); a1int &set(long l); @@ -45,6 +46,7 @@ class a1int bool operator < (const a1int &a) const; bool operator == (const a1int &a) const; bool operator != (const a1int &a) const; + operator QString() const; }; #endif diff --git a/lib/pki_x509.cpp b/lib/pki_x509.cpp index b8543d90..6edbf41c 100644 --- a/lib/pki_x509.cpp +++ b/lib/pki_x509.cpp @@ -698,7 +698,7 @@ QString pki_x509::getIndexEntry() return QString("%1\t%2\t%3\t%4\tunknown\t%5\n").arg( flag, getNotAfter().toPlainUTC(), revoked ? revocation.getDate().toPlainUTC() : "", - getSerial().toHex(), + getSerial(), QString(X509_NAME_oneline(getSubject().get(), NULL, 0))); } diff --git a/widgets/CertDetail.cpp b/widgets/CertDetail.cpp index 64a6c323..cb1c114c 100644 --- a/widgets/CertDetail.cpp +++ b/widgets/CertDetail.cpp @@ -111,7 +111,7 @@ void CertDetail::setCert(pki_x509 *cert) } // the serial - serialNr->setText(cert->getSerial().toHex()); + serialNr->setText(cert->getSerial()); // details of the issuer issuer->setX509name(cert->getIssuerName()); diff --git a/widgets/CrlDetail.cpp b/widgets/CrlDetail.cpp index e6c360bc..a585d812 100644 --- a/widgets/CrlDetail.cpp +++ b/widgets/CrlDetail.cpp @@ -64,7 +64,7 @@ void CrlDetail::setCrl(pki_crl *crl) lUpdate->setToolTip(crl->getLastUpdate().toPrettyGMT()); nUpdate->setText(crl->getNextUpdate().toPretty()); nUpdate->setToolTip(crl->getNextUpdate().toPrettyGMT()); - version->setText((++crl->getVersion()).toHex()); + version->setText((++crl->getVersion())); issuer->setX509name(crl->getSubject()); diff --git a/widgets/RevocationList.cpp b/widgets/RevocationList.cpp index 528a4901..3a8253dc 100644 --- a/widgets/RevocationList.cpp +++ b/widgets/RevocationList.cpp @@ -21,10 +21,8 @@ class revListItem : public QTreeWidgetItem int col = treeWidget()->sortColumn(); switch (col) { case Cserial: { - a1int ithis, iother; - ithis.setHex(text(Cserial)); - iother.setHex(other.text(Cserial)); - return ithis < iother; + return a1int(text(Cserial)) < + a1int(other.text(Cserial)); } case Cnumber: return text(Cnumber).toLong() < @@ -43,7 +41,7 @@ static void setup_revRevItem(QTreeWidgetItem *item, const x509rev &revit, for (int i = 0; i < Cmax; i++) item->setToolTip(i, rev->getIntName()); } - item->setText(Cserial, revit.getSerial().toHex()); + item->setText(Cserial, revit.getSerial()); item->setText(Cdate, revit.getDate().toSortable()); item->setText(Creason, revit.getReason()); @@ -141,14 +139,12 @@ void RevocationList::on_delRev_clicked(void) QTreeWidgetItem *current = certList->currentItem(); x509rev rev; int idx; - a1int a1_serial; if (!current) return; idx = certList->indexOfTopLevelItem(current); certList->takeTopLevelItem(idx); - a1_serial.setHex(current->text(Cserial)); - rev.setSerial(a1_serial); + rev.setSerial(a1int(current->text(Cserial))); idx = revList.indexOf(rev); if (idx != -1) revList.takeAt(idx); @@ -159,13 +155,11 @@ void RevocationList::on_editRev_clicked() QTreeWidgetItem *current = certList->currentItem(); x509rev rev; int idx; - a1int a1_serial; if (!current) return; - a1_serial.setHex(current->text(Cserial)); - rev.setSerial(a1_serial); + rev.setSerial(a1int(current->text(Cserial))); idx = revList.indexOf(rev); if (idx == -1) return; @@ -203,13 +197,13 @@ Revocation::Revocation(QWidget *w, QModelIndexList indexes) : QDialog(w) } qSort(serials.begin(), serials.end()); foreach(a1int a, serials) - sl << a.toHex(); + sl << a; serial->setToolTip(sl.join("\n")); serial->setEnabled(false); } else if (indexes.size() == 1) { pki_x509 *cert = static_cast (indexes[0].internalPointer()); - serial->setText(cert->getSerial().toHex()); + serial->setText(cert->getSerial()); serial->setEnabled(false); } else { serial->setValidator( @@ -221,7 +215,7 @@ x509rev Revocation::getRevocation() { x509rev r; - r.setSerial(a1int().setHex(serial->text())); + r.setSerial(a1int(serial->text())); r.setInvalDate(invalid->getDate()); r.setDate(a1time()); r.setCrlNo(0); @@ -233,7 +227,7 @@ void Revocation::setRevocation(x509rev r) { a1int i; - serial->setText(r.getSerial().toHex()); + serial->setText(r.getSerial()); invalid->setDate(r.getInvalDate()); reason->setCurrentText(r.getReason()); }