mirror of
https://github.com/eosswedenorg/antelope-keygen
synced 2026-06-18 04:00:03 +02:00
core/string.h: move base58 functions to crypto/base58.h
This commit is contained in:
parent
040d3457ef
commit
4a64da310b
5 changed files with 23 additions and 13 deletions
|
|
@ -24,6 +24,7 @@
|
|||
#include <cstddef>
|
||||
#include <cctype>
|
||||
#include <algorithm>
|
||||
#include "../crypto/base58.h"
|
||||
#include "string.h"
|
||||
|
||||
namespace eoskeygen {
|
||||
|
|
@ -88,18 +89,6 @@ std::string& trim(std::string& str) {
|
|||
return ltrim(rtrim(str));
|
||||
}
|
||||
|
||||
static bool _is_base58(char ch) {
|
||||
static std::string alphabet = "123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz";
|
||||
return alphabet.find(ch) != std::string::npos;
|
||||
}
|
||||
|
||||
std::string& base58_strip(std::string &str) {
|
||||
str.erase(std::remove_if(str.begin(), str.end(), [] (std::string::value_type ch)
|
||||
{ return !_is_base58(ch); }
|
||||
), str.end());
|
||||
return str;
|
||||
}
|
||||
|
||||
strlist_t& base58_strip(strlist_t& list) {
|
||||
|
||||
std::transform(list.begin(), list.end(), list.begin(), [](std::string& str){ return base58_strip(str); });
|
||||
|
|
|
|||
|
|
@ -43,7 +43,6 @@ std::string& rtrim(std::string& str);
|
|||
std::string& ltrim(std::string& str);
|
||||
std::string& trim(std::string& str);
|
||||
|
||||
std::string& base58_strip(std::string &str);
|
||||
strlist_t& base58_strip(strlist_t& list);
|
||||
|
||||
strlist_t l33twords(std::string str);
|
||||
|
|
|
|||
|
|
@ -24,6 +24,7 @@
|
|||
*
|
||||
* Based on code from https://github.com/bitcoin/bitcoin/blob/f1e2f2a85962c1664e4e55471061af0eaa798d40/src/base58.cpp
|
||||
*/
|
||||
#include <algorithm>
|
||||
#include <cstddef>
|
||||
#include <cassert>
|
||||
#include "base58.h"
|
||||
|
|
@ -83,4 +84,20 @@ std::string base58_encode(const std::vector<unsigned char>& vch) {
|
|||
return base58_encode(vch.data(), vch.data() + vch.size());
|
||||
}
|
||||
|
||||
bool is_base58(char ch) {
|
||||
for(unsigned int i=0; i < sizeof(charmap); i++) {
|
||||
if (ch == charmap[i]) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
std::string& base58_strip(std::string &str) {
|
||||
str.erase(std::remove_if(str.begin(), str.end(), [] (std::string::value_type ch)
|
||||
{ return is_base58(ch) == false; }
|
||||
), str.end());
|
||||
return str;
|
||||
}
|
||||
|
||||
} // namespace eoskeygen
|
||||
|
|
|
|||
|
|
@ -33,6 +33,10 @@ std::string base58_encode(const std::string& str);
|
|||
std::string base58_encode(const std::vector<unsigned char>& vch);
|
||||
std::string base58_encode(const unsigned char* pbegin, const unsigned char* pend);
|
||||
|
||||
bool is_base58(char ch);
|
||||
|
||||
std::string& base58_strip(std::string& str);
|
||||
|
||||
} //namespace eoskeygen
|
||||
|
||||
#endif /* EOSIOKEYGEN_CRYPTO_BASE58_H */
|
||||
|
|
|
|||
|
|
@ -23,6 +23,7 @@
|
|||
*/
|
||||
#include <string>
|
||||
#include "crypto/ec.h"
|
||||
#include "crypto/base58.h"
|
||||
#include "key_search_helpers.h"
|
||||
#include "key_search.h"
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue