1 Commits

Author SHA1 Message Date
7d3066572c included crypto++ lib 2023-01-30 00:08:28 +01:00
13 changed files with 191 additions and 224 deletions

View File

@ -1,11 +0,0 @@
# To get started with Dependabot version updates, you'll need to specify which
# package ecosystems to update and where the package manifests are located.
# Please see the documentation for all configuration options:
# https://docs.github.com/github/administering-a-repository/configuration-options-for-dependency-updates
version: 2
updates:
- package-ecosystem: "" # See documentation for possible values
directory: "/" # Location of package manifests
schedule:
interval: "weekly"

View File

@ -19,44 +19,31 @@ jobs:
strategy: strategy:
fail-fast: false fail-fast: false
matrix: matrix:
os: [ubuntu-latest, os: [ubuntu-latest, macos-latest, windows-latest]
macos-latest,
windows-latest]
steps: steps:
- uses: actions/checkout@v3 - uses: actions/checkout@v3
- name: Prepare dependencies - name: Prepare dependencies
run: | run: |
if [ "$RUNNER_OS" == "Linux" ]; then if [ "$RUNNER_OS" == "Linux" ]; then
sudo apt-get update && \ sudo apt-get update && \
sudo apt-get install -yq \ sudo apt-get install -yq \
libasio-dev \ libboost-system-dev \
libssl-dev zlib1g-dev \ libboost-date-time-dev \
cmake graphviz doxygen cmake \
elif [ "$RUNNER_OS" == "Windows" ]; then graphviz doxygen
VCPKG_DEFAULT_TRIPLET=x64-windows vcpkg install elif [ "$RUNNER_OS" == "Windows" ]; then
elif [ "$RUNNER_OS" == "macOS" ]; then choco install boost-msvc-14.3 graphviz doxygen.install
brew install asio openssl zlib doxygen graphviz elif [ "$RUNNER_OS" == "macOS" ]; then
else brew install boost graphviz doxygen
echo "$RUNNER_OS not supported" else
exit 1 echo "$RUNNER_OS not supported"
fi exit 1
shell: bash fi
shell: bash
- name: Configure CMake - name: Configure CMake
run: | run: cmake -B build
if [ "$RUNNER_OS" == "Windows" ]; then shell: bash
cmake \
-DCMAKE_TOOLCHAIN_FILE=C:/vcpkg/scripts/buildsystems/vcpkg.cmake \
-B build
elif [ "$RUNNER_OS" == "macOS" ]; then
cmake \
-B build
else
cmake \
-B build
fi
shell: bash
- name: Build - name: Build
# Build your program with the given configuration # Build your program with the given configuration
run: cmake --build build --config ${{env.BUILD_TYPE}} run: cmake --build build --config ${{env.BUILD_TYPE}}

View File

@ -15,12 +15,7 @@ jobs:
- name: Checkout 🛎️ - name: Checkout 🛎️
uses: actions/checkout@v3 uses: actions/checkout@v3
- name: Prepare dependencies - name: Prepare dependencies
run: | run: sudo apt-get update && sudo apt-get install -yq libboost-system-dev libboost-date-time-dev cmake graphviz doxygen
sudo apt-get update && \
sudo apt-get install -yq \
libasio-dev \
libssl-dev zlib1g-dev \
cmake graphviz doxygen
- name: configure - name: configure
run: cmake -B build -S . -DEXPATPP_BUILD_DOCS=ON run: cmake -B build -S . -DEXPATPP_BUILD_DOCS=ON
- name: clean generated docs dir - name: clean generated docs dir

View File

