keycodes work, need some documentation

This commit is contained in:
Kevin Darby committed 2019-06-06 16:40:32 -04:00
1 parent 0da6b2cc3e
commit 8a1d49733e
5 files changed
+31 -10

No files matched your search

+19 -2
View File
@@ -16,6 +16,7 @@
#include <boost/date_time/local_time/local_time.hpp>
#include <boost/tokenizer.hpp>
#include <boost/date_time/gregorian/gregorian.hpp>
#include <boost/algorithm/string/replace.hpp>
#include <google/protobuf/text_format.h>
#include <google/protobuf/io/zero_copy_stream_impl.h>
#include <google/protobuf/timestamp.pb.h>
@@ -147,6 +148,17 @@ void write_keycode(const std::string& users, const std::string& expiration, bts:
kc.set_generation_time(now);
}
void eraseAllSubStr(std::string& mainStr, const std::string& toErase)
{
size_t pos = std::string::npos;
// Search for the substring in string in a loop untill nothing is found
while ((pos = mainStr.find(toErase) )!= std::string::npos)
{
// If found then erase it from string
mainStr.erase(pos, toErase.length());
}
}
int encrypt(const std::string& keyfile, const std::string& pass, const std::string& users, const std::string& expiration)
{
@@ -176,7 +188,12 @@ int encrypt(const std::string& keyfile, const std::string& pass, const std::stri
//int ret = openssl::RSA_private_encrypt(sz-1, pay, &buffer[0], key->pkey.rsa, RSA_PKCS1_PADDING);
EncryptedKeyCode ekc;
ekc.set_keycode(encrypted.str());
auto kcstr = encrypted.str();
eraseAllSubStr(kcstr,"-----BEGIN BTS-----\n");
eraseAllSubStr(kcstr, "\n-----END BTS-----\n");
kcstr.erase( std::remove(kcstr.begin(), kcstr.end(), '\n'), kcstr.end() );
//kcstr = boost::replace_all_copy<string>(kcstr, "\n", "\\n");
ekc.set_keycode(kcstr);
std::string pb;
google::protobuf::TextFormat::PrintToString(ekc, &pb);
std::cout << std::endl << std::endl;
@@ -217,7 +234,7 @@ int decode(const std::vector<std::string>& args)
std::fstream fs(source);
//google::protobuf::io::IstreamInputStream pay_stream(&fs);
//google::protobuf::TextFormat::Parse(&pay_stream, &ekc);
std::string str((std::istreambuf_iterator<char>(fs)), std::istreambuf_iterator<char>());
std::string str((std::istreambuf_iterator<char>(fs)), std::istreambuf_iterator<char>());
config::internal::initialize_for_test(str);
ekc = config::get<bts::config::EncryptedKeyCode>();