From 0e4c094eed71ab4cded7faf07ba4746c508fda0a Mon Sep 17 00:00:00 2001 From: Gulliver Date: Sat, 31 Dec 2022 13:49:58 +0100 Subject: [PATCH] corrected name RequestCDD to RequestCDDC --- README.md | 7 ++++++- src/main.cpp | 4 ++-- src/model.cpp | 8 ++++---- src/model.hpp | 6 +++--- test/test.cpp | 20 ++++++++++---------- 5 files changed, 25 insertions(+), 20 deletions(-) diff --git a/README.md b/README.md index 715e6d8..16ad164 100644 --- a/README.md +++ b/README.md @@ -16,8 +16,13 @@ or also the key? ## TODO -+ [ ] bigint type for big integers encoded as string ++ [x] bigint type for big integers encoded as string + [ ] blinding utilizing crypto++ +- [x] complete from_json conversions +- [x] complete tests +- [x] drone config +- [ ] select crypto library + + https://en.wikipedia.org/wiki/Comparison_of_cryptography_libraries ### Blinding Notes diff --git a/src/main.cpp b/src/main.cpp index a45fa57..c76baa7 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -29,11 +29,11 @@ int main() { CROW_ROUTE(app, "/cddc/serial") .methods(crow::HTTPMethod::POST)([&model](const crow::request &request) { - auto req = RequestCDDSerial::from_string(request.body); + auto req = RequestCDDCSerial::from_string(request.body); if (!req) { return crow::response(crow::status::BAD_REQUEST); } else { - ResponseCDDSerial res; + ResponseCDDCSerial res; res.message_reference = req->message_reference; auto cddc = model->getCurrentCDDC(); diff --git a/src/model.cpp b/src/model.cpp index 9420065..b1094a3 100644 --- a/src/model.cpp +++ b/src/model.cpp @@ -104,7 +104,7 @@ crow::json::wvalue Response::to_json() const { return r; } -crow::json::wvalue ResponseCDDSerial::to_json() const { +crow::json::wvalue ResponseCDDCSerial::to_json() const { crow::json::wvalue r = Response::to_json(); TO_JSON(cdd_serial); @@ -112,8 +112,8 @@ crow::json::wvalue ResponseCDDSerial::to_json() const { return r; } -tl::expected -RequestCDDSerial::from_string(const std::string &str) { +tl::expected +RequestCDDCSerial::from_string(const std::string &str) { auto json = crow::json::load(str); if (!json) { return tl::make_unexpected(eError::JSON_PARSE_ERROR); @@ -122,7 +122,7 @@ RequestCDDSerial::from_string(const std::string &str) { } else if (json["type"] != "request cdd serial") { return tl::make_unexpected(eError::JSON_ERROR); } else { - RequestCDDSerial r; + RequestCDDCSerial r; r.message_reference = json["message_reference"].u(); return r; } diff --git a/src/model.hpp b/src/model.hpp index 584581c..3d9a2b7 100644 --- a/src/model.hpp +++ b/src/model.hpp @@ -100,14 +100,14 @@ struct Response { virtual crow::json::wvalue to_json() const; }; -struct RequestCDDSerial { +struct RequestCDDCSerial { unsigned int message_reference; /// Client internal message reference. /// (Integer) - static tl::expected + static tl::expected from_string(const std::string &str); }; -struct ResponseCDDSerial : Response { +struct ResponseCDDCSerial : Response { unsigned int cdd_serial; crow::json::wvalue to_json() const override; diff --git a/test/test.cpp b/test/test.cpp index db4ef9f..5045313 100644 --- a/test/test.cpp +++ b/test/test.cpp @@ -15,32 +15,32 @@ TEST_CASE( "PublicKey::to_json", "[to_json]" ) { REQUIRE( json.keys().size() == 3 ); } -TEST_CASE("RequestCDDSerial::from_string", "[from_string]") { +TEST_CASE("RequestCDDCSerial::from_string", "[from_string]") { // good case std::string good = "{" "\"message_reference\": 100000," "\"type\": \"request cdd serial\"" "}"; - auto res = RequestCDDSerial::from_string(good); + auto res = RequestCDDCSerial::from_string(good); REQUIRE(res.has_value() == true); REQUIRE(res->message_reference == 100000); // bad cases - res = RequestCDDSerial::from_string(""); + res = RequestCDDCSerial::from_string(""); REQUIRE(res.has_value() == false); // invalid type - res = RequestCDDSerial::from_string("{" - "\"message_reference\": 100000," - "\"type\": \"request something wrong\"" - "}"); + res = RequestCDDCSerial::from_string("{" + "\"message_reference\": 100000," + "\"type\": \"request something wrong\"" + "}"); REQUIRE(res.has_value() == false); // invalid attribute name - res = RequestCDDSerial::from_string("{" - "\"x_message_reference\": 100000," - "}"); + res = RequestCDDCSerial::from_string("{" + "\"x_message_reference\": 100000," + "}"); REQUIRE(res.has_value() == false); }