Skip to content

Commit e31c0e1

Browse files
committed
strencodings:add ChallengeToStdString
1 parent c5b0c10 commit e31c0e1

File tree

2 files changed

+24
-0
lines changed

2 files changed

+24
-0
lines changed

src/util/strencodings.cpp

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -383,6 +383,25 @@ std::string Capitalize(std::string str)
383383
return str;
384384
}
385385

386+
std::string ChallengeToStdString(const std::vector<uint8_t>& v)
387+
{
388+
std::string result;
389+
result.reserve(v.size() * 2);
390+
391+
static constexpr char hex[] = "0123456789ABCDEF";
392+
393+
for (uint8_t c : v)
394+
{
395+
result.push_back(hex[c / 16]);
396+
result.push_back(hex[c % 16]);
397+
}
398+
if (IsHex(result)) {
399+
return result;
400+
} else {
401+
return "Invalid signet_challenge";
402+
}
403+
}
404+
386405
std::optional<uint64_t> ParseByteUnits(std::string_view str, ByteUnit default_multiplier)
387406
{
388407
if (str.empty()) {

src/util/strencodings.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -311,6 +311,11 @@ std::string ToUpper(std::string_view str);
311311
*/
312312
std::string Capitalize(std::string str);
313313

314+
/**
315+
* Converts a signet_challenge to std::string
316+
*/
317+
std::string ChallengeToStdString(const std::vector<uint8_t>& v);
318+
314319
/**
315320
* Parse a string with suffix unit [k|K|m|M|g|G|t|T].
316321
* Must be a whole integer, fractions not allowed (0.5t), no whitespace or +-

0 commit comments

Comments
 (0)