@ -1,11 +1,8 @@
cmake_minimum_required(VERSION 3.15.0 FATAL_ERROR) cmake_minimum_required(VERSION 3.1.3)
project(oc-issuer VERSION 0.0.2 LANGUAGES CXX)
enable_language(C) enable_language(C)
enable_language(CXX) enable_language(CXX)
set(CMAKE_CXX_STANDARD 17) set(CMAKE_CXX_STANDARD 17)
set(CMAKE_EXPORT_COMPILE_COMMANDS On)
if(POLICY CMP0077) if(POLICY CMP0077)
cmake_policy(SET CMP0077 NEW) cmake_policy(SET CMP0077 NEW)
@ -17,6 +14,7 @@ else()
add_compile_options(-Wall -Wextra -pedantic) add_compile_options(-Wall -Wextra -pedantic)
endif() endif()
project(oc-issuer VERSION 0.0.2 LANGUAGES CXX)
include(FetchContent) include(FetchContent)
@ -27,12 +25,11 @@ set(CROW_BUILD_EXAMPLES Off)
set(CROW_BUILD_TOOLS Off) set(CROW_BUILD_TOOLS Off)
set(CROW_BUILD_TESTS Off) set(CROW_BUILD_TESTS Off)
set(CROW_BUILD_DOCS Off) set(CROW_BUILD_DOCS Off)
set(CROW_FEATURES "ssl;compression")
# add crow project to the build # add crow project to the build
FetchContent_Declare(crow FetchContent_Declare(crow
GIT_REPOSITORY https://github.com/CrowCpp/Crow.git GIT_REPOSITORY https://github.com/CrowCpp/Crow.git
GIT_TAG v1.2.0 GIT_TAG v1.0+5
) )
if(NOT crow_POPULATED) if(NOT crow_POPULATED)
@ -49,15 +46,27 @@ if(NOT expected_POPULATED)
FetchContent_Populate(expected) FetchContent_Populate(expected)
endif(NOT expected_POPULATED) endif(NOT expected_POPULATED)
# add crypt++ (+cmake) library
set(CRYPTOPP_BUILD_TESTING Off)
set(CRYPTOPP_INSTALL Off)
if(NOT cryptopp_POPULATED)
FetchContent_Declare(cryptopp
GIT_REPOSITORY https://github.com/abdes/cryptopp-cmake.git
GIT_TAG CRYPTOPP_8_7_0)
FetchContent_Populate(cryptopp)
add_subdirectory(${cryptopp_SOURCE_DIR} ${cryptopp_BINARY_DIR})
endif(NOT cryptopp_POPULATED)
include(CTest) include(CTest)
enable_testing() enable_testing()
set(CATCH_INSTALL_DOCS Off) set(CATCH_INSTALL_DOCS Off)
set(CATCH_INSTALL_EXTRAS Off) set(CATCH_INSTALL_EXTRAS Off)
FetchContent_Declare( FetchContent_Declare(
Catch2 Catch2
GIT_REPOSITORY https://github.com/catchorg/Catch2.git GIT_REPOSITORY https://github.com/catchorg/Catch2.git
GIT_TAG v3.6.0 GIT_TAG v3.3.1
) )
FetchContent_MakeAvailable(Catch2) FetchContent_MakeAvailable(Catch2)
@ -80,7 +89,7 @@ set(LIB_SOURCES
src/big_int.hpp src/big_int.cpp ) src/big_int.hpp src/big_int.cpp )
add_library(oc-mint-lib ${LIB_SOURCES}) add_library(oc-mint-lib ${LIB_SOURCES})
target_link_libraries(oc-mint-lib PUBLIC Crow::Crow) target_link_libraries(oc-mint-lib PUBLIC Crow::Crow cryptopp::cryptopp)
target_include_directories(oc-mint-lib PUBLIC ${expected_SOURCE_DIR}/include src) target_include_directories(oc-mint-lib PUBLIC ${expected_SOURCE_DIR}/include src)
add_executable(${PROJECT_NAME} src/main.cpp) add_executable(${PROJECT_NAME} src/main.cpp)

View File

@ -18,8 +18,8 @@ The following table gives an overview of the mapping of requests to URLs:
| Request | URL | Response | C++ Interface Method | | Request | URL | Response | C++ Interface Method |
|:------------------|:-------------|:------------------------------|:---------------------------------------------------| |:------------------|:-------------|:------------------------------|:---------------------------------------------------|
| RequestCDDCSerial | /cddc/serial | ResponseCDDCSerial | cdd.cdd_serial of Model::get_current_cddc() | | RequestCDDCSerial | /cddc/serial | ResponseCDDCSerial | cdd.cdd_serial of Model::getCurrentCDDC() |
| RequestCDDC | /cddc | ResponseCDDC | Model::get_current_cddc() | | RequestCDDC | /cddc | ResponseCDDC | Model::getCurrentCDDC() |
| RequestMKCs | /mkcs | ResponseMKCs | Model::getMKCs | | RequestMKCs | /mkcs | ResponseMKCs | Model::getMKCs |
| RequestMint | /mint | ResponseMint | Model::mint | | RequestMint | /mint | ResponseMint | Model::mint |
| RequestRenew | /renew | ResponseMint or ResponseDelay | ? | | RequestRenew | /renew | ResponseMint or ResponseDelay | ? |
@ -51,8 +51,3 @@ https://crypto.stackexchange.com/questions/12707/usability-of-padding-scheme-in-
https://crypto.stackexchange.com/questions/54085/is-there-a-standard-padding-format-for-rsa-blind-signatures/60728#60728 https://crypto.stackexchange.com/questions/54085/is-there-a-standard-padding-format-for-rsa-blind-signatures/60728#60728
https://crypto.stackexchange.com/questions/5626/rsa-blind-signatures-in-practice https://crypto.stackexchange.com/questions/5626/rsa-blind-signatures-in-practice
<https://cfrg.github.io/draft-irtf-cfrg-blind-signatures/draft-irtf-cfrg-rsa-blind-signatures.html>
alternative implementation using openssl
https://github.com/jedisct1/blind-rsa-signatures

