Move profiler command line to main, move key to external file, add register function

This commit is contained in:
2019-07-02 15:31:40 +02:00
parent 5452021ab7
commit bcb7f00f68
4 changed files with 41 additions and 22 deletions

1
key.txt Normal file
View File

@@ -0,0 +1 @@
A0 7C 3D 99 FA 00 02 46 97 33 73 50 31 7C D3 DC

View File

@@ -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;

View File

@@ -1,11 +1,9 @@
#include "profiler.hpp"
#include <iostream>
#include <sstream>
#include <iomanip>
using namespace std;
using std::string;
Profiler profiler;
@@ -19,22 +17,12 @@ void Profiler::reset()
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++)
{
ostringstream out;
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;
}

View File

@@ -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__)