From dab03e34f5973d27797b7b415558fa75691a3830 Mon Sep 17 00:00:00 2001 From: "Wladimir J. van der Laan" Date: Fri, 3 Jun 2011 10:52:49 +0200 Subject: [PATCH] Make base58 validator explicit --- gui/include/bitcoinaddressvalidator.h | 5 ++++- gui/src/bitcoinaddressvalidator.cpp | 26 ++++++++++++++++++++++---- 2 files changed, 26 insertions(+), 5 deletions(-) diff --git a/gui/include/bitcoinaddressvalidator.h b/gui/include/bitcoinaddressvalidator.h index c7b2eefc..73f6ea1f 100644 --- a/gui/include/bitcoinaddressvalidator.h +++ b/gui/include/bitcoinaddressvalidator.h @@ -3,7 +3,10 @@ #include -class BitcoinAddressValidator : public QRegExpValidator +/* Base48 entry widget validator. + Corrects near-miss characters and refuses characters that are no part of base48. + */ +class BitcoinAddressValidator : public QValidator { Q_OBJECT public: diff --git a/gui/src/bitcoinaddressvalidator.cpp b/gui/src/bitcoinaddressvalidator.cpp index bccf4457..761a2669 100644 --- a/gui/src/bitcoinaddressvalidator.cpp +++ b/gui/src/bitcoinaddressvalidator.cpp @@ -1,7 +1,5 @@ #include "bitcoinaddressvalidator.h" -#include "base58.h" - #include /* Base58 characters are: @@ -18,12 +16,13 @@ */ BitcoinAddressValidator::BitcoinAddressValidator(QObject *parent) : - QRegExpValidator(QRegExp(QString("^[")+QString(pszBase58)+QString("]+")), parent) + QValidator(parent) { } QValidator::State BitcoinAddressValidator::validate(QString &input, int &pos) const { + /* Correction */ for(int idx=0; idx= '0' && ch<='9') || + (ch >= 'a' && ch<='z') || + (ch >= 'A' && ch<='Z')) && + ch != 'l' && ch != 'I' && ch != '0' && ch != 'O') + { + /* Alphanumeric and not a 'forbidden' character */ + } + else + { + state = QValidator::Invalid; + } } - return QRegExpValidator::validate(input, pos); + + return state; }