From a99a23ae9b9e34b11fcd5d4847ad48985713c956 Mon Sep 17 00:00:00 2001 From: Henrik Hautakoski Date: Fri, 10 Mar 2023 10:38:18 +0100 Subject: [PATCH] include/libeosio/base58.hpp: Change decode function to accept vector instead of string. --- include/libeosio/base58.hpp | 4 ++-- src/base58.cpp | 4 ++-- tests/base58/decode.cpp | 6 ++++-- 3 files changed, 8 insertions(+), 6 deletions(-) diff --git a/include/libeosio/base58.hpp b/include/libeosio/base58.hpp index 9a6f37c..6975412 100644 --- a/include/libeosio/base58.hpp +++ b/include/libeosio/base58.hpp @@ -40,8 +40,8 @@ std::string base58_encode(const unsigned char* pbegin, const unsigned char* pend /** * Base58 Decoding functions. */ -bool base58_decode(const char* psz, std::string& out); -bool base58_decode(const std::string& str, std::string& out); +bool base58_decode(const char* psz, std::vector& out); +bool base58_decode(const std::string& str, std::vector& out); /** * Returns true if `ch` is a base58 character, false otherwise. diff --git a/src/base58.cpp b/src/base58.cpp index 6c2589d..998c4c0 100644 --- a/src/base58.cpp +++ b/src/base58.cpp @@ -108,7 +108,7 @@ std::string base58_encode(const std::vector& vch) { return base58_encode(vch.data(), vch.data() + vch.size()); } -bool base58_decode(const char* psz, std::string& out) { +bool base58_decode(const char* psz, std::vector& out) { // Skip leading spaces. while (*psz && is_space(*psz)) psz++; @@ -160,7 +160,7 @@ bool base58_decode(const char* psz, std::string& out) { return true; } -bool base58_decode(const std::string& str, std::string& out) { +bool base58_decode(const std::string& str, std::vector& out) { return base58_decode(str.c_str(), out); } diff --git a/tests/base58/decode.cpp b/tests/base58/decode.cpp index 6193f45..4c7a372 100644 --- a/tests/base58/decode.cpp +++ b/tests/base58/decode.cpp @@ -39,10 +39,12 @@ TEST_CASE("base58_decode") { for(tests::const_iterator it = input.begin(); it != input.end(); it++) { SUBCASE(it->name.c_str()) { - std::string result; + std::vector result; + + std::vector expectedOut(it->expectedOut.begin(), it->expectedOut.end()); CHECK( libeosio::base58_decode(it->in, result) == it->expectedReturn ); - CHECK( result == it->expectedOut ); + CHECK( result == expectedOut ); } } } \ No newline at end of file