LCOV - code coverage report
Current view: top level - src/qt - bitcoinaddressvalidator.cpp (source / functions) Hit Total Coverage
Test: total_coverage.info Lines: 0 34 0.0 %
Date: 2020-09-26 01:30:44 Functions: 0 6 0.0 %

          Line data    Source code
       1             : // Copyright (c) 2011-2018 The Bitcoin Core developers
       2             : // Distributed under the MIT software license, see the accompanying
       3             : // file COPYING or http://www.opensource.org/licenses/mit-license.php.
       4             : 
       5             : #include <qt/bitcoinaddressvalidator.h>
       6             : 
       7             : #include <key_io.h>
       8             : 
       9             : /* Base58 characters are:
      10             :      "123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"
      11             : 
      12             :   This is:
      13             :   - All numbers except for '0'
      14             :   - All upper-case letters except for 'I' and 'O'
      15             :   - All lower-case letters except for 'l'
      16             : */
      17             : 
      18           0 : BitcoinAddressEntryValidator::BitcoinAddressEntryValidator(QObject *parent) :
      19           0 :     QValidator(parent)
      20           0 : {
      21           0 : }
      22             : 
      23           0 : QValidator::State BitcoinAddressEntryValidator::validate(QString &input, int &pos) const
      24             : {
      25             :     Q_UNUSED(pos);
      26             : 
      27             :     // Empty address is "intermediate" input
      28           0 :     if (input.isEmpty())
      29           0 :         return QValidator::Intermediate;
      30             : 
      31             :     // Correction
      32           0 :     for (int idx = 0; idx < input.size();)
      33             :     {
      34             :         bool removeChar = false;
      35           0 :         QChar ch = input.at(idx);
      36             :         // Corrections made are very conservative on purpose, to avoid
      37             :         // users unexpectedly getting away with typos that would normally
      38             :         // be detected, and thus sending to the wrong address.
      39           0 :         switch(ch.unicode())
      40             :         {
      41             :         // Qt categorizes these as "Other_Format" not "Separator_Space"
      42             :         case 0x200B: // ZERO WIDTH SPACE
      43             :         case 0xFEFF: // ZERO WIDTH NO-BREAK SPACE
      44             :             removeChar = true;
      45           0 :             break;
      46             :         default:
      47             :             break;
      48             :         }
      49             : 
      50             :         // Remove whitespace
      51           0 :         if (ch.isSpace())
      52           0 :             removeChar = true;
      53             : 
      54             :         // To next character
      55           0 :         if (removeChar)
      56           0 :             input.remove(idx, 1);
      57             :         else
      58           0 :             ++idx;
      59           0 :     }
      60             : 
      61             :     // Validation
      62           0 :     QValidator::State state = QValidator::Acceptable;
      63           0 :     for (int idx = 0; idx < input.size(); ++idx)
      64             :     {
      65           0 :         int ch = input.at(idx).unicode();
      66             : 
      67           0 :         if (((ch >= '0' && ch<='9') ||
      68           0 :             (ch >= 'a' && ch<='z') ||
      69           0 :             (ch >= 'A' && ch<='Z')) &&
      70           0 :             ch != 'I' && ch != 'O') // Characters invalid in both Base58 and Bech32
      71             :         {
      72             :             // Alphanumeric and not a 'forbidden' character
      73             :         }
      74             :         else
      75             :         {
      76             :             state = QValidator::Invalid;
      77             :         }
      78             :     }
      79             : 
      80             :     return state;
      81           0 : }
      82             : 
      83           0 : BitcoinAddressCheckValidator::BitcoinAddressCheckValidator(QObject *parent) :
      84           0 :     QValidator(parent)
      85           0 : {
      86           0 : }
      87             : 
      88           0 : QValidator::State BitcoinAddressCheckValidator::validate(QString &input, int &pos) const
      89             : {
      90             :     Q_UNUSED(pos);
      91             :     // Validate the passed Bitcoin address
      92           0 :     if (IsValidDestinationString(input.toStdString())) {
      93           0 :         return QValidator::Acceptable;
      94             :     }
      95             : 
      96           0 :     return QValidator::Invalid;
      97           0 : }

Generated by: LCOV version 1.15