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 <iostream>
|
||||
#include <fstream>
|
||||
#include <string>
|
||||
|
||||
#include "profiler.hpp"
|
||||
|
||||
using namespace std;
|
||||
|
||||
uint8_t key[16];
|
||||
|
||||
string prompt(char separator = '>')
|
||||
{
|
||||
PROFILER_RECORD;
|
||||
@@ -25,13 +28,12 @@ void print_help()
|
||||
{
|
||||
PROFILER_RECORD;
|
||||
// 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()
|
||||
{
|
||||
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";
|
||||
string username = prompt(':');
|
||||
cout << "Password";
|
||||
@@ -50,6 +52,12 @@ void login()
|
||||
// TODO Validate encrypted password
|
||||
}
|
||||
|
||||
void register_user()
|
||||
{
|
||||
PROFILER_RECORD;
|
||||
cout << "Registration is currently unavailable" << endl;
|
||||
}
|
||||
|
||||
bool execute_command(const string &input)
|
||||
{
|
||||
PROFILER_RECORD;
|
||||
@@ -62,19 +70,41 @@ bool execute_command(const string &input)
|
||||
{
|
||||
login();
|
||||
}
|
||||
else if (input == "register")
|
||||
{
|
||||
register_user();
|
||||
}
|
||||
else if (input == "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;
|
||||
}
|
||||
|
||||
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) {
|
||||
PROFILER_RECORD;
|
||||
load_key();
|
||||
cout << "Welcome to the Secutech customer portal." << endl;
|
||||
cout << "How can we help you today? (type 'help' for help)" << endl;
|
||||
string input;
|
||||
|
||||
14
profiler.cpp
14
profiler.cpp
@@ -1,11 +1,9 @@
|
||||
#include "profiler.hpp"
|
||||
|
||||
#include <iostream>
|
||||
#include <sstream>
|
||||
#include <iomanip>
|
||||
|
||||
using namespace std;
|
||||
using std::string;
|
||||
|
||||
Profiler profiler;
|
||||
|
||||
@@ -19,9 +17,7 @@ void Profiler::reset()
|
||||
calls.clear();
|
||||
}
|
||||
|
||||
bool Profiler::command_line(const string &input)
|
||||
{
|
||||
if (input == "profiler_print")
|
||||
void Profiler::print() const
|
||||
{
|
||||
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;
|
||||
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;
|
||||
void record_function_call(const char *function_name);
|
||||
void reset();
|
||||
bool command_line(const std::string &input);
|
||||
void print() const;
|
||||
};
|
||||
|
||||
#define PROFILER_RECORD profiler.record_function_call(__func__)
|
||||
|
||||
Reference in New Issue
Block a user