♻️ refactor

main
_ 2021-01-17 15:45:59 -06:00
parent 3fdfc983e2
commit 9c4fe4a26e
4 changed files with 30 additions and 14 deletions

View File

@ -5,10 +5,10 @@ CXX_FLAGS=$(FLAGS) -c
L_FLAGS=$(FLAGS)
LIBS=-lsodium
bmc_test: bmc_test.o base64.o string_helpers.o
bmc_test: bmc_test.o base64.o string_helpers.o time_helpers.o
$(CXX) -o $@ $^ $(L_FLAGS) $(LIBS)
bmc_test.o: bmc_test.cpp string_helpers.h
bmc_test.o: bmc_test.cpp string_helpers.h time_helpers.h
$(CXX) -o $@ $(CXX_FLAGS) $<
base64.o: cpp-base64/base64.cpp cpp-base64/base64.h
@ -17,6 +17,9 @@ base64.o: cpp-base64/base64.cpp cpp-base64/base64.h
string_helpers.o: string_helpers.cpp string_helpers.h cpp-base64/base64.h
$(CXX) -o $@ $(CXX_FLAGS) $<
time_helpers.o: time_helpers.cpp time_helpers.h
$(CXX) -o $@ $(CXX_FLAGS) $<
clean:
rm -f bmc_test bmc_test.o base64.o string_helpers.o

View File

@ -12,19 +12,13 @@
#include "json.hpp"
#include "string_helpers.h"
#include "time_helpers.h"
using namespace std;
using chrono::duration_cast;
using chrono::seconds;
using chrono::system_clock;
using nlohmann::json;
using namespace BareMinimumCrypto;
const int64_t about_1_week = (int64_t)7 * 86400;
const int64_t about_3_months = (int64_t)105 * 86400;
const int64_t about_1_year = (int64_t)365 * 86400;
struct ExpiringSignature {
string cert_s;
vector <uint8_t> sig;
@ -42,11 +36,6 @@ struct ExpiringSignature {
}
};
int64_t get_seconds_since_epoch () {
const auto utc_now = system_clock::now ();
return duration_cast <seconds> (utc_now.time_since_epoch ()).count ();
}
void try_sodium_init () {
if (sodium_init () < 0) {
throw std::runtime_error ("Can't initialize libsodium");

View File

@ -0,0 +1,13 @@
#include "time_helpers.h"
#include <chrono>
namespace BareMinimumCrypto {
using namespace std;
using namespace chrono;
int64_t get_seconds_since_epoch () {
const auto utc_now = system_clock::now ();
return duration_cast <seconds> (utc_now.time_since_epoch ()).count ();
}
}

View File

@ -0,0 +1,11 @@
#pragma once
#include <stdint.h>
namespace BareMinimumCrypto {
const int64_t about_1_week = (int64_t)7 * 86400;
const int64_t about_3_months = (int64_t)105 * 86400;
const int64_t about_1_year = (int64_t)365 * 86400;
int64_t get_seconds_since_epoch ();
}