Skip to content

Commit 4a218cd

Browse files
committed
Fix linter by exporting b(l)ech32 internals
1 parent 99b047c commit 4a218cd

File tree

6 files changed

+17
-19
lines changed

6 files changed

+17
-19
lines changed

src/bech32.cpp

+1-6
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
#include <bech32.h>
66

7-
namespace
7+
namespace bech32
88
{
99

1010
typedef std::vector<uint8_t> data;
@@ -138,11 +138,6 @@ data CreateChecksum(const std::string& hrp, const data& values)
138138
return ret;
139139
}
140140

141-
} // namespace
142-
143-
namespace bech32
144-
{
145-
146141
/** Encode a Bech32 string. */
147142
std::string Encode(const std::string& hrp, const data& values) {
148143
data checksum = CreateChecksum(hrp, values);

src/bech32.h

+3
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,9 @@ std::string Encode(const std::string& hrp, const std::vector<uint8_t>& values);
2525
/** Decode a Bech32 string. Returns (hrp, data). Empty hrp means failure. */
2626
std::pair<std::string, std::vector<uint8_t>> Decode(const std::string& str);
2727

28+
/// Exported for testing.
29+
uint32_t PolyMod(const std::vector<uint8_t>& v);
30+
2831
} // namespace bech32
2932

3033
#endif // BITCOIN_BECH32_H

src/blech32.cpp

+1-6
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
* TODO: Update comments
1212
*/
1313

14-
namespace
14+
namespace blech32
1515
{
1616

1717
typedef std::vector<uint8_t> data;
@@ -145,11 +145,6 @@ data CreateChecksum(const std::string& hrp, const data& values)
145145
return ret;
146146
}
147147

148-
} // namespace
149-
150-
namespace blech32
151-
{
152-
153148
/** Encode a Blech32 string. */
154149
std::string Encode(const std::string& hrp, const data& values) {
155150
data checksum = CreateChecksum(hrp, values);

src/blech32.h

+5
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,11 @@ std::string Encode(const std::string& hrp, const std::vector<uint8_t>& values);
2525
/** Decode a Bech32 string. Returns (hrp, data). Empty hrp means failure. */
2626
std::pair<std::string, std::vector<uint8_t>> Decode(const std::string& str);
2727

28+
/// Exported for testing.
29+
uint64_t PolyMod(const std::vector<uint8_t>& v);
30+
/// Exported for testing.
31+
std::vector<uint8_t> CreateChecksum(const std::string& hrp, const std::vector<uint8_t>& values);
32+
2833
} // namespace blech32
2934

3035
#endif // BITCOIN_BLECH32_H

src/test/bech32_tests.cpp

+3-3
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
// Distributed under the MIT software license, see the accompanying
33
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
44

5-
#include <bech32.cpp>
5+
#include <bech32.h>
66
#include <test/test_bitcoin.h>
77

88
#include <boost/test/unit_test.hpp>
@@ -73,13 +73,13 @@ BOOST_AUTO_TEST_CASE(bech32_polymod_sanity)
7373

7474
std::vector<unsigned char> base32;
7575
ConvertBits<8, 5, true>([&](unsigned char c) { base32.push_back(c); }, data.begin(), data.end());
76-
uint64_t plm1 = PolyMod(base32);
76+
uint64_t plm1 = bech32::PolyMod(base32);
7777

7878
// Now add 1023 zeros.
7979
for (auto i = 0; i < 1023; i++) {
8080
base32.push_back(0);
8181
}
82-
uint64_t plm2 = PolyMod(base32);
82+
uint64_t plm2 = bech32::PolyMod(base32);
8383

8484
BOOST_CHECK_EQUAL(plm1, plm2);
8585
}

src/test/blech32_tests.cpp

+4-4
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
// Distributed under the MIT software license, see the accompanying
33
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
44

5-
#include <blech32.cpp>
5+
#include <blech32.h>
66
#include <random.h>
77
#include <utilstrencodings.h>
88
#include <test/test_bitcoin.h>
@@ -18,13 +18,13 @@ BOOST_AUTO_TEST_CASE(blech32_polymod_sanity)
1818

1919
std::vector<unsigned char> base32;
2020
ConvertBits<8, 5, true>([&](unsigned char c) { base32.push_back(c); }, data.begin(), data.end());
21-
uint64_t plm1 = PolyMod(base32);
21+
uint64_t plm1 = blech32::PolyMod(base32);
2222

2323
// Now add 1023 zeros.
2424
for (auto i = 0; i < 1023; i++) {
2525
base32.push_back(0);
2626
}
27-
uint64_t plm2 = PolyMod(base32);
27+
uint64_t plm2 = blech32::PolyMod(base32);
2828

2929
BOOST_CHECK_EQUAL(plm1, plm2);
3030
}
@@ -34,7 +34,7 @@ BOOST_AUTO_TEST_CASE(blech32_checksum)
3434
std::vector<unsigned char> vector{7,2,3,4,5,6,7,8,9,234,123,213,16};
3535
std::vector<unsigned char> b32;
3636
ConvertBits<8, 5, true>([&](unsigned char c) { b32.push_back(c); }, vector.begin(), vector.end());
37-
std::vector<unsigned char> cs = CreateChecksum("lq", b32);
37+
std::vector<unsigned char> cs = blech32::CreateChecksum("lq", b32);
3838

3939
std::vector<unsigned char> expected_cs{22,13,13,5,4,4,23,7,28,21,30,12};
4040
for (size_t i = 0; i < expected_cs.size(); i++) {

0 commit comments

Comments
 (0)