LCOV - code coverage report
Current view: top level - src/util - bip32.cpp (source / functions) Hit Total Coverage
Test: coverage.lcov Lines: 44 45 97.8 %
Date: 2022-04-21 14:51:19 Functions: 3 3 100.0 %
Legend: Modified by patch:
Lines: hit not hit | Branches: + taken - not taken # not executed

Not modified by patch:
Lines: hit not hit | Branches: + taken - not taken # not executed
Branches: 17 18 94.4 %

           Branch data     Line data    Source code
#       1                 :            : // Copyright (c) 2019-2020 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 <sstream>
#       6                 :            : #include <stdio.h>
#       7                 :            : #include <tinyformat.h>
#       8                 :            : #include <util/bip32.h>
#       9                 :            : #include <util/strencodings.h>
#      10                 :            : 
#      11                 :            : 
#      12                 :            : bool ParseHDKeypath(const std::string& keypath_str, std::vector<uint32_t>& keypath)
#      13                 :         46 : {
#      14                 :         46 :     std::stringstream ss(keypath_str);
#      15                 :         46 :     std::string item;
#      16                 :         46 :     bool first = true;
#      17         [ +  + ]:        213 :     while (std::getline(ss, item, '/')) {
#      18         [ +  + ]:        190 :         if (item.compare("m") == 0) {
#      19         [ +  - ]:         20 :             if (first) {
#      20                 :         20 :                 first = false;
#      21                 :         20 :                 continue;
#      22                 :         20 :             }
#      23                 :          0 :             return false;
#      24                 :         20 :         }
#      25                 :            :         // Finds whether it is hardened
#      26                 :        170 :         uint32_t path = 0;
#      27                 :        170 :         size_t pos = item.find("'");
#      28         [ +  + ]:        170 :         if (pos != std::string::npos) {
#      29                 :            :             // The hardened tick can only be in the last index of the string
#      30         [ +  + ]:         13 :             if (pos != item.size() - 1) {
#      31                 :          3 :                 return false;
#      32                 :          3 :             }
#      33                 :         10 :             path |= 0x80000000;
#      34                 :         10 :             item = item.substr(0, item.size() - 1); // Drop the last character which is the hardened tick
#      35                 :         10 :         }
#      36                 :            : 
#      37                 :            :         // Ensure this is only numbers
#      38         [ +  + ]:        167 :         if (item.find_first_not_of( "0123456789" ) != std::string::npos) {
#      39                 :         11 :             return false;
#      40                 :         11 :         }
#      41                 :        156 :         uint32_t number;
#      42         [ +  + ]:        156 :         if (!ParseUInt32(item, &number)) {
#      43                 :          9 :             return false;
#      44                 :          9 :         }
#      45                 :        147 :         path |= number;
#      46                 :            : 
#      47                 :        147 :         keypath.push_back(path);
#      48                 :        147 :         first = false;
#      49                 :        147 :     }
#      50                 :         23 :     return true;
#      51                 :         46 : }
#      52                 :            : 
#      53                 :            : std::string FormatHDKeypath(const std::vector<uint32_t>& path)
#      54                 :     300415 : {
#      55                 :     300415 :     std::string ret;
#      56         [ +  + ]:     747364 :     for (auto i : path) {
#      57                 :     747364 :         ret += strprintf("/%i", (i << 1) >> 1);
#      58         [ +  + ]:     747364 :         if (i >> 31) ret += '\'';
#      59                 :     747364 :     }
#      60                 :     300415 :     return ret;
#      61                 :     300415 : }
#      62                 :            : 
#      63                 :            : std::string WriteHDKeypath(const std::vector<uint32_t>& keypath)
#      64                 :       2902 : {
#      65                 :       2902 :     return "m" + FormatHDKeypath(keypath);
#      66                 :       2902 : }

Generated by: LCOV version 0-eol-96201-ge66f56f4af6a