Browse Source

Fix clang-tidy issues

Signed-off-by: Igor Egorov <igor@soramitsu.co.jp>
pull/99/head
Igor Egorov 3 years ago
parent
commit
964f0f98b8
  1. 6
      src/common/hexutil.cpp
  2. 23
      src/crypto/common_functions.cpp
  3. 7
      src/crypto/hmac_provider/hmac_provider_ctr_impl.cpp
  4. 4
      src/crypto/key_marshaller/key_marshaller_impl.cpp
  5. 6
      src/security/noise/handshake_message_marshaller_impl.cpp
  6. 17
      src/security/noise/noise_connection.cpp

6
src/common/hexutil.cpp

@ -3,6 +3,8 @@
* SPDX-License-Identifier: Apache-2.0
*/
#include <ios>
#include <libp2p/common/hexutil.hpp>
#include <boost/algorithm/hex.hpp>
@ -24,13 +26,13 @@ namespace libp2p::common {
std::string int_to_hex(uint64_t n, size_t fixed_width) noexcept {
std::stringstream result;
result.width(fixed_width);
result.width(static_cast<std::streamsize>(fixed_width));
result.fill('0');
result << std::hex << std::uppercase << n;
auto str = result.str();
if (str.length() % 2 != 0) {
str.push_back('\0');
for (int64_t i = str.length() - 2; i >= 0; --i) {
for (int64_t i = static_cast<int64_t>(str.length()) - 2; i >= 0; --i) {
str[i + 1] = str[i];
}
str[0] = '0';

23
src/crypto/common_functions.cpp

@ -25,8 +25,8 @@ namespace libp2p::crypto {
}
// turn private key bytes into big number
BIGNUM *private_bignum{
BN_bin2bn(private_key.data(), private_key.size(), nullptr)};
BIGNUM *private_bignum{BN_bin2bn(
private_key.data(), static_cast<int>(private_key.size()), nullptr)};
if (nullptr == private_bignum) {
return FAILED;
}
@ -92,10 +92,11 @@ namespace libp2p::crypto {
int, gsl::span<const uint8_t>, decltype(EVP_PKEY_new_raw_public_key) *);
outcome::result<std::vector<uint8_t>> GenerateEcSignature(
gsl::span<const uint8_t> digest,
const std::shared_ptr<EC_KEY> &key) {
gsl::span<const uint8_t> digest, const std::shared_ptr<EC_KEY> &key) {
std::shared_ptr<ECDSA_SIG> signature{
ECDSA_do_sign(digest.data(), digest.size(), key.get()), ECDSA_SIG_free};
ECDSA_do_sign(digest.data(), static_cast<int>(digest.size()),
key.get()),
ECDSA_SIG_free};
if (signature == nullptr) {
return CryptoProviderError::SIGNATURE_GENERATION_FAILED;
}
@ -110,12 +111,12 @@ namespace libp2p::crypto {
return std::move(signature_bytes);
}
outcome::result<bool> VerifyEcSignature(
gsl::span<const uint8_t> digest,
gsl::span<const uint8_t> signature,
const std::shared_ptr<EC_KEY> &key) {
int result = ECDSA_verify(0, digest.data(), digest.size(), signature.data(),
signature.size(), key.get());
outcome::result<bool> VerifyEcSignature(gsl::span<const uint8_t> digest,
gsl::span<const uint8_t> signature,
const std::shared_ptr<EC_KEY> &key) {
int result = ECDSA_verify(0, digest.data(), static_cast<int>(digest.size()),
signature.data(),
static_cast<int>(signature.size()), key.get());
if (result < 0) {
return CryptoProviderError::SIGNATURE_VERIFICATION_FAILED;
}

7
src/crypto/hmac_provider/hmac_provider_ctr_impl.cpp

@ -40,7 +40,8 @@ namespace libp2p::crypto::hmac {
return;
}
initialized_ = 1
== HMAC_Init_ex(hmac_ctx_, key_.data(), key_.size(), hash_st_, nullptr);
== HMAC_Init_ex(hmac_ctx_, key_.data(), static_cast<int>(key_.size()),
hash_st_, nullptr);
}
HmacProviderCtrImpl::~HmacProviderCtrImpl() {
@ -87,8 +88,8 @@ namespace libp2p::crypto::hmac {
hmac_ctx_ = HMAC_CTX_new();
if (nullptr == hmac_ctx_
or 1
!= HMAC_Init_ex(hmac_ctx_, key_.data(), key_.size(), hash_st_,
nullptr)) {
!= HMAC_Init_ex(hmac_ctx_, key_.data(),
static_cast<int>(key_.size()), hash_st_, nullptr)) {
return HmacProviderError::FAILED_INITIALIZE_CONTEXT;
}
initialized_ = true;

4
src/crypto/key_marshaller/key_marshaller_impl.cpp

@ -84,7 +84,7 @@ namespace libp2p::crypto::marshaller {
const ProtobufKey &proto_key) const {
protobuf::PublicKey protobuf_key;
if (!protobuf_key.ParseFromArray(proto_key.key.data(),
proto_key.key.size())) {
static_cast<int>(proto_key.key.size()))) {
return CryptoProviderError::FAILED_UNMARSHAL_DATA;
}
@ -101,7 +101,7 @@ namespace libp2p::crypto::marshaller {
const ProtobufKey &proto_key) const {
protobuf::PublicKey protobuf_key;
if (!protobuf_key.ParseFromArray(proto_key.key.data(),
proto_key.key.size())) {
static_cast<int>(proto_key.key.size()))) {
return CryptoProviderError::FAILED_UNMARSHAL_DATA;
}

6
src/security/noise/handshake_message_marshaller_impl.cpp

@ -59,7 +59,8 @@ namespace libp2p::security::noise {
const HandshakeMessage &msg) const {
OUTCOME_TRY(proto_msg, handyToProto(msg));
common::ByteArray out_msg(proto_msg.ByteSizeLong());
if (not proto_msg.SerializeToArray(out_msg.data(), out_msg.size())) {
if (not proto_msg.SerializeToArray(out_msg.data(),
static_cast<int>(out_msg.size()))) {
return Error::MESSAGE_SERIALIZING_ERROR;
}
return out_msg;
@ -69,7 +70,8 @@ namespace libp2p::security::noise {
HandshakeMessageMarshallerImpl::unmarshal(
gsl::span<const uint8_t> msg_bytes) const {
protobuf::NoiseHandshakePayload proto_msg;
if (not proto_msg.ParseFromArray(msg_bytes.data(), msg_bytes.size())) {
if (not proto_msg.ParseFromArray(msg_bytes.data(),
static_cast<int>(msg_bytes.size()))) {
return Error::MESSAGE_DESERIALIZING_ERROR;
}
return protoToHandy(proto_msg);

17
src/security/noise/noise_connection.cpp

@ -97,7 +97,7 @@ namespace libp2p::connection {
if (not frame_buffer_->empty()) {
auto n{std::min(bytes, frame_buffer_->size())};
auto begin{frame_buffer_->begin()};
auto end{begin + n};
auto end{begin + static_cast<int64_t>(n)};
std::copy(begin, end, out.begin());
frame_buffer_->erase(begin, end);
return cb(n);
@ -137,13 +137,14 @@ namespace libp2p::connection {
write_buffers_.emplace(write_buffers_.end(), dummy_size, dummy_value);
}
ctx.write_buffer->swap(encrypted);
framer_->write(*ctx.write_buffer,
[self{shared_from_this()}, in{in.subspan(n)},
bytes{bytes - n}, cb{std::move(cb)}, ctx](auto _n) mutable {
OUTCOME_CB(n, _n);
ctx.bytes_served += n;
self->write(in, bytes, ctx, std::move(cb));
});
framer_->write(
*ctx.write_buffer,
[self{shared_from_this()}, in{in.subspan(static_cast<int64_t>(n))},
bytes{bytes - n}, cb{std::move(cb)}, ctx](auto _n) mutable {
OUTCOME_CB(n, _n);
ctx.bytes_served += n;
self->write(in, bytes, ctx, std::move(cb));
});
}
void NoiseConnection::writeSome(gsl::span<const uint8_t> in, size_t bytes,

Loading…
Cancel
Save