mirror of
https://github.com/ElementsProject/elements.git
synced 2026-08-15 12:51:00 +02:00
Fix linter by exporting b(l)ech32 internals
This commit is contained in:
parent
99b047c305
commit
4a218cd0ef
6 changed files with 17 additions and 19 deletions
|
|
@ -4,7 +4,7 @@
|
|||
|
||||
#include <bech32.h>
|
||||
|
||||
namespace
|
||||
namespace bech32
|
||||
{
|
||||
|
||||
typedef std::vector<uint8_t> data;
|
||||
|
|
@ -138,11 +138,6 @@ data CreateChecksum(const std::string& hrp, const data& values)
|
|||
return ret;
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
namespace bech32
|
||||
{
|
||||
|
||||
/** Encode a Bech32 string. */
|
||||
std::string Encode(const std::string& hrp, const data& values) {
|
||||
data checksum = CreateChecksum(hrp, values);
|
||||
|
|
|
|||
|
|
@ -25,6 +25,9 @@ std::string Encode(const std::string& hrp, const std::vector<uint8_t>& values);
|
|||
/** Decode a Bech32 string. Returns (hrp, data). Empty hrp means failure. */
|
||||
std::pair<std::string, std::vector<uint8_t>> Decode(const std::string& str);
|
||||
|
||||
/// Exported for testing.
|
||||
uint32_t PolyMod(const std::vector<uint8_t>& v);
|
||||
|
||||
} // namespace bech32
|
||||
|
||||
#endif // BITCOIN_BECH32_H
|
||||
|
|
|
|||
|
|
@ -11,7 +11,7 @@
|
|||
* TODO: Update comments
|
||||
*/
|
||||
|
||||
namespace
|
||||
namespace blech32
|
||||
{
|
||||
|
||||
typedef std::vector<uint8_t> data;
|
||||
|
|
@ -145,11 +145,6 @@ data CreateChecksum(const std::string& hrp, const data& values)
|
|||
return ret;
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
namespace blech32
|
||||
{
|
||||
|
||||
/** Encode a Blech32 string. */
|
||||
std::string Encode(const std::string& hrp, const data& values) {
|
||||
data checksum = CreateChecksum(hrp, values);
|
||||
|
|
|
|||
|
|
@ -25,6 +25,11 @@ std::string Encode(const std::string& hrp, const std::vector<uint8_t>& values);
|
|||
/** Decode a Bech32 string. Returns (hrp, data). Empty hrp means failure. */
|
||||
std::pair<std::string, std::vector<uint8_t>> Decode(const std::string& str);
|
||||
|
||||
/// Exported for testing.
|
||||
uint64_t PolyMod(const std::vector<uint8_t>& v);
|
||||
/// Exported for testing.
|
||||
std::vector<uint8_t> CreateChecksum(const std::string& hrp, const std::vector<uint8_t>& values);
|
||||
|
||||
} // namespace blech32
|
||||
|
||||
#endif // BITCOIN_BLECH32_H
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@
|
|||
// Distributed under the MIT software license, see the accompanying
|
||||
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
|
||||
|
||||
#include <bech32.cpp>
|
||||
#include <bech32.h>
|
||||
#include <test/test_bitcoin.h>
|
||||
|
||||
#include <boost/test/unit_test.hpp>
|
||||
|
|
@ -73,13 +73,13 @@ BOOST_AUTO_TEST_CASE(bech32_polymod_sanity)
|
|||
|
||||
std::vector<unsigned char> base32;
|
||||
ConvertBits<8, 5, true>([&](unsigned char c) { base32.push_back(c); }, data.begin(), data.end());
|
||||
uint64_t plm1 = PolyMod(base32);
|
||||
uint64_t plm1 = bech32::PolyMod(base32);
|
||||
|
||||
// Now add 1023 zeros.
|
||||
for (auto i = 0; i < 1023; i++) {
|
||||
base32.push_back(0);
|
||||
}
|
||||
uint64_t plm2 = PolyMod(base32);
|
||||
uint64_t plm2 = bech32::PolyMod(base32);
|
||||
|
||||
BOOST_CHECK_EQUAL(plm1, plm2);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@
|
|||
// Distributed under the MIT software license, see the accompanying
|
||||
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
|
||||
|
||||
#include <blech32.cpp>
|
||||
#include <blech32.h>
|
||||
#include <random.h>
|
||||
#include <utilstrencodings.h>
|
||||
#include <test/test_bitcoin.h>
|
||||
|
|
@ -18,13 +18,13 @@ BOOST_AUTO_TEST_CASE(blech32_polymod_sanity)
|
|||
|
||||
std::vector<unsigned char> base32;
|
||||
ConvertBits<8, 5, true>([&](unsigned char c) { base32.push_back(c); }, data.begin(), data.end());
|
||||
uint64_t plm1 = PolyMod(base32);
|
||||
uint64_t plm1 = blech32::PolyMod(base32);
|
||||
|
||||
// Now add 1023 zeros.
|
||||
for (auto i = 0; i < 1023; i++) {
|
||||
base32.push_back(0);
|
||||
}
|
||||
uint64_t plm2 = PolyMod(base32);
|
||||
uint64_t plm2 = blech32::PolyMod(base32);
|
||||
|
||||
BOOST_CHECK_EQUAL(plm1, plm2);
|
||||
}
|
||||
|
|
@ -34,7 +34,7 @@ BOOST_AUTO_TEST_CASE(blech32_checksum)
|
|||
std::vector<unsigned char> vector{7,2,3,4,5,6,7,8,9,234,123,213,16};
|
||||
std::vector<unsigned char> b32;
|
||||
ConvertBits<8, 5, true>([&](unsigned char c) { b32.push_back(c); }, vector.begin(), vector.end());
|
||||
std::vector<unsigned char> cs = CreateChecksum("lq", b32);
|
||||
std::vector<unsigned char> cs = blech32::CreateChecksum("lq", b32);
|
||||
|
||||
std::vector<unsigned char> expected_cs{22,13,13,5,4,4,23,7,28,21,30,12};
|
||||
for (size_t i = 0; i < expected_cs.size(); i++) {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue