Skip to content

Commit e3fd9cb

Browse files
committed
fixes for warnings from code analysis
1 parent 84cbb34 commit e3fd9cb

File tree

8 files changed

+158
-159
lines changed

8 files changed

+158
-159
lines changed

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,8 @@ The following table gives an overview of the mapping of requests to URLs:
1818

1919
| Request | URL | Response | C++ Interface Method |
2020
|:------------------|:-------------|:------------------------------|:---------------------------------------------------|
21-
| RequestCDDCSerial | /cddc/serial | ResponseCDDCSerial | cdd.cdd_serial of Model::getCurrentCDDC() |
22-
| RequestCDDC | /cddc | ResponseCDDC | Model::getCurrentCDDC() |
21+
| RequestCDDCSerial | /cddc/serial | ResponseCDDCSerial | cdd.cdd_serial of Model::get_current_cddc() |
22+
| RequestCDDC | /cddc | ResponseCDDC | Model::get_current_cddc() |
2323
| RequestMKCs | /mkcs | ResponseMKCs | Model::getMKCs |
2424
| RequestMint | /mint | ResponseMint | Model::mint |
2525
| RequestRenew | /renew | ResponseMint or ResponseDelay | ? |

src/big_int.cpp

Lines changed: 50 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -1,82 +1,76 @@
11
#include "big_int.hpp"
22
#include "tl/expected.hpp"
3-
#include <iostream>
43
#include <charconv>
5-
#include <vector>
64

5+
#pragma clang diagnostic push
6+
#pragma ide diagnostic ignored "clion-misra-cpp2008-6-4-5"
77
inline uint8_t hex(char c) {
88
switch(c) {
9-
case '0': return 0;
10-
case '1': return 1;
11-
case '2': return 2;
12-
case '3': return 3;
13-
case '4': return 4;
14-
case '5': return 5;
15-
case '6': return 6;
16-
case '7': return 7;
17-
case '8': return 8;
18-
case '9': return 9;
19-
case 'a': return 10;
20-
case 'b': return 11;
21-
case 'c': return 12;
22-
case 'd': return 13;
23-
case 'e': return 14;
24-
case 'f': return 15;
25-
case 'A': return 10;
26-
case 'B': return 11;
27-
case 'C': return 12;
28-
case 'D': return 13;
29-
case 'E': return 14;
30-
case 'F': return 15;
9+
case '0': return 0U;
10+
case '1': return 1U;
11+
case '2': return 2U;
12+
case '3': return 3U;
13+
case '4': return 4U;
14+
case '5': return 5U;
15+
case '6': return 6U;
16+
case '7': return 7U;
17+
case '8': return 8U;
18+
case '9': return 9U;
19+
case 'a': return 10U;
20+
case 'b': return 11U;
21+
case 'c': return 12U;
22+
case 'd': return 13U;
23+
case 'e': return 14U;
24+
case 'f': return 15U;
25+
case 'A': return 10U;
26+
case 'B': return 11U;
27+
case 'C': return 12U;
28+
case 'D': return 13U;
29+
case 'E': return 14U;
30+
case 'F': return 15U;
3131
default:
32-
return 0xff;
32+
return 0xffU;
3333
}
3434
}
35+
#pragma clang diagnostic pop
3536