View File

@ -1,76 +1,82 @@
#include "big_int.hpp" #include "big_int.hpp"
#include "tl/expected.hpp" #include "tl/expected.hpp"
#include <iostream>
#include <charconv> #include <charconv>
#include <vector>
#pragma clang diagnostic push
#pragma ide diagnostic ignored "clion-misra-cpp2008-6-4-5"
inline uint8_t hex(char c) { inline uint8_t hex(char c) {
switch(c) { switch(c) {
case '0': return 0U; case '0': return 0;
case '1': return 1U; case '1': return 1;
case '2': return 2U; case '2': return 2;
case '3': return 3U; case '3': return 3;
case '4': return 4U; case '4': return 4;
case '5': return 5U; case '5': return 5;
case '6': return 6U; case '6': return 6;
case '7': return 7U; case '7': return 7;
case '8': return 8U; case '8': return 8;
case '9': return 9U; case '9': return 9;
case 'a': return 10U; case 'a': return 10;
case 'b': return 11U; case 'b': return 11;
case 'c': return 12U; case 'c': return 12;
case 'd': return 13U; case 'd': return 13;
case 'e': return 14U; case 'e': return 14;
case 'f': return 15U; case 'f': return 15;
case 'A': return 10U; case 'A': return 10;
case 'B': return 11U; case 'B': return 11;
case 'C': return 12U; case 'C': return 12;
case 'D': return 13U; case 'D': return 13;
case 'E': return 14U; case 'E': return 14;
case 'F': return 15U; case 'F': return 15;
default: default:
return 0xffU; return 0xff;
} }
} }
#pragma clang diagnostic pop
tl::expected<BigInt,BigInt::eError> tl::expected<BigInt,BigInt::eError>
BigInt::from_string(const std::string& str) { BigInt::from_string(const std::string& str) {
BigInt b; BigInt b;
// std::cout << str << std::endl;
uint8_t hval=0U; uint8_t hval=0;
uint8_t nibble; uint8_t nibble;
size_t i = str.size()+1U; size_t i = str.size()+1;
for(auto c : str) { for(auto c : str) {
nibble = hex(c); nibble = hex(c);
if (nibble ==0xFFU) { if (nibble ==0xFF) {
return tl::make_unexpected(eError::PARSE_ERROR); return tl::make_unexpected(eError::PARSE_ERROR);
} }
if ( i%2U != 0U ) { if (i%2) {
hval = nibble << 4U; hval = nibble << 4;
} else { } else {
hval |= nibble; hval |= nibble;
b.data[256U - (i/2U)]= hval; b.data[256 - (i/2)]= hval;
hval = 0U; hval = 0;
} }
i--; i--;
} }
// std::cout << std::hex;
// for (auto b: b.data)
// {
// std::cout << (int)b;
// }
// std::cout << std::dec << std::endl;
return b; return b;
} }
BigInt BigInt::from_int(uint64_t value) BigInt BigInt::from_int(uint64_t value)
{ {
BigInt b; BigInt b;
b.data[248U]=static_cast<uint8_t>(value >> 56 & 0xffU); b.data[248]=(value >> 56 & 0xff);
b.data[249U]=static_cast<uint8_t>(value >> 48 & 0xffU); b.data[249]=(value >> 48 & 0xff);
b.data[250U]=static_cast<uint8_t>(value >> 40U & 0xffU); b.data[250]=(value >> 40 & 0xff);
b.data[251U]=static_cast<uint8_t>(value >> 32U & 0xffU); b.data[251]=(value >> 32 & 0xff);
b.data[252U]=static_cast<uint8_t>(value >> 24U & 0xffU); b.data[252]=(value >> 24 & 0xff);
b.data[253U]=static_cast<uint8_t>(value >> 16U & 0xffU); b.data[253]=(value >> 16 & 0xff);
b.data[254U]=static_cast<uint8_t>(value >> 8U & 0xffU); b.data[254]=(value >> 8 & 0xff);
b.data[255U]=static_cast<uint8_t>(value & 0xffU); b.data[255]=(value & 0xff);
return b; return b;
} }
@ -79,16 +85,14 @@ std::string BigInt::to_string() const
{ {
std::string s; std::string s;
uint8_t b; uint8_t b;
uint8_t first_digit = 0U; uint8_t first_digit = 0;
for (size_t i = 0U; i<256U;i++) { for (size_t i = 0; i<256;i++) {
b = data[i]; b = data[i];
if (first_digit==0U) { if (first_digit==0) {
if (b==0U) { if (b==0) {
continue; continue;
} else if (b>0xfU) { } else if (b>0xf) {
s.push_back(hex_char[b >> 4]); s.push_back(hex_char[b >> 4]);
} else {
/* nothing to do here */
} }
s.push_back(hex_char[b & 0xf]); s.push_back(hex_char[b & 0xf]);
first_digit = b; first_digit = b;

View File

@ -1,5 +1,5 @@
#ifndef OC_ISSUER_BIG_INT_HPP #ifndef BIG_INT_HPP
#define OC_ISSUER_BIG_INT_HPP #define BIG_INT_HPP
#include <string> #include <string>
#include <array> #include <array>
@ -9,19 +9,19 @@
struct BigInt { struct BigInt {
BigInt() : data() {} BigInt() : data() {}
virtual ~BigInt() = default; virtual ~BigInt() {}
enum class eError : uint8_t { PARSE_ERROR }; enum class eError : uint8_t { PARSE_ERROR };
static tl::expected<BigInt, eError> from_string(const std::string &str); static tl::expected<BigInt, eError> from_string(const std::string &str);
static BigInt from_int(uint64_t value); static BigInt from_int(uint64_t value);
[[nodiscard]] std::string to_string() const; std::string to_string() const;
friend bool operator == (const BigInt& rhs, const BigInt& lhs); friend bool operator == (const BigInt& rhs, const BigInt& lhs);
private: private:
std::array<uint8_t,256U> data; std::array<uint8_t,256> data;
}; };
bool operator==(const BigInt &rhs, const BigInt &lhs); bool operator==(const BigInt &rhs, const BigInt &lhs);
#endif // #ifndef #ifndef OC_ISSUER_BIG_INT_HPP #endif // #ifndef #ifndef BIG_INT_HPP

View File

@ -10,18 +10,16 @@
template <class T> template <class T>
crow::json::wvalue list_to_json(const std::vector<T> &array) { crow::json::wvalue list_to_json(const std::vector<T> &array) {
crow::json::wvalue::list l; crow::json::wvalue::list l;
for (const auto& item : array) { for (auto item : array)
l.push_back(item.to_json()); l.push_back(item.to_json());
} return crow::json::wvalue(l);
return {l};
} }
crow::json::wvalue list_to_json(const std::vector<unsigned int> &array) { crow::json::wvalue list_to_json(const std::vector<unsigned int> &array) {
crow::json::wvalue::list l; crow::json::wvalue::list l;
for (auto item : array) { for (auto item : array)
l.emplace_back(item); l.push_back(item);
} return crow::json::wvalue(l);
return {l};
} }
crow::json::wvalue PublicKey::to_json() const { crow::json::wvalue PublicKey::to_json() const {
@ -37,7 +35,7 @@ crow::json::wvalue WeightedUrl::to_json() const {
crow::json::wvalue w(weight); crow::json::wvalue w(weight);
l.push_back(w); l.push_back(w);
l.emplace_back(url); l.push_back(url);
return l; return l;
} }
@ -173,7 +171,7 @@ RequestMKCs::from_string(const std::string &str) {
if (denominations.t() != crow::json::type::List) { if (denominations.t() != crow::json::type::List) {
return tl::make_unexpected(eError::JSON_WRONG_REQUEST_TYPE); return tl::make_unexpected(eError::JSON_WRONG_REQUEST_TYPE);
} else { } else {
for (const auto& d : denominations.lo()) { for (auto d : denominations.lo()) {
r.denominations.push_back(d.u()); r.denominations.push_back(d.u());
} }
} }
@ -181,7 +179,7 @@ RequestMKCs::from_string(const std::string &str) {
if (mint_key_ids.t() != crow::json::type::List) { if (mint_key_ids.t() != crow::json::type::List) {
return tl::make_unexpected(eError::JSON_WRONG_REQUEST_TYPE); return tl::make_unexpected(eError::JSON_WRONG_REQUEST_TYPE);
} else { } else {
for (const auto& k: mint_key_ids.lo()) { for (auto k: mint_key_ids.lo()) {
auto kv = BigInt::from_string(k.s()); auto kv = BigInt::from_string(k.s());
if (!kv.has_value()) { if (!kv.has_value()) {
return tl::make_unexpected(eError::JSON_PARSE_ERROR); return tl::make_unexpected(eError::JSON_PARSE_ERROR);
@ -271,7 +269,7 @@ RequestMint::from_string(const std::string &str) {
return tl::make_unexpected(eError::JSON_WRONG_VALUE_TYPE); return tl::make_unexpected(eError::JSON_WRONG_VALUE_TYPE);
} }
for (const auto& item : json["blinds"]) { for (auto item : json["blinds"]) {
auto b = Blind::from_json(item); auto b = Blind::from_json(item);
if (!b.has_value()) { if (!b.has_value()) {
return tl::make_unexpected(b.error()); return tl::make_unexpected(b.error());
@ -386,7 +384,7 @@ RequestRenew::from_string(const std::string &str) {
} else { } else {
RequestRenew r; RequestRenew r;
for (const auto& item : json["coins"]) { for (auto item : json["coins"]) {
auto coin = Coin::from_json(item); auto coin = Coin::from_json(item);
if (!coin.has_value()) { if (!coin.has_value()) {
return tl::make_unexpected(coin.error()); return tl::make_unexpected(coin.error());
@ -395,7 +393,7 @@ RequestRenew::from_string(const std::string &str) {
} }
} }
for (const auto& item : json["blinds"]) { for (auto item : json["blinds"]) {
auto blind = Blind::from_json(item); auto blind = Blind::from_json(item);
if (!blind.has_value()) { if (!blind.has_value()) {
return tl::make_unexpected(blind.error()); return tl::make_unexpected(blind.error());
@ -455,7 +453,7 @@ RequestRedeem::from_string(const std::string &str) {
return tl::make_unexpected(eError::JSON_WRONG_VALUE_TYPE); return tl::make_unexpected(eError::JSON_WRONG_VALUE_TYPE);
} }
for (const auto& item : json["coins"]) { for (auto item : json["coins"]) {
auto coin = Coin::from_json(item); auto coin = Coin::from_json(item);
if (!coin.has_value()) { if (!coin.has_value()) {
return tl::make_unexpected(coin.error()); return tl::make_unexpected(coin.error());

View File

@ -1,22 +1,22 @@
#include "crow.h" #include "crow.h"
#include "crow/common.h" #include "crow/common.h"
#include "crow/http_parser_merged.h"
#include "crow/http_response.h" #include "crow/http_response.h"
#include "model.hpp" #include "model.hpp"
int main() { int main() {
crow::SimpleApp app; crow::SimpleApp app;
std::shared_ptr<Model> model = Model::get_model("simple"); std::shared_ptr<Model> model = Model::getModel("simple");
CROW_ROUTE(app, "/cddc") CROW_ROUTE(app, "/cddc")
.methods(crow::HTTPMethod::POST) .methods(crow::HTTPMethod::POST)([&model](const crow::request &req) {
([&model](const crow::request &req) {
auto req_cddc = RequestCDDC::from_string(req.body); auto req_cddc = RequestCDDC::from_string(req.body);
if (!req_cddc) { if (!req_cddc) {
return crow::response(crow::status::BAD_REQUEST); return crow::response(crow::status::BAD_REQUEST);
} else { } else {
ResponseCDDC res; ResponseCDDC res;
res.message_reference = req_cddc->message_reference; res.message_reference = req_cddc->message_reference;
auto cddc = model->get_cddc(req_cddc->cdd_serial); auto cddc = model->getCDDC(req_cddc->cdd_serial);
if (!cddc) { if (!cddc) {
res.status_code = crow::status::NOT_FOUND; res.status_code = crow::status::NOT_FOUND;
} else { } else {
@ -36,7 +36,7 @@ int main() {
ResponseCDDCSerial res; ResponseCDDCSerial res;
res.message_reference = req->message_reference; res.message_reference = req->message_reference;
auto cddc = model->get_current_cddc(); auto cddc = model->getCurrentCDDC();
if (!cddc) { if (!cddc) {
res.status_code = crow::status::NOT_FOUND; res.status_code = crow::status::NOT_FOUND;
} else { } else {
@ -47,8 +47,8 @@ int main() {
} }
}); });
CROW_ROUTE(app, "/mkcs").methods(crow::HTTPMethod::POST) CROW_ROUTE(app, "/mkcs")
([&model](const crow::request &request) { .methods(crow::HTTPMethod::POST)([&model](const crow::request &request) {
auto req = RequestMKCs::from_string(request.body); auto req = RequestMKCs::from_string(request.body);
if (!req) { if (!req) {
return crow::response(crow::status::BAD_REQUEST); return crow::response(crow::status::BAD_REQUEST);
@ -61,8 +61,8 @@ int main() {
} }
}); });
CROW_ROUTE(app, "/mint").methods(crow::HTTPMethod::POST) CROW_ROUTE(app, "/mint")
([&model](const crow::request &request) { .methods(crow::HTTPMethod::POST)([&model](const crow::request &request) {
auto req = RequestMint::from_string(request.body); auto req = RequestMint::from_string(request.body);
if (!req) { if (!req) {
return crow::response(crow::status::BAD_REQUEST); return crow::response(crow::status::BAD_REQUEST);
@ -70,9 +70,8 @@ int main() {
ResponseMint res; ResponseMint res;
res.message_reference = req->message_reference; res.message_reference = req->message_reference;
/// \todo change argument transaction_reference to bigint /// \todo change argument transaction_reference to bigint
auto minted = auto minted = model->mint(req->transaction_reference.to_string(), req->blinds);
model->mint(req->transaction_reference.to_string(), req->blinds);
res.blind_signatures = minted; res.blind_signatures = minted;
res.status_code = crow::status::OK; res.status_code = crow::status::OK;

View File

@ -4,53 +4,53 @@
using std::cout; using std::cout;
using std::endl; using std::endl;
#define UNUSED(s) /* s */ #define UNUSED(s) /* s */
/** this is for now our sample model */ /** this is for now our sample model */
class DefaultModel : public Model { class DefaultModel : public Model {
public: public:
DefaultModel() = default; DefaultModel() {}
tl::expected<CDDC *, bool> getCDDC(unsigned int cdd_serial) override {
cout << __FUNCTION__ << "(" << cdd_serial << ")" << endl;
return &m_cddc;
};
tl::expected<CDDC *, bool> get_cddc(unsigned int cdd_serial) override { tl::expected<CDDC *, bool> getCurrentCDDC() override {
cout << __FUNCTION__ << "(" << cdd_serial << ")" << endl; // NOLINT(clion-misra-cpp2008-5-2-12) cout << __FUNCTION__ << "()" << endl;
return &m_cddc;
};
tl::expected<CDDC *, bool> get_current_cddc() override { return &m_cddc;
cout << __FUNCTION__ << "()" << endl; }
return &m_cddc; std::vector<BlindSignature>
} mint(const std::string& UNUSED(transaction_reference),
const std::vector<Blind> &UNUSED(blinds) ) override
{
std::vector<BlindSignature> res;
cout << __FUNCTION__ << "("
<< ")" << endl;
std::vector<BlindSignature> return res;
mint(const std::string & UNUSED(transaction_reference), }
const std::vector<Blind> &UNUSED(blinds)) override {
std::vector<BlindSignature> res;
cout << __FUNCTION__ << "("
<< ")" << endl;
return res; const std::vector<MintKeyCert>
} getMKCs(const std::vector<unsigned int> & UNUSED(denominations),
const std::vector<BigInt> & UNUSED(mint_key_ids) ) override
{
std::vector<MintKeyCert> res;
cout << __FUNCTION__ << endl;
return res;
}
std::vector<MintKeyCert> bool redeem(const std::vector<Coin> &UNUSED(coins)) override {
getMKCs(const std::vector<unsigned int> & UNUSED(denominations), cout << __FUNCTION__ << endl;
const std::vector<BigInt> & UNUSED(mint_key_ids)) override { return false;
std::vector<MintKeyCert> res; }
cout << __FUNCTION__ << endl;
return res;
}
bool redeem(const std::vector<Coin> &UNUSED(coins)) override {
cout << __FUNCTION__ << endl;
return false;
}
private: private:
CDDC m_cddc; CDDC m_cddc;
}; };
std::unique_ptr<Model> Model::get_model(const std::string & /*backend_name*/) { std::unique_ptr<Model> Model::getModel(const std::string & /*backend_name*/) {
cout << __FUNCTION__ << endl; cout << __FUNCTION__ << endl;
//:wq //:wq
// if (backend_name=="default") // if (backend_name=="default")
return std::make_unique<DefaultModel>(); return std::make_unique<DefaultModel>();
} }

View File

@ -1,5 +1,5 @@
#ifndef OC_ISSUER_MODEL_HPP #ifndef MODEL_HPP
#define OC_ISSUER_MODEL_HPP #define MODEL_HPP
#include <chrono> #include <chrono>
#include <memory> #include <memory>
@ -15,14 +15,14 @@ struct PublicKey {
BigInt modulus; //: "daaa63ddda38c189b8c49020c8276adbe0a695685a...", BigInt modulus; //: "daaa63ddda38c189b8c49020c8276adbe0a695685a...",
BigInt public_exponent;//: 65537, BigInt public_exponent;//: 65537,
[[nodiscard]] crow::json::wvalue to_json() const; crow::json::wvalue to_json() const;
}; };
struct WeightedUrl { struct WeightedUrl {
uint32_t weight; uint32_t weight;
std::string url; std::string url;
[[nodiscard]] crow::json::wvalue to_json() const; crow::json::wvalue to_json() const;
}; };
/** @brief currency description document /** @brief currency description document
@ -58,14 +58,14 @@ struct CDD {
std::vector<WeightedUrl> redeem_service; std::vector<WeightedUrl> redeem_service;
std::vector<WeightedUrl> renew_service; std::vector<WeightedUrl> renew_service;
[[nodiscard]] crow::json::wvalue to_json() const; crow::json::wvalue to_json() const;
}; };
struct CDDC { struct CDDC {
CDD cdd; CDD cdd;
std::string signature; std::string signature;
[[nodiscard]] crow::json::wvalue to_json() const; crow::json::wvalue to_json() const;
}; };
struct MintKey { struct MintKey {
@ -79,14 +79,14 @@ struct MintKey {
std::string sign_coins_not_after; std::string sign_coins_not_after;
std::string sign_coins_not_before; std::string sign_coins_not_before;
// "type": "mint key" // "type": "mint key"
[[nodiscard]] crow::json::wvalue to_json() const; crow::json::wvalue to_json() const;
}; };
struct MintKeyCert { struct MintKeyCert {
MintKey mint_key; MintKey mint_key;
std::string signature; std::string signature;
[[nodiscard]] crow::json::wvalue to_json() const; crow::json::wvalue to_json() const;
}; };
enum class eError { enum class eError {
@ -103,7 +103,7 @@ struct Response {
unsigned int status_code; unsigned int status_code;
std::string status_description; std::string status_description;
[[nodiscard]] virtual crow::json::wvalue to_json() const=0; virtual crow::json::wvalue to_json() const;
}; };
struct RequestCDDCSerial { struct RequestCDDCSerial {
@ -114,9 +114,9 @@ struct RequestCDDCSerial {
}; };
struct ResponseCDDCSerial : Response { struct ResponseCDDCSerial : Response {
unsigned int cdd_serial{0U}; unsigned int cdd_serial;
[[nodiscard]] crow::json::wvalue to_json() const override; crow::json::wvalue to_json() const override;
}; };
struct RequestCDDC { struct RequestCDDC {
@ -129,7 +129,7 @@ struct RequestCDDC {
struct ResponseCDDC : Response { struct ResponseCDDC : Response {
CDDC cddc; CDDC cddc;
[[nodiscard]] crow::json::wvalue to_json() const override; crow::json::wvalue to_json() const override;
}; };
struct RequestMKCs { struct RequestMKCs {
@ -144,21 +144,21 @@ struct RequestMKCs {
struct ResponseMKCs : Response { struct ResponseMKCs : Response {
std::vector<MintKeyCert> keys; std::vector<MintKeyCert> keys;
[[nodiscard]] crow::json::wvalue to_json() const override; crow::json::wvalue to_json() const override;
}; };
struct Blind { struct Blind {
BigInt blinded_payload_hash; //bigint BigInt blinded_payload_hash; //bigint
BigInt mint_key_id; //bigint BigInt mint_key_id; //bigint
std::string reference; std::string reference;
[[nodiscard]] crow::json::wvalue to_json() const; crow::json::wvalue to_json() const;
static tl::expected<Blind, eError> from_json(const crow::json::rvalue &json); static tl::expected<Blind, eError> from_json(const crow::json::rvalue &json);
}; };
struct BlindSignature { struct BlindSignature {
BigInt blind_signature; BigInt blind_signature;
std::string reference; std::string reference;
[[nodiscard]] crow::json::wvalue to_json() const; crow::json::wvalue to_json() const;
}; };
struct RequestMint { struct RequestMint {
@ -173,7 +173,7 @@ struct RequestMint {
struct ResponseMint : Response { struct ResponseMint : Response {
std::vector<BlindSignature> blind_signatures; std::vector<BlindSignature> blind_signatures;
[[nodiscard]] crow::json::wvalue to_json() const override; crow::json::wvalue to_json() const override;
}; };
struct Coin { struct Coin {
@ -184,15 +184,15 @@ struct Coin {
BigInt mint_key_id; BigInt mint_key_id;
std::string protocol_version; std::string protocol_version;
BigInt serial; BigInt serial;
[[nodiscard]] crow::json::wvalue to_json() const; crow::json::wvalue to_json() const;
static tl::expected<Payload,eError> from_json(const crow::json::rvalue& json); static tl::expected<Payload,eError> from_json(const crow::json::rvalue& json);
}; };
Payload payload; Payload payload;
std::string signature; std::string signature;
[[nodiscard]] crow::json::wvalue to_json() const; crow::json::wvalue to_json() const;
static tl::expected<Coin, eError> from_json(const crow::json::rvalue &json); static tl::expected<Coin, eError> from_json(const crow::json::rvalue &json);
}; };
@ -200,7 +200,7 @@ struct CoinStack {
std::vector<Coin> coins; std::vector<Coin> coins;
std::string subject; std::string subject;
// "type": "coinstack" // "type": "coinstack"
[[nodiscard]] crow::json::wvalue to_json() const; crow::json::wvalue to_json() const;
}; };
struct RequestRenew { struct RequestRenew {
@ -214,7 +214,7 @@ struct RequestRenew {
}; };
struct ResponseDelay : Response { struct ResponseDelay : Response {
[[nodiscard]] crow::json::wvalue to_json() const override; crow::json::wvalue to_json() const override;
}; };
struct RequestResume { struct RequestResume {
@ -236,12 +236,12 @@ struct RequestRedeem {
}; };
struct ResponseRedeem : Response { struct ResponseRedeem : Response {
[[nodiscard]] crow::json::wvalue to_json() const override; crow::json::wvalue to_json() const override;
}; };
class Model { class Model {
public: public:
virtual ~Model()=default; virtual ~Model(){};
/** /**
* return the CurrencyDocumentDescription certifikate for a specific * return the CurrencyDocumentDescription certifikate for a specific
@ -249,13 +249,13 @@ public:
* [see spec](https://opencoin.org/0.4/schemata.html#cddc) * [see spec](https://opencoin.org/0.4/schemata.html#cddc)
* @return returns a pointer to the CDDC if successful, false otherwise * @return returns a pointer to the CDDC if successful, false otherwise
*/ */
virtual tl::expected<CDDC *, bool> get_cddc(unsigned int cdd_serial) = 0; virtual tl::expected<CDDC *, bool> getCDDC(unsigned int cdd_serial) = 0;
/** /**
* return the CurrencyDocumentDescription certifikate * return the CurrencyDocumentDescription certifikate
* [see spec](https://opencoin.org/0.4/schemata.html#cddc) * [see spec](https://opencoin.org/0.4/schemata.html#cddc)
* @return returns a pointer to the CDDC if successful, false otherwise * @return returns a pointer to the CDDC if successful, false otherwise
*/virtual tl::expected<CDDC *, bool> get_current_cddc() = 0; */virtual tl::expected<CDDC *, bool> getCurrentCDDC() = 0;
/** /**
* return the MintKey certificates for a given list of denominations * return the MintKey certificates for a given list of denominations
@ -266,7 +266,7 @@ public:
* *
* @return mint key certificates for given denominations and mint_key_ids * @return mint key certificates for given denominations and mint_key_ids
*/ */
virtual std::vector<MintKeyCert> virtual const std::vector<MintKeyCert>
getMKCs(const std::vector<unsigned int> &denominations, getMKCs(const std::vector<unsigned int> &denominations,
const std::vector<BigInt> &mint_key_ids) = 0; const std::vector<BigInt> &mint_key_ids) = 0;
@ -300,9 +300,9 @@ public:
* *
* @return pointer to backend instance or null on invalid backend name * @return pointer to backend instance or null on invalid backend name
*/ */
static std::unique_ptr<Model> get_model(const std::string &backend_name); static std::unique_ptr<Model> getModel(const std::string &backend_name);
private: private:
}; };
#endif // #ifndef OC_ISSUER_MODEL_HPP #endif // #ifndef MODEL_HPP

View File

@ -2,7 +2,7 @@
#include <catch2/catch_test_macros.hpp> #include <catch2/catch_test_macros.hpp>
TEST_CASE("BigInt::from_string", "[big_int]") { TEST_CASE("BigInt::from_string", "[big_int]") {
const std::string VALID [] = { std::string VALID [] = {
"1", "1",
"12", "12",
"123", "123",
@ -17,10 +17,10 @@ TEST_CASE("BigInt::from_string", "[big_int]") {
"abcdef1" "abcdef1"
}; };
for (const auto & i : VALID) { for (size_t i= 0; i<sizeof(VALID)/sizeof(VALID[0]);i++) {
auto b = BigInt::from_string(i); auto b = BigInt::from_string(VALID[i]);
REQUIRE(b->to_string() == VALID[i]);
REQUIRE(b.has_value()); REQUIRE(b.has_value());
REQUIRE(b->to_string() == i);
} }
auto invalid_hex = "aabbcc.."; auto invalid_hex = "aabbcc..";

View File

@ -1,9 +0,0 @@
{
"name": "oc-mint-cpp",
"version-string": "master",
"dependencies": [
"asio",
"openssl",
"zlib"
]
}