Move profiler command line to main, move key to external file, add register function
This commit is contained in:
38
main.cpp
38
main.cpp
@@ -1,12 +1,15 @@
|
|||||||
#include "aes.hpp"
|
#include "aes.hpp"
|
||||||
|
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
|
#include <fstream>
|
||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
#include "profiler.hpp"
|
#include "profiler.hpp"
|
||||||
|
|
||||||
using namespace std;
|
using namespace std;
|
||||||
|
|
||||||
|
uint8_t key[16];
|
||||||
|
|
||||||
string prompt(char separator = '>')
|
string prompt(char separator = '>')
|
||||||
{
|
{
|
||||||
PROFILER_RECORD;
|
PROFILER_RECORD;
|
||||||
@@ -25,13 +28,12 @@ void print_help()
|
|||||||
{
|
{
|
||||||
PROFILER_RECORD;
|
PROFILER_RECORD;
|
||||||
// TODO Verify whether there are more/less commands
|
// TODO Verify whether there are more/less commands
|
||||||
cout << "The following commands are available: help, login, exit" << endl;
|
cout << "The following commands are available: help, login, register, exit" << endl;
|
||||||
}
|
}
|
||||||
|
|
||||||
void login()
|
void login()
|
||||||
{
|
{
|
||||||
PROFILER_RECORD;
|
PROFILER_RECORD;
|
||||||
uint8_t key[16] = {0xA0,0x7C,0x3D,0x99,0xFA,0x00,0x02,0x46,0x97,0x33,0x73,0x50,0x31,0x7C,0xD3,0xDC}; // TODO Load me from a file
|
|
||||||
cout << "Username";
|
cout << "Username";
|
||||||
string username = prompt(':');
|
string username = prompt(':');
|
||||||
cout << "Password";
|
cout << "Password";
|
||||||
@@ -50,6 +52,12 @@ void login()
|
|||||||
// TODO Validate encrypted password
|
// TODO Validate encrypted password
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void register_user()
|
||||||
|
{
|
||||||
|
PROFILER_RECORD;
|
||||||
|
cout << "Registration is currently unavailable" << endl;
|
||||||
|
}
|
||||||
|
|
||||||
bool execute_command(const string &input)
|
bool execute_command(const string &input)
|
||||||
{
|
{
|
||||||
PROFILER_RECORD;
|
PROFILER_RECORD;
|
||||||
@@ -62,19 +70,41 @@ bool execute_command(const string &input)
|
|||||||
{
|
{
|
||||||
login();
|
login();
|
||||||
}
|
}
|
||||||
|
else if (input == "register")
|
||||||
|
{
|
||||||
|
register_user();
|
||||||
|
}
|
||||||
else if (input == "help")
|
else if (input == "help")
|
||||||
{
|
{
|
||||||
print_help();
|
print_help();
|
||||||
}
|
}
|
||||||
else if (!profiler.command_line(input))
|
else if (input == "profiler_print")
|
||||||
{
|
{
|
||||||
cout << "Invalid command '" << input << "'" << endl;
|
profiler.print();
|
||||||
}
|
}
|
||||||
|
else if (input == "profiler_reset")
|
||||||
|
{
|
||||||
|
profiler.reset();
|
||||||
|
}
|
||||||
|
cout << "Invalid command '" << input << "'" << endl;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void load_key()
|
||||||
|
{
|
||||||
|
PROFILER_RECORD;
|
||||||
|
ifstream file("key.txt");
|
||||||
|
string line;
|
||||||
|
getline(file, line);
|
||||||
|
for (int i = 0;i < 16;i++)
|
||||||
|
{
|
||||||
|
key[i] = stoi(line.substr(3 * i, 2), 0, 16);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
int main(int argc, char **argv) {
|
int main(int argc, char **argv) {
|
||||||
PROFILER_RECORD;
|
PROFILER_RECORD;
|
||||||
|
load_key();
|
||||||
cout << "Welcome to the Secutech customer portal." << endl;
|
cout << "Welcome to the Secutech customer portal." << endl;
|
||||||
cout << "How can we help you today? (type 'help' for help)" << endl;
|
cout << "How can we help you today? (type 'help' for help)" << endl;
|
||||||
string input;
|
string input;
|
||||||
|
|||||||
14
profiler.cpp
14
profiler.cpp
@@ -1,11 +1,9 @@
|
|||||||
#include "profiler.hpp"
|
#include "profiler.hpp"
|
||||||
|
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <sstream>
|
|
||||||
#include <iomanip>
|
#include <iomanip>
|
||||||
|
|
||||||
using namespace std;
|
using namespace std;
|
||||||
using std::string;
|
|
||||||
|
|
||||||
Profiler profiler;
|
Profiler profiler;
|
||||||
|
|
||||||
@@ -19,9 +17,7 @@ void Profiler::reset()
|
|||||||
calls.clear();
|
calls.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Profiler::command_line(const string &input)
|
void Profiler::print() const
|
||||||
{
|
|
||||||
if (input == "profiler_print")
|
|
||||||
{
|
{
|
||||||
for (auto it = this->calls.begin();it != this->calls.end();it++)
|
for (auto it = this->calls.begin();it != this->calls.end();it++)
|
||||||
{
|
{
|
||||||
@@ -29,12 +25,4 @@ bool Profiler::command_line(const string &input)
|
|||||||
out << left << setw(25) << it->first << right << setw(5) << it->second;
|
out << left << setw(25) << it->first << right << setw(5) << it->second;
|
||||||
cout << out.str() << endl;
|
cout << out.str() << endl;
|
||||||
}
|
}
|
||||||
return true;
|
|
||||||
}
|
|
||||||
if (input == "profiler_reset")
|
|
||||||
{
|
|
||||||
this->reset();
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -10,7 +10,7 @@ public:
|
|||||||
std::map<std::string, uint32_t> calls;
|
std::map<std::string, uint32_t> calls;
|
||||||
void record_function_call(const char *function_name);
|
void record_function_call(const char *function_name);
|
||||||
void reset();
|
void reset();
|
||||||
bool command_line(const std::string &input);
|
void print() const;
|
||||||
};
|
};
|
||||||
|
|
||||||
#define PROFILER_RECORD profiler.record_function_call(__func__)
|
#define PROFILER_RECORD profiler.record_function_call(__func__)
|
||||||
|
|||||||
Reference in New Issue
Block a user