3637
tl::expected<BigInt,BigInt::eError>
3738
BigInt::from_string(const std::string& str) {
3839
BigInt b;
39-
// std::cout << str << std::endl;
4040

41-
uint8_t hval=0;
41+
uint8_t hval=0U;
4242
uint8_t nibble;
43-
size_t i = str.size()+1;
43+
size_t i = str.size()+1U;
4444

4545
for(auto c : str) {
4646
nibble = hex(c);
47-
if (nibble ==0xFF) {
47+
if (nibble ==0xFFU) {
4848
return tl::make_unexpected(eError::PARSE_ERROR);
4949
}
50-
if (i%2) {
51-
hval = nibble << 4;
50+
if ( i%2U != 0U ) {
51+
hval = nibble << 4U;
5252
} else {
5353
hval |= nibble;
54-
b.data[256 - (i/2)]= hval;
55-
hval = 0;
54+
b.data[256U - (i/2U)]= hval;
55+
hval = 0U;
5656
}
5757
i--;
5858
}
5959

60-
// std::cout << std::hex;
61-
// for (auto b: b.data)
62-
// {
63-
// std::cout << (int)b;
64-
// }
65-
// std::cout << std::dec << std::endl;
6660
return b;
6761
}
6862

6963
BigInt BigInt::from_int(uint64_t value)
7064
{
7165
BigInt b;
72-
b.data[248]=(value >> 56 & 0xff);
73-
b.data[249]=(value >> 48 & 0xff);
74-
b.data[250]=(value >> 40 & 0xff);
75-
b.data[251]=(value >> 32 & 0xff);
76-
b.data[252]=(value >> 24 & 0xff);
77-
b.data[253]=(value >> 16 & 0xff);
78-
b.data[254]=(value >> 8 & 0xff);
79-
b.data[255]=(value & 0xff);
66+
b.data[248U]=static_cast<uint8_t>(value >> 56 & 0xffU);
67+
b.data[249U]=static_cast<uint8_t>(value >> 48 & 0xffU);
68+
b.data[250U]=static_cast<uint8_t>(value >> 40U & 0xffU);
69+
b.data[251U]=static_cast<uint8_t>(value >> 32U & 0xffU);
70+
b.data[252U]=static_cast<uint8_t>(value >> 24U & 0xffU);
71+
b.data[253U]=static_cast<uint8_t>(value >> 16U & 0xffU);
72+
b.data[254U]=static_cast<uint8_t>(value >> 8U & 0xffU);
73+
b.data[255U]=static_cast<uint8_t>(value & 0xffU);
8074
return b;
8175
}
8276

@@ -85,14 +79,16 @@ std::string BigInt::to_string() const
8579
{
8680
std::string s;
8781
uint8_t b;
88-
uint8_t first_digit = 0;
89-
for (size_t i = 0; i<256;i++) {
82+
uint8_t first_digit = 0U;
83+
for (size_t i = 0U; i<256U;i++) {
9084
b = data[i];
91-
if (first_digit==0) {
92-
if (b==0) {
93-
continue;
94-
} else if (b>0xf) {
95-
s.push_back(hex_char[b >> 4]);
85+
if (first_digit==0U) {
86+
if (b==0U) {
87+
continue;
88+
} else if (b>0xfU) {
89+
s.push_back(hex_char[b >> 4]);
90+
} else {
91+
/* nothing to do here */
9692
}
9793
s.push_back(hex_char[b & 0xf]);
9894
first_digit = b;

src/big_int.hpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
#ifndef BIG_INT_HPP
2-
#define BIG_INT_HPP
1+
#ifndef OC_ISSUER_BIG_INT_HPP
2+
#define OC_ISSUER_BIG_INT_HPP
33

44
#include <string>
55
#include <array>
@@ -9,19 +9,19 @@
99
struct BigInt {
1010

1111
BigInt() : data() {}
12-
virtual ~BigInt() {}
12+
virtual ~BigInt() = default;
1313

1414
enum class eError : uint8_t { PARSE_ERROR };
1515
static tl::expected<BigInt, eError> from_string(const std::string &str);
1616

1717
static BigInt from_int(uint64_t value);
18-
std::string to_string() const;
18+
[[nodiscard]] std::string to_string() const;
1919

2020
friend bool operator == (const BigInt& rhs, const BigInt& lhs);
2121
private:
22-
std::array<uint8_t,256> data;
22+
std::array<uint8_t,256U> data;
2323
};
2424

2525
bool operator==(const BigInt &rhs, const BigInt &lhs);
2626

27-
#endif // #ifndef #ifndef BIG_INT_HPP
27+
#endif // #ifndef #ifndef OC_ISSUER_BIG_INT_HPP

src/json_serialisation.cpp

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -10,16 +10,18 @@
1010
template <class T>
1111
crow::json::wvalue list_to_json(const std::vector<T> &array) {
1212
crow::json::wvalue::list l;
13-
for (auto item : array)
13+
for (const auto& item : array) {
1414
l.push_back(item.to_json());
15-
return crow::json::wvalue(l);
15+
}
16+
return {l};
1617
}
1718

1819
crow::json::wvalue list_to_json(const std::vector<unsigned int> &array) {
1920
crow::json::wvalue::list l;
20-
for (auto item : array)
21-
l.push_back(item);
22-
return crow::json::wvalue(l);
21+
for (auto item : array) {
22+
l.emplace_back(item);
23+
}
24+
return {l};
2325
}
2426

2527
crow::json::wvalue PublicKey::to_json() const {
@@ -35,7 +37,7 @@ crow::json::wvalue WeightedUrl::to_json() const {
3537
crow::json::wvalue w(weight);
3638

3739
l.push_back(w);
38-
l.push_back(url);
40+
l.emplace_back(url);
3941
return l;
4042
}
4143

@@ -171,15 +173,15 @@ RequestMKCs::from_string(const std::string &str) {
171173
if (denominations.t() != crow::json::type::List) {
172174
return tl::make_unexpected(eError::JSON_WRONG_REQUEST_TYPE);
173175
} else {
174-
for (auto d : denominations.lo()) {
176+
for (const auto& d : denominations.lo()) {
175177
r.denominations.push_back(d.u());
176178
}
177179
}
178180
auto mint_key_ids = json["mint_key_ids"];
179181
if (mint_key_ids.t() != crow::json::type::List) {
180182
return tl::make_unexpected(eError::JSON_WRONG_REQUEST_TYPE);
181183
} else {
182-
for (auto k: mint_key_ids.lo()) {
184+
for (const auto& k: mint_key_ids.lo()) {
183185
auto kv = BigInt::from_string(k.s());
184186
if (!kv.has_value()) {
185187
return tl::make_unexpected(eError::JSON_PARSE_ERROR);
@@ -269,7 +271,7 @@ RequestMint::from_string(const std::string &str) {
269271
return tl::make_unexpected(eError::JSON_WRONG_VALUE_TYPE);
270272
}
271273

272-
for (auto item : json["blinds"]) {
274+
for (const auto& item : json["blinds"]) {
273275
auto b = Blind::from_json(item);
274276
if (!b.has_value()) {
275277
return tl::make_unexpected(b.error());
@@ -384,7 +386,7 @@ RequestRenew::from_string(const std::string &str) {
384386
} else {
385387
RequestRenew r;
386388

387-
for (auto item : json["coins"]) {
389+
for (const auto& item : json["coins"]) {
388390
auto coin = Coin::from_json(item);
389391
if (!coin.has_value()) {
390392
return tl::make_unexpected(coin.error());
@@ -393,7 +395,7 @@ RequestRenew::from_string(const std::string &str) {
393395
}
394396
}
395397

396-
for (auto item : json["blinds"]) {
398+
for (const auto& item : json["blinds"]) {
397399
auto blind = Blind::from_json(item);
398400
if (!blind.has_value()) {
399401
return tl::make_unexpected(blind.error());
@@ -453,7 +455,7 @@ RequestRedeem::from_string(const std::string &str) {
453455
return tl::make_unexpected(eError::JSON_WRONG_VALUE_TYPE);
454456
}
455457

456-
for (auto item : json["coins"]) {
458+
for (const auto& item : json["coins"]) {
457459
auto coin = Coin::from_json(item);
458460
if (!coin.has_value()) {
459461
return tl::make_unexpected(coin.error());

src/main.cpp

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,22 @@
11
#include "crow.h"
22
#include "crow/common.h"
3-
#include "crow/http_parser_merged.h"
43
#include "crow/http_response.h"
54
#include "model.hpp"
65

76
int main() {
87
crow::SimpleApp app;
9-
std::shared_ptr<Model> model = Model::getModel("simple");
8+
std::shared_ptr<Model> model = Model::get_model("simple");
109

1110
CROW_ROUTE(app, "/cddc")
12-
.methods(crow::HTTPMethod::POST)([&model](const crow::request &req) {
11+
.methods(crow::HTTPMethod::POST)
12+
([&model](const crow::request &req) {
1313
auto req_cddc = RequestCDDC::from_string(req.body);
1414
if (!req_cddc) {
1515
return crow::response(crow::status::BAD_REQUEST);
1616
} else {
1717
ResponseCDDC res;
1818
res.message_reference = req_cddc->message_reference;
19-
auto cddc = model->getCDDC(req_cddc->cdd_serial);
19+
auto cddc = model->get_cddc(req_cddc->cdd_serial);
2020
if (!cddc) {
2121
res.status_code = crow::status::NOT_FOUND;
2222
} else {
@@ -36,7 +36,7 @@ int main() {
3636
ResponseCDDCSerial res;
3737
res.message_reference = req->message_reference;
3838

39-
auto cddc = model->getCurrentCDDC();
39+
auto cddc = model->get_current_cddc();
4040
if (!cddc) {
4141
res.status_code = crow::status::NOT_FOUND;
4242
} else {
@@ -47,8 +47,8 @@ int main() {
4747
}
4848
});
4949

50-
CROW_ROUTE(app, "/mkcs")
51-
.methods(crow::HTTPMethod::POST)([&model](const crow::request &request) {
50+
CROW_ROUTE(app, "/mkcs").methods(crow::HTTPMethod::POST)
51+
([&model](const crow::request &request) {
5252
auto req = RequestMKCs::from_string(request.body);
5353
if (!req) {
5454
return crow::response(crow::status::BAD_REQUEST);
@@ -61,17 +61,18 @@ int main() {
6161
}
6262
});
6363

64-
CROW_ROUTE(app, "/mint")
65-
.methods(crow::HTTPMethod::POST)([&model](const crow::request &request) {
64+
CROW_ROUTE(app, "/mint").methods(crow::HTTPMethod::POST)
65+
([&model](const crow::request &request) {
6666
auto req = RequestMint::from_string(request.body);
6767
if (!req) {
6868
return crow::response(crow::status::BAD_REQUEST);
6969
} else {
7070
ResponseMint res;
7171
res.message_reference = req->message_reference;
7272

73-
/// \todo change argument transaction_reference to bigint
74-
auto minted = model->mint(req->transaction_reference.to_string(), req->blinds);
73+
/// \todo change argument transaction_reference to bigint
74+
auto minted =
75+
model->mint(req->transaction_reference.to_string(), req->blinds);
7576

7677
res.blind_signatures = minted;
7778
res.status_code = crow::status::OK;

0 commit comments

Comments
 (0)