Fix clang-tidy issues 21/320621/1
authorKrzysztof Malysa <k.malysa@samsung.com>
Tue, 19 Nov 2024 12:10:56 +0000 (13:10 +0100)
committerKrzysztof Malysa <k.malysa@samsung.com>
Tue, 19 Nov 2024 12:10:56 +0000 (13:10 +0100)
Change-Id: I6a55c3bf1c320b7e187c7c4389086f3757e6a64d

srcs/crypto/ec_key.cpp
srcs/crypto/openssl_error.h
tests/bluetooth_tests.cpp
tests/message_tests.cpp

index 1b5e71695a64bb850561a01d4e9543719e93935c..9e467c4a53477d044d1cfc39d852d2cad41e1b28 100644 (file)
@@ -56,7 +56,7 @@ ECKey::~ECKey() { EVP_PKEY_free(m_key); }
 ECKey ECKey::Create(Curve curve)
 {
     EVP_PKEY *pkeyTmp = nullptr;
-    std::unique_ptr<EVP_PKEY_CTX, decltype(&EVP_PKEY_CTX_free)> ctx(
+    const std::unique_ptr<EVP_PKEY_CTX, decltype(&EVP_PKEY_CTX_free)> ctx(
         EVP_PKEY_CTX_new_id(EVP_PKEY_EC, nullptr), EVP_PKEY_CTX_free);
     if (!ctx)
         THROW_OPENSSL("EVP_PKEY_CTX_new_id() error");
@@ -82,7 +82,7 @@ ECKey ECKey::ImportPrivateKey(Curve curve, const CryptoBuffer &input)
     if (!ec)
         THROW_OPENSSL("EC_KEY_new() error");
 
-    std::unique_ptr<EC_GROUP, decltype(&EC_GROUP_clear_free)> group(
+    const std::unique_ptr<EC_GROUP, decltype(&EC_GROUP_clear_free)> group(
         EC_GROUP_new_by_curve_name(Curve2NID(curve)), EC_GROUP_clear_free);
     if (!group)
         THROW_OPENSSL("EC_GROUP_new_by_curve_name() error");
@@ -94,8 +94,8 @@ ECKey ECKey::ImportPrivateKey(Curve curve, const CryptoBuffer &input)
     if (EC_KEY_oct2priv(ec.get(), input.data(), input.size()) != 1)
         THROW_OPENSSL("EC_KEY_oct2priv() error");
 
-    std::unique_ptr<EC_POINT, decltype(&EC_POINT_clear_free)> point(EC_POINT_new(group.get()),
-                                                                    EC_POINT_clear_free);
+    const std::unique_ptr<EC_POINT, decltype(&EC_POINT_clear_free)> point(EC_POINT_new(group.get()),
+                                                                          EC_POINT_clear_free);
     if (!point)
         THROW_OPENSSL("EC_POINT_new() error");
 
@@ -111,8 +111,7 @@ ECKey ECKey::ImportPrivateKey(Curve curve, const CryptoBuffer &input)
 
     if (EVP_PKEY_assign_EC_KEY(pkey.get(), ec.get()) != 1)
         THROW_OPENSSL("EVP_PKEY_assign_EC_KEY() error");
-
-    ec.release();
+    (void)ec.release();
 
     return ECKey{pkey.release()};
 }
@@ -127,7 +126,7 @@ ECKey ECKey::ImportPublicKey(Curve curve, const CryptoBuffer &input)
     if (!ec)
         THROW_OPENSSL("EC_KEY_new() error");
 
-    std::unique_ptr<EC_GROUP, decltype(&EC_GROUP_clear_free)> group(
+    const std::unique_ptr<EC_GROUP, decltype(&EC_GROUP_clear_free)> group(
         EC_GROUP_new_by_curve_name(Curve2NID(curve)), EC_GROUP_clear_free);
     if (!group)
         THROW_OPENSSL("EC_GROUP_new_by_curve_name() error");
@@ -141,19 +140,18 @@ ECKey ECKey::ImportPublicKey(Curve curve, const CryptoBuffer &input)
 
     if (EVP_PKEY_assign_EC_KEY(pkey.get(), ec.get()) != 1)
         THROW_OPENSSL("EVP_PKEY_assign_EC_KEY() error");
-
-    ec.release();
+    (void)ec.release();
 
     return ECKey{pkey.release()};
 }
 
 ECKey ECKey::ImportPublicKey(Curve curve, const CryptoBuffer &x, const CryptoBuffer &y)
 {
-    std::unique_ptr<BIGNUM, decltype(&BN_free)> bx(BN_new(), BN_free);
+    const std::unique_ptr<BIGNUM, decltype(&BN_free)> bx(BN_new(), BN_free);
     if (!bx)
         THROW_OPENSSL("BN_new() error");
 
-    std::unique_ptr<BIGNUM, decltype(&BN_free)> by(BN_new(), BN_free);
+    const std::unique_ptr<BIGNUM, decltype(&BN_free)> by(BN_new(), BN_free);
     if (!by)
         THROW_OPENSSL("BN_new() error");
 
@@ -176,8 +174,7 @@ ECKey ECKey::ImportPublicKey(Curve curve, const CryptoBuffer &x, const CryptoBuf
 
     if (EVP_PKEY_assign_EC_KEY(evpKey.get(), ecKey.get()) != 1)
         THROW_OPENSSL("EVP_PKEY_assign_EC_KEY() failed");
-
-    ecKey.release();
+    (void)ecKey.release();
 
     return ECKey{evpKey.release()};
 }
index 3556dcacfb4147de5466bc98d3efd2ade0cdbaa7..f186321aa86f9a755fc6a2bb4883ae7292dc31de 100644 (file)
 
 #include <exception>
 #include <string>
+#include <utility>
 
 namespace Crypto {
 
 class OpensslError : public std::exception {
 public:
-    explicit OpensslError(const std::string &messageIn) : message(messageIn) {}
+    explicit OpensslError(std::string msg) : message(std::move(msg)) {}
 
     [[nodiscard]] const char *what() const noexcept override { return message.c_str(); }
 
index 07fb911077bd2dfa30497a649752cf28e0a0451a..eea1c621d707afbb448ef2d84b71304b551ef370 100644 (file)
@@ -496,7 +496,7 @@ TEST(UnpackDecryptedAdvert, first_byte_is_non_0_Negative)
 
 TEST(UnpackDecryptedAdvert, validate_bluetooth_errors_Positive)
 {
-    std::map<int, std::string> errors = {
+    const std::map<int, std::string> errors = {
         {BT_ERROR_NONE,                        "BT_ERROR_NONE"                       },
         {BT_ERROR_CANCELLED,                   "BT_ERROR_CANCELLED"                  },
         {BT_ERROR_INVALID_PARAMETER,           "BT_ERROR_INVALID_PARAMETER"          },
index 906a479af4268d3a64447dd8953e85418182d563..d09b244eacaa28f77b561ba99721d6f4f9caa07f 100644 (file)
@@ -767,15 +767,15 @@ TEST(Messages, ParseUpdateMessage_Positive)
 TEST(Messages, MakeCredentialResponse_Negative)
 {
     MakeCredentialResponse msg;
-    auto cborUnexpectedType = BUFFER_VIEW("\x11");
-    auto errorProcessing = BUFFER_VIEW("\x21");
-    auto unsupportedAlgorithm = BUFFER_VIEW("\x26");
-    auto missingParameter = BUFFER_VIEW("\x14");
-    auto operationDenied = BUFFER_VIEW("\x27");
-    auto keyStoreFull = BUFFER_VIEW("\x28");
-    auto userActionTimeout = BUFFER_VIEW("\x2F");
-    auto pinBlocked = BUFFER_VIEW("\x32");
-    auto credentialExcluded = BUFFER_VIEW("\x19");
+    auto cborUnexpectedType = BUFFER_VIEW("\x11");   // NOLINT(modernize-raw-string-literal)
+    auto errorProcessing = BUFFER_VIEW("\x21");      // NOLINT(modernize-raw-string-literal)
+    auto unsupportedAlgorithm = BUFFER_VIEW("\x26"); // NOLINT(modernize-raw-string-literal)
+    auto missingParameter = BUFFER_VIEW("\x14");     // NOLINT(modernize-raw-string-literal)
+    auto operationDenied = BUFFER_VIEW("\x27");      // NOLINT(modernize-raw-string-literal)
+    auto keyStoreFull = BUFFER_VIEW("\x28");         // NOLINT(modernize-raw-string-literal)
+    auto userActionTimeout = BUFFER_VIEW("\x2F");    // NOLINT(modernize-raw-string-literal)
+    auto pinBlocked = BUFFER_VIEW("\x32");           // NOLINT(modernize-raw-string-literal)
+    auto credentialExcluded = BUFFER_VIEW("\x19");   // NOLINT(modernize-raw-string-literal)
     EXPECT_THROW(msg.Deserialize(cborUnexpectedType), Exception::EncodingFailed);
     EXPECT_THROW(msg.Deserialize(errorProcessing), Exception::InvalidState);
     EXPECT_THROW(msg.Deserialize(unsupportedAlgorithm), Exception::NotSupported);