Skip to content

Commit b55ddc3

Browse files
fix widows compile error
1 parent 5653454 commit b55ddc3

File tree

2 files changed

+25
-22
lines changed

2 files changed

+25
-22
lines changed

keychain_lib/include/keychain_lib/keychain_commands.hpp

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,29 @@ class keychain_base
5454
std::string uid_hash;
5555
};
5656

57-
fc::variant open_keyfile(const char* filename);
57+
template <typename char_t>
58+
fc::variant open_keyfile(const char_t* filename)
59+
{
60+
std::ifstream fin = std::ifstream(filename);
61+
if(!fin.is_open())
62+
throw std::runtime_error("Error: cannot open keyfile");
63+
std::array<char, 1024> read_buf;
64+
memset(read_buf.data(), 0x00, read_buf.size());
65+
auto pbuf = read_buf.data();
66+
auto it = read_buf.begin();
67+
size_t read_count = 0;
68+
while(!fin.eof()&&fin.good())
69+
{
70+
fin.getline(pbuf, std::distance(it, read_buf.end()));
71+
pbuf += fin.gcount() - 1;
72+
it += fin.gcount() - 1;
73+
read_count += fin.gcount() - 1;
74+
}
75+
if(!fin.good()&&read_count==0)
76+
throw std::runtime_error("Error: cannot read keyfile");
77+
return fc::json::from_string(std::string(read_buf.begin(), read_buf.end()), fc::json::strict_parser);
78+
}
79+
5880
void create_keyfile(const char* filename, const fc::variant& keyfile_var);
5981
secp256_private_key get_priv_key_from_str(const std::string& str);
6082
fc::sha256 get_hash(const keychain_app::unit_list_t &list);
@@ -111,11 +133,13 @@ struct find_keyfile_by_username
111133
, m_keyfile(keyfile)
112134
{
113135
}
136+
114137
bool operator()(bfs::directory_entry &unit)
115138
{
116139
if (!bfs::is_regular_file(unit.status()))
117140
return false;
118141
const auto &file_path = unit.path().filename();
142+
119143
auto j_keyfile = open_keyfile(file_path.c_str());
120144
auto keyfile = j_keyfile.as<keyfile_format::keyfile_t>();
121145
if(m_keyfile)

keychain_lib/src/keychain_commands.cpp

Lines changed: 0 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -83,27 +83,6 @@ keychain_app::secp256_private_key keychain_app::get_priv_key_from_str(const std:
8383
return *result;
8484
}
8585

86-
fc::variant keychain_app::open_keyfile(const char* filename){
87-
std::ifstream fin = std::ifstream(filename);
88-
if(!fin.is_open())
89-
throw std::runtime_error("Error: cannot open keyfile");
90-
std::array<char, 1024> read_buf;
91-
memset(read_buf.data(), 0x00, read_buf.size());
92-
auto pbuf = read_buf.data();
93-
auto it = read_buf.begin();
94-
size_t read_count = 0;
95-
while(!fin.eof()&&fin.good())
96-
{
97-
fin.getline(pbuf, std::distance(it, read_buf.end()));
98-
pbuf += fin.gcount() - 1;
99-
it += fin.gcount() - 1;
100-
read_count += fin.gcount() - 1;
101-
}
102-
if(!fin.good()&&read_count==0)
103-
throw std::runtime_error("Error: cannot read keyfile");
104-
return fc::json::from_string(std::string(read_buf.begin(), read_buf.end()), fc::json::strict_parser);
105-
}
106-
10786
namespace bfs = keychain_app::bfs;
10887

10988
void keychain_app::create_keyfile(const char* filename, const fc::variant& keyfile_var)

0 commit comments

Comments
 (0)