mirror of
https://github.com/eosswedenorg/antelope-keygen
synced 2026-06-16 03:44:56 +02:00
refactor struct key_search_result from src/key_search_helpers.h to include/eoskeygen/key_search.h
This commit is contained in:
parent
8035e3233c
commit
a417390bb7
5 changed files with 36 additions and 32 deletions
|
|
@ -31,6 +31,13 @@ namespace eoskeygen {
|
|||
|
||||
class KeySearch
|
||||
{
|
||||
public :
|
||||
|
||||
struct result {
|
||||
size_t pos; // position where the word was found.
|
||||
size_t len; // the length of the word.
|
||||
};
|
||||
|
||||
public :
|
||||
// Add a word to search for.
|
||||
void addWord(const std::string& str);
|
||||
|
|
@ -56,6 +63,10 @@ public :
|
|||
|
||||
protected :
|
||||
|
||||
// Check if any word in <word_list> appears in <key>'s public key.
|
||||
// returns true if a word was found (stored in <result>), false otherwise.
|
||||
bool _contains_word(const struct ec_keypair* key, struct result& result);
|
||||
|
||||
#ifdef HAVE_THREADS
|
||||
void _thr_proc();
|
||||
|
||||
|
|
|
|||
|
|
@ -23,6 +23,7 @@
|
|||
*/
|
||||
#include <string>
|
||||
#include <eoskeygen/crypto/ec.h>
|
||||
#include <eoskeygen/crypto/WIF.h>
|
||||
#include <eoskeygen/key_search.h>
|
||||
#include "key_search_helpers.h"
|
||||
|
||||
|
|
@ -63,9 +64,9 @@ void KeySearch::_search_linear(size_t n) {
|
|||
struct ec_keypair pair;
|
||||
|
||||
while (count < n) {
|
||||
struct key_result res;
|
||||
struct result res;
|
||||
ec_generate_key(&pair);
|
||||
if (key_contains_word(&pair, m_words, &res)) {
|
||||
if (_contains_word(&pair, res)) {
|
||||
key_search_result(&pair, &res, m_dict);
|
||||
count++;
|
||||
}
|
||||
|
|
@ -85,4 +86,21 @@ void KeySearch::find(size_t num_results) {
|
|||
_search_linear(num_results);
|
||||
}
|
||||
|
||||
bool KeySearch::_contains_word(const struct ec_keypair* key, struct result& result) {
|
||||
|
||||
// skip first 3 chars, as those are always "EOS"
|
||||
std::string pubstr = wif_pub_encode(key->pub).substr(3);
|
||||
strtolower(pubstr);
|
||||
|
||||
for(auto const& w: m_words) {
|
||||
size_t p = pubstr.find(w);
|
||||
if (p != std::string::npos) {
|
||||
result.pos = p + 3;
|
||||
result.len = w.length();
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
} // namespace eoskeygen
|
||||
|
|
|
|||
|
|
@ -37,7 +37,7 @@ static size_t highlight(console::Color color, const std::string& str, size_t pos
|
|||
return len;
|
||||
}
|
||||
|
||||
void key_search_result(const struct ec_keypair* key, const struct key_result* result, const Dictionary& dict) {
|
||||
void key_search_result(const struct ec_keypair* key, const struct KeySearch::result* result, const Dictionary& dict) {
|
||||
|
||||
std::string pub = wif_pub_encode(key->pub);
|
||||
Dictionary::search_result_t dict_res = dict.search(pub);
|
||||
|
|
@ -66,21 +66,4 @@ void key_search_result(const struct ec_keypair* key, const struct key_result* re
|
|||
<< "Private: " << wif_priv_encode(key->secret) << std::endl;
|
||||
}
|
||||
|
||||
bool key_contains_word(const struct ec_keypair* key, const strlist_t& word_list, struct key_result *result) {
|
||||
|
||||
// skip first 3 chars, as those are always "EOS"
|
||||
std::string pubstr = wif_pub_encode(key->pub).substr(3);
|
||||
strtolower(pubstr);
|
||||
|
||||
for(auto const& w: word_list) {
|
||||
size_t p = pubstr.find(w);
|
||||
if (p != std::string::npos) {
|
||||
result->pos = p + 3;
|
||||
result->len = w.length();
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
} // namespace eoskeygen
|
||||
|
|
|
|||
|
|
@ -26,21 +26,13 @@
|
|||
|
||||
#include <eoskeygen/core/string.h>
|
||||
#include <eoskeygen/crypto/types.h>
|
||||
#include <eoskeygen/key_search.h>
|
||||
|
||||
namespace eoskeygen {
|
||||
|
||||
class Dictionary;
|
||||
|
||||
struct key_result {
|
||||
size_t pos; // position where the word was found.
|
||||
size_t len; // the length of the word.
|
||||
};
|
||||
|
||||
void key_search_result(const struct ec_keypair* key, const struct key_result* result, const Dictionary& dict);
|
||||
|
||||
// Check if any word in <word_list> appears in <key>'s public key.
|
||||
// returns true if a word was found (stored in <result>), false otherwise.
|
||||
bool key_contains_word(const struct ec_keypair* key, const strlist_t& word_list, struct key_result *result);
|
||||
void key_search_result(const struct ec_keypair* key, const struct KeySearch::result* result, const Dictionary& dict);
|
||||
|
||||
} // namespace eoskeygen
|
||||
|
||||
|
|
|
|||
|
|
@ -46,10 +46,10 @@ void KeySearch::_thr_proc() {
|
|||
struct ec_keypair pair;
|
||||
|
||||
while (g_count < g_max) {
|
||||
struct key_result res;
|
||||
struct result res;
|
||||
|
||||
ec_generate_key(&pair);
|
||||
if (key_contains_word(&pair, m_words, &res)) {
|
||||
if (_contains_word(&pair, res)) {
|
||||
|
||||
// Guard output with mutex, so we don't get
|
||||
// interrupted mid write and can write to g_count safely.
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue