corrected name RequestCDD to RequestCDDC

This commit is contained in:
Gulliver 2022-12-31 13:49:58 +01:00 committed by gittiver
parent 87386e1b65
commit 0e4c094eed
5 changed files with 25 additions and 20 deletions

View File

@ -16,8 +16,13 @@ or also the key?
## TODO ## TODO
+ [ ] bigint type for big integers encoded as string + [x] bigint type for big integers encoded as string
+ [ ] blinding utilizing crypto++ + [ ] 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 ### Blinding Notes

View File

@ -29,11 +29,11 @@ int main() {
CROW_ROUTE(app, "/cddc/serial") CROW_ROUTE(app, "/cddc/serial")
.methods(crow::HTTPMethod::POST)([&model](const crow::request &request) { .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) { if (!req) {
return crow::response(crow::status::BAD_REQUEST); return crow::response(crow::status::BAD_REQUEST);
} else { } else {
ResponseCDDSerial res; ResponseCDDCSerial res;
res.message_reference = req->message_reference; res.message_reference = req->message_reference;
auto cddc = model->getCurrentCDDC(); auto cddc = model->getCurrentCDDC();

View File

@ -104,7 +104,7 @@ crow::json::wvalue Response::to_json() const {
return r; return r;
} }
crow::json::wvalue ResponseCDDSerial::to_json() const { crow::json::wvalue ResponseCDDCSerial::to_json() const {
crow::json::wvalue r = Response::to_json(); crow::json::wvalue r = Response::to_json();
TO_JSON(cdd_serial); TO_JSON(cdd_serial);
@ -112,8 +112,8 @@ crow::json::wvalue ResponseCDDSerial::to_json() const {
return r; return r;
} }
tl::expected<RequestCDDSerial, eError> tl::expected<RequestCDDCSerial, eError>
RequestCDDSerial::from_string(const std::string &str) { RequestCDDCSerial::from_string(const std::string &str) {
auto json = crow::json::load(str); auto json = crow::json::load(str);
if (!json) { if (!json) {
return tl::make_unexpected(eError::JSON_PARSE_ERROR); 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") { } else if (json["type"] != "request cdd serial") {
return tl::make_unexpected(eError::JSON_ERROR); return tl::make_unexpected(eError::JSON_ERROR);
} else { } else {
RequestCDDSerial r; RequestCDDCSerial r;
r.message_reference = json["message_reference"].u(); r.message_reference = json["message_reference"].u();
return r; return r;
} }

View File

@ -100,14 +100,14 @@ struct Response {
virtual crow::json::wvalue to_json() const; virtual crow::json::wvalue to_json() const;
}; };
struct RequestCDDSerial { struct RequestCDDCSerial {
unsigned int message_reference; /// Client internal message reference. unsigned int message_reference; /// Client internal message reference.
/// (Integer) /// (Integer)
static tl::expected<RequestCDDSerial, eError> static tl::expected<RequestCDDCSerial, eError>
from_string(const std::string &str); from_string(const std::string &str);
}; };
struct ResponseCDDSerial : Response { struct ResponseCDDCSerial : Response {
unsigned int cdd_serial; unsigned int cdd_serial;
crow::json::wvalue to_json() const override; crow::json::wvalue to_json() const override;

View File

@ -15,30 +15,30 @@ TEST_CASE( "PublicKey::to_json", "[to_json]" ) {
REQUIRE( json.keys().size() == 3 ); REQUIRE( json.keys().size() == 3 );
} }
TEST_CASE("RequestCDDSerial::from_string", "[from_string]") { TEST_CASE("RequestCDDCSerial::from_string", "[from_string]") {
// good case // good case
std::string good = "{" std::string good = "{"
"\"message_reference\": 100000," "\"message_reference\": 100000,"
"\"type\": \"request cdd serial\"" "\"type\": \"request cdd serial\""
"}"; "}";
auto res = RequestCDDSerial::from_string(good); auto res = RequestCDDCSerial::from_string(good);
REQUIRE(res.has_value() == true); REQUIRE(res.has_value() == true);
REQUIRE(res->message_reference == 100000); REQUIRE(res->message_reference == 100000);
// bad cases // bad cases
res = RequestCDDSerial::from_string(""); res = RequestCDDCSerial::from_string("");
REQUIRE(res.has_value() == false); REQUIRE(res.has_value() == false);
// invalid type // invalid type
res = RequestCDDSerial::from_string("{" res = RequestCDDCSerial::from_string("{"
"\"message_reference\": 100000," "\"message_reference\": 100000,"
"\"type\": \"request something wrong\"" "\"type\": \"request something wrong\""
"}"); "}");
REQUIRE(res.has_value() == false); REQUIRE(res.has_value() == false);
// invalid attribute name // invalid attribute name
res = RequestCDDSerial::from_string("{" res = RequestCDDCSerial::from_string("{"
"\"x_message_reference\": 100000," "\"x_message_reference\": 100000,"
"}"); "}");
REQUIRE(res.has_value() == false); REQUIRE(res.has_value() == false);