mirror of
https://github.com/eosswedenorg/antelope-keygen
synced 2026-06-19 04:10:03 +02:00
Importing libeoskeygen as "common" module in this repo (the amount of git repos is too damn high!)
This commit is contained in:
parent
f181bddc4f
commit
654a53698f
19 changed files with 1143 additions and 0 deletions
30
common/include/eoskeygen/config.h
Normal file
30
common/include/eoskeygen/config.h
Normal file
|
|
@ -0,0 +1,30 @@
|
|||
/**
|
||||
* MIT License
|
||||
*
|
||||
* Copyright (c) 2019-2020 EOS Sw/eden
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in all
|
||||
* copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* SOFTWARE.
|
||||
*/
|
||||
#ifndef EOSIOKEYGEN_COMMON_CONFIG_H
|
||||
#define EOSIOKEYGEN_COMMON_CONFIG_H
|
||||
|
||||
// Defined if we have thread support.
|
||||
#define EOSIOKEYGEN_HAVE_THREADS
|
||||
|
||||
#endif /* EOSIOKEYGEN_COMMON_CONFIG_H */
|
||||
72
common/include/eoskeygen/core/dictionary.h
Normal file
72
common/include/eoskeygen/core/dictionary.h
Normal file
|
|
@ -0,0 +1,72 @@
|
|||
/**
|
||||
* MIT License
|
||||
*
|
||||
* Copyright (c) 2019-2020 EOS Sw/eden
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in all
|
||||
* copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* SOFTWARE.
|
||||
*/
|
||||
#ifndef EOSIOKEYGEN_COMMON_CORE_DICTIONARY_H
|
||||
#define EOSIOKEYGEN_COMMON_CORE_DICTIONARY_H
|
||||
|
||||
#include <string>
|
||||
#include <map>
|
||||
#include <set>
|
||||
|
||||
namespace eoskeygen {
|
||||
|
||||
class Dictionary
|
||||
{
|
||||
public :
|
||||
// Map that contains position and length for substrings.
|
||||
//
|
||||
// key = position in the search string.
|
||||
// value = length of the word from this position.
|
||||
typedef std::map< size_t, size_t > search_result_t;
|
||||
|
||||
public :
|
||||
|
||||
// Load words from file.
|
||||
bool loadFromFile(const std::string& filename);
|
||||
|
||||
// Add a word to the dictionary.
|
||||
void add(const std::string& word);
|
||||
|
||||
// Add words from another dictionary.
|
||||
void add(const Dictionary& dictionary);
|
||||
|
||||
// Clear all words from the dictionary.
|
||||
void clear();
|
||||
|
||||
// Returns true if word exists in the dictionary.
|
||||
bool contains(const std::string& word) const;
|
||||
|
||||
// Searches the subject for words defined in the dictionary.
|
||||
// Returns a search_result_t with the words found in subject.
|
||||
// See search_result_t for more details.
|
||||
search_result_t search(const std::string& subject) const;
|
||||
|
||||
protected :
|
||||
|
||||
// Words in the dictionary.
|
||||
std::set<std::string> m_words;
|
||||
};
|
||||
|
||||
} // namespace eoskeygen
|
||||
|
||||
#endif /* EOSIOKEYGEN_COMMON_CORE_DICTIONARY_H */
|
||||
35
common/include/eoskeygen/core/file.h
Normal file
35
common/include/eoskeygen/core/file.h
Normal file
|
|
@ -0,0 +1,35 @@
|
|||
/**
|
||||
* MIT License
|
||||
*
|
||||
* Copyright (c) 2019-2020 EOS Sw/eden
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in all
|
||||
* copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* SOFTWARE.
|
||||
*/
|
||||
#ifndef EOSIOKEYGEN_COMMON_CORE_FILE_H
|
||||
#define EOSIOKEYGEN_COMMON_CORE_FILE_H
|
||||
|
||||
#include <eoskeygen/core/strlist.h>
|
||||
|
||||
namespace eoskeygen {
|
||||
|
||||
bool readLines(const std::string& filename, strlist_t& lines);
|
||||
|
||||
} // namespace
|
||||
|
||||
#endif /* EOSIOKEYGEN_COMMON_CORE_FILE_H */
|
||||
36
common/include/eoskeygen/core/leet.h
Normal file
36
common/include/eoskeygen/core/leet.h
Normal file
|
|
@ -0,0 +1,36 @@
|
|||
/**
|
||||
* MIT License
|
||||
*
|
||||
* Copyright (c) 2019-2020 EOS Sw/eden
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in all
|
||||
* copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* SOFTWARE.
|
||||
*/
|
||||
#ifndef EOSIOKEYGEN_COMMON_CORE_LEET_H
|
||||
#define EOSIOKEYGEN_COMMON_CORE_LEET_H
|
||||
|
||||
#include <string>
|
||||
#include <eoskeygen/core/strlist.h>
|
||||
|
||||
namespace eoskeygen {
|
||||
|
||||
strlist_t l33twords(std::string str);
|
||||
|
||||
} // namespace eoskeygen
|
||||
|
||||
#endif /* EOSIOKEYGEN_COMMON_CORE_LEET_H */
|
||||
41
common/include/eoskeygen/core/string.h
Normal file
41
common/include/eoskeygen/core/string.h
Normal file
|
|
@ -0,0 +1,41 @@
|
|||
/**
|
||||
* MIT License
|
||||
*
|
||||
* Copyright (c) 2019-2020 EOS Sw/eden
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in all
|
||||
* copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* SOFTWARE.
|
||||
*/
|
||||
#ifndef EOSIOKEYGEN_COMMON_CORE_STRING_H
|
||||
#define EOSIOKEYGEN_COMMON_CORE_STRING_H
|
||||
|
||||
#include <vector>
|
||||
#include <string>
|
||||
#include <eoskeygen/core/strlist.h>
|
||||
|
||||
namespace eoskeygen {
|
||||
|
||||
std::string& strtolower(std::string& str);
|
||||
|
||||
std::string& rtrim(std::string& str);
|
||||
std::string& ltrim(std::string& str);
|
||||
std::string& trim(std::string& str);
|
||||
|
||||
} // namespace eoskeygen
|
||||
|
||||
#endif /* EOSIOKEYGEN_COMMON_CORE_STRING_H */
|
||||
50
common/include/eoskeygen/core/strlist.h
Normal file
50
common/include/eoskeygen/core/strlist.h
Normal file
|
|
@ -0,0 +1,50 @@
|
|||
/**
|
||||
* MIT License
|
||||
*
|
||||
* Copyright (c) 2019-2020 EOS Sw/eden
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in all
|
||||
* copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* SOFTWARE.
|
||||
*/
|
||||
#ifndef EOSIOKEYGEN_COMMON_CORE_STRLIST_H
|
||||
#define EOSIOKEYGEN_COMMON_CORE_STRLIST_H
|
||||
|
||||
#include <vector>
|
||||
#include <string>
|
||||
|
||||
namespace eoskeygen {
|
||||
|
||||
typedef std::vector<std::string> strlist_t;
|
||||
|
||||
typedef std::string& (*strlist_stripfunc_t)(std::string& str);
|
||||
|
||||
namespace strlist {
|
||||
|
||||
strlist_t splitw(const std::string& str, const std::string& delim = ",");
|
||||
|
||||
strlist_t split(const std::string& str, const std::string& delim);
|
||||
|
||||
std::string join(const strlist_t& list, const std::string& delim);
|
||||
|
||||
strlist_t& strip(strlist_t& list, strlist_stripfunc_t fn);
|
||||
|
||||
} // namespace strlist
|
||||
|
||||
} // namespace eoskeygen
|
||||
|
||||
#endif /* EOSIOKEYGEN_COMMON_CORE_STRLIST_H */
|
||||
104
common/include/eoskeygen/key_search.h
Normal file
104
common/include/eoskeygen/key_search.h
Normal file
|
|
@ -0,0 +1,104 @@
|
|||
/**
|
||||
* MIT License
|
||||
*
|
||||
* Copyright (c) 2019-2020 EOS Sw/eden
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in all
|
||||
* copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* SOFTWARE.
|
||||
*/
|
||||
#ifndef EOSIOKEYGEN_COMMON_KEY_SEARCH_H
|
||||
#define EOSIOKEYGEN_COMMON_KEY_SEARCH_H
|
||||
|
||||
#include <stdint.h>
|
||||
#include <string>
|
||||
#include <eoskeygen/config.h>
|
||||
#include <eoskeygen/core/dictionary.h>
|
||||
#include <eoskeygen/core/strlist.h>
|
||||
|
||||
namespace eoskeygen {
|
||||
|
||||
class IKeySearchResult;
|
||||
|
||||
class KeySearch
|
||||
{
|
||||
public :
|
||||
|
||||
struct result {
|
||||
size_t pos; // position where the word was found.
|
||||
size_t len; // the length of the word.
|
||||
};
|
||||
|
||||
public :
|
||||
KeySearch();
|
||||
|
||||
// Add a word to search for.
|
||||
void addWord(const std::string& str);
|
||||
|
||||
// Add a list of words to search for.
|
||||
void addList(const strlist_t& list);
|
||||
|
||||
// get the list of words to search for.
|
||||
const strlist_t& getList();
|
||||
|
||||
// Clears the search list.
|
||||
void clear();
|
||||
|
||||
// Set callback for search result.
|
||||
void setCallback(IKeySearchResult* callback);
|
||||
|
||||
#ifdef EOSIOKEYGEN_HAVE_THREADS
|
||||
// Returns the maximum number of threads
|
||||
// reported by the operating system.
|
||||
static size_t max_threads();
|
||||
|
||||
// Set the number of threads to use while searching.
|
||||
void setThreadCount(size_t num);
|
||||
#endif /* EOSIOKEYGEN_HAVE_THREADS */
|
||||
|
||||
// Perform a search.
|
||||
void find(size_t num_results);
|
||||
|
||||
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 libeosio::ec_keypair* key, struct result& result);
|
||||
|
||||
#ifdef EOSIOKEYGEN_HAVE_THREADS
|
||||
void _thr_proc();
|
||||
|
||||
void _search_mt(size_t n);
|
||||
#endif /* EOSIOKEYGEN_HAVE_THREADS */
|
||||
|
||||
void _search_linear(size_t n);
|
||||
|
||||
protected :
|
||||
// List of words to search for.
|
||||
strlist_t m_words;
|
||||
|
||||
#ifdef EOSIOKEYGEN_HAVE_THREADS
|
||||
// Number of threads to use.
|
||||
size_t m_threads;
|
||||
#endif /* EOSIOKEYGEN_HAVE_THREADS */
|
||||
|
||||
IKeySearchResult* m_callback;
|
||||
};
|
||||
|
||||
} // namespace eoskeygen
|
||||
|
||||
#endif /* EOSIOKEYGEN_COMMON_KEY_SEARCH_H */
|
||||
40
common/include/eoskeygen/key_search_result.h
Normal file
40
common/include/eoskeygen/key_search_result.h
Normal file
|
|
@ -0,0 +1,40 @@
|
|||
/**
|
||||
* MIT License
|
||||
*
|
||||
* Copyright (c) 2019-2020 EOS Sw/eden
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in all
|
||||
* copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* SOFTWARE.
|
||||
*/
|
||||
#ifndef EOSIOKEYGEN_COMMON_KEY_SEARCH_RESULT_H
|
||||
#define EOSIOKEYGEN_COMMON_KEY_SEARCH_RESULT_H
|
||||
|
||||
#include <eoskeygen/key_search.h>
|
||||
|
||||
namespace eoskeygen {
|
||||
|
||||
class IKeySearchResult
|
||||
{
|
||||
public :
|
||||
|
||||
virtual void onResult(const struct libeosio::ec_keypair* key, const struct KeySearch::result& result) = 0;
|
||||
};
|
||||
|
||||
} // namespace eoskeygen
|
||||
|
||||
#endif /* EOSIOKEYGEN_COMMON_KEY_SEARCH_RESULT_H */
|
||||
Loading…
Add table
Add a link
Reference in a new issue