♻️ refactor
parent
9c4fe4a26e
commit
8438ec3225
|
@ -169,27 +169,6 @@ public:
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
// Most tests will use a virtual clock. But just as a smoke test,
|
|
||||||
// make sure real time is realistic.
|
|
||||||
|
|
||||||
int check_real_time () {
|
|
||||||
const auto seconds_since_epoch = get_seconds_since_epoch ();
|
|
||||||
|
|
||||||
const auto time_of_writing = 1610844872;
|
|
||||||
if (seconds_since_epoch < time_of_writing) {
|
|
||||||
cerr << "Error: Real time is in the past." << endl;
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
const int64_t about_100_years = (int64_t)100 * 365 * 86400;
|
|
||||||
if (seconds_since_epoch > time_of_writing + about_100_years) {
|
|
||||||
cerr << "Error: Real time is in the far future." << endl;
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
int check_base64 () {
|
int check_base64 () {
|
||||||
// I assume that char is 8 bits
|
// I assume that char is 8 bits
|
||||||
// char is C++ nonsense inherited from C nonsense
|
// char is C++ nonsense inherited from C nonsense
|
||||||
|
@ -231,7 +210,7 @@ int happy_path () {
|
||||||
SigningKey root_key;
|
SigningKey root_key;
|
||||||
cerr << "Root pub key " << root_key.pub_to_base64 () << endl;
|
cerr << "Root pub key " << root_key.pub_to_base64 () << endl;
|
||||||
|
|
||||||
if (check_real_time () != 0) {
|
if (test_time () != 0) {
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
#include "time_helpers.h"
|
#include "time_helpers.h"
|
||||||
|
|
||||||
#include <chrono>
|
#include <chrono>
|
||||||
|
#include <iostream>
|
||||||
|
|
||||||
namespace BareMinimumCrypto {
|
namespace BareMinimumCrypto {
|
||||||
using namespace std;
|
using namespace std;
|
||||||
|
@ -10,4 +11,25 @@ namespace BareMinimumCrypto {
|
||||||
const auto utc_now = system_clock::now ();
|
const auto utc_now = system_clock::now ();
|
||||||
return duration_cast <seconds> (utc_now.time_since_epoch ()).count ();
|
return duration_cast <seconds> (utc_now.time_since_epoch ()).count ();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Most tests will use a virtual clock. But just as a smoke test,
|
||||||
|
// make sure real time is realistic.
|
||||||
|
|
||||||
|
int test_time () {
|
||||||
|
const auto seconds_since_epoch = get_seconds_since_epoch ();
|
||||||
|
|
||||||
|
const auto time_of_writing = 1610844872;
|
||||||
|
if (seconds_since_epoch < time_of_writing) {
|
||||||
|
cerr << "Error: Real time is in the past." << endl;
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
const int64_t about_100_years = (int64_t)100 * 365 * 86400;
|
||||||
|
if (seconds_since_epoch > time_of_writing + about_100_years) {
|
||||||
|
cerr << "Error: Real time is in the far future." << endl;
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -8,4 +8,6 @@ namespace BareMinimumCrypto {
|
||||||
const int64_t about_1_year = (int64_t)365 * 86400;
|
const int64_t about_1_year = (int64_t)365 * 86400;
|
||||||
|
|
||||||
int64_t get_seconds_since_epoch ();
|
int64_t get_seconds_since_epoch ();
|
||||||
|
|
||||||
|
int test_time ();
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue