Browse Source

Make base58 validator explicit

pull/1/head
Wladimir J. van der Laan 12 years ago
parent
commit
dab03e34f5
  1. 5
      gui/include/bitcoinaddressvalidator.h
  2. 26
      gui/src/bitcoinaddressvalidator.cpp

5
gui/include/bitcoinaddressvalidator.h

@ -3,7 +3,10 @@ @@ -3,7 +3,10 @@
#include <QRegExpValidator>
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:

26
gui/src/bitcoinaddressvalidator.cpp

@ -1,7 +1,5 @@ @@ -1,7 +1,5 @@
#include "bitcoinaddressvalidator.h"
#include "base58.h"
#include <QDebug>
/* Base58 characters are:
@ -18,12 +16,13 @@ @@ -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<input.size(); ++idx)
{
switch(input.at(idx).unicode())
@ -39,7 +38,26 @@ QValidator::State BitcoinAddressValidator::validate(QString &input, int &pos) co @@ -39,7 +38,26 @@ QValidator::State BitcoinAddressValidator::validate(QString &input, int &pos) co
default:
break;
}
}
/* Validation */
QValidator::State state = QValidator::Acceptable;
for(int idx=0; idx<input.size(); ++idx)
{
int ch = input.at(idx).unicode();
if(((ch >= '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;
}

Loading…
Cancel
Save