]> git.ipfire.org Git - thirdparty/kea.git/commitdiff
[#3209] addressed review
authorRazvan Becheriu <razvan@isc.org>
Tue, 6 Feb 2024 16:56:27 +0000 (18:56 +0200)
committerThomas Markwalder <tmark@isc.org>
Wed, 7 Feb 2024 13:58:47 +0000 (13:58 +0000)
src/lib/util/encode/encode.cc
src/lib/util/encode/encode.h
src/lib/util/tests/encode_unittest.cc

index ed63c11cc4ea44e8150eb1db74999517420e49ea..baab625a60e93fad450755c2b22b526367599551 100644 (file)
@@ -50,7 +50,7 @@ BaseNEncoder::bitsToDigit(uint8_t bits) {
                   << static_cast<uint16_t>(bits) << " invalid for " << algorithm_);
     }
 
-    return(digit_set_[bits]);
+    return (digit_set_[bits]);
 }
 
 uint8_t
@@ -60,14 +60,14 @@ BaseNEncoder::digitToBits(uint8_t digit) {
                   << static_cast<uint16_t>(digit) << " for " << algorithm_);
     }
 
-    return(bits_table_[digit]);
+    return (bits_table_[digit]);
 }
 
 std::string
 BaseNEncoder::encode(const std::vector<uint8_t>& input) {
     std::string encoded_output;
     if (input.empty()) {
-        return(encoded_output);
+        return (encoded_output);
     }
 
     uint8_t cur_bit = 0x0;
@@ -130,7 +130,7 @@ BaseNEncoder::encode(const std::vector<uint8_t>& input) {
         }
     }
 
-    return(encoded_output);
+    return (encoded_output);
 }
 
 void
@@ -301,7 +301,7 @@ const std::vector<uint8_t> Base16Encoder::BITS_TABLE = {
 string
 encodeBase64(const vector<uint8_t>& binary) {
     static Base64Encoder encoder;
-    return(encoder.encode(binary));
+    return (encoder.encode(binary));
 }
 
 void
@@ -313,7 +313,7 @@ decodeBase64 (const std::string& encoded_str, std::vector<uint8_t>& output) {
 string
 encodeBase32Hex(const vector<uint8_t>& binary) {
     static Base32HexEncoder encoder;
-    return(encoder.encode(binary));
+    return (encoder.encode(binary));
 }
 
 void
@@ -325,7 +325,7 @@ decodeBase32Hex(const std::string& encoded_str, std::vector<uint8_t>& output) {
 string
 encodeHex(const vector<uint8_t>& binary) {
     static Base16Encoder encoder;
-    return(encoder.encode(binary));
+    return (encoder.encode(binary));
 }
 
 void
index 13d3c3e96e880ca4370a32e7932a3fb24c6659cf..0f8933685923bc12de36f0d10567f8dd9466bfc2 100644 (file)
@@ -29,9 +29,9 @@ public:
     /// @param digits_per_group number of digits contained in a group
     /// @param pad_char character used for padding out to group size (0 means no
     /// padding)
-    /// @param max_pad maximum  number of pad characters in a group
+    /// @param max_pad maximum number of pad characters in a group
     /// @param case_sensitive indicates if the algorithm's digit set is
-    /// case sensitive.
+    /// case sensitive
     BaseNEncoder(const std::string& algorithm,
                  const char* digit_set,
                  const std::vector<uint8_t>& bits_table,
@@ -79,71 +79,71 @@ public:
     ///
     /// @return string containing the algorithm name
     std::string getAlgorithm() const {
-        return(algorithm_);
+        return (algorithm_);
     }
 
     /// @brief Get the digit set
     ///
     /// @return string containing the set of digits
     const char* getDigitSet() const {
-        return(digit_set_);
+        return (digit_set_);
     }
 
     /// @brief Get the digit lookup table
     ///
     /// @return vector containing the lookup table
     const std::vector<uint8_t>& getBitsTable() const {
-        return(bits_table_);
+        return (bits_table_);
     }
 
     /// @brief Get the number of data bits represented by a digit
     ///
     /// @return number of data bits per digit
     size_t getBitsPerDigit() {
-        return(bits_per_digit_);
+        return (bits_per_digit_);
     }
 
     /// @brief Get the number of digits contained in a group
     ///
     /// @return number of digits per group
     size_t getDigitsPerGroup() const {
-        return(digits_per_group_);
+        return (digits_per_group_);
     }
 
     /// @brief Get the character used for padding out to group size (0 means no padding)
     ///
     /// @return Character used as a pad byte
     uint8_t getPadChar() const {
-        return(pad_char_);
+        return (pad_char_);
     }
 
     /// @brief Get the maximum number of pad characters in a group
     ///
     /// @return Maximum number of pad characters
     size_t getMaxPad() {
-        return(max_pad_);
+        return (max_pad_);
     }
 
     /// @brief Get the maxium index value of the digit set
     ///
     /// @return Maxium index value of the digit set
     size_t getMaxBitsToDigit() {
-        return(max_bits_to_digit_);
+        return (max_bits_to_digit_);
     }
 
     /// @brief Get the maxium index value of the algorithm bit table
     ///
     /// @return Maxium index value of the algorithm bit table
     size_t getMaxDigitToBits() {
-        return(max_digit_to_bits_);
+        return (max_digit_to_bits_);
     }
 
     /// @brief Indicates whether or not the algorithm's digit set
     /// is case-sensitive.
     ///
-    /// @return true if the digit set is case-sensitive.
+    /// @return true if the digit set is case-sensitive, false otherwise
     bool isCaseSensitive() {
-        return(case_sensitive_);
+        return (case_sensitive_);
     }
 
 protected:
@@ -157,7 +157,7 @@ protected:
     ///
     /// The table must map all 256 ASCII chars to their corresponding
     /// algorithm-specific data value.  A data value of 0xee marks
-    /// a char as whitespace, 0xff marks a char is invalid.
+    /// a char as whitespace, 0xff marks a char is invalid
     std::vector<uint8_t>bits_table_;
 
     /// @brief Number of data bits represented by a digit
@@ -172,7 +172,7 @@ protected:
     /// @brief Maximum number of pad characters in a group
     size_t max_pad_;
 
-    /// @brief Indicates whether or not the algorithm's digit set is case-sensitive.
+    /// @brief Indicates whether or not the algorithm's digit set is case-sensitive
     bool case_sensitive_;
 
     /// @brief Maxium index value of the digit set
@@ -278,10 +278,10 @@ std::string encodeHex(const std::vector<uint8_t>& binary);
 /// @throw BadValue if the input string is invalid.
 void decodeHex(const std::string& encoded_str, std::vector<uint8_t>& output);
 
-/// @brief Encode in hexadecimal inline
+/// @brief Encode in hexadecimal inline.
 ///
-/// @param value the value to encode
-/// @return 0x followed by the value encoded in hex
+/// @param value the value to encode.
+/// @return 0x followed by the value encoded in hex.
 inline std::string toHex(std::string value) {
     std::vector<uint8_t> bin(value.begin(), value.end());
     return ("0x" + encodeHex(bin));
index d90963db6b54cd41f091046130ffa7b05de749cc..7e2c8bedead04a84069fe19fc4ec8a70dc34417d 100644 (file)
@@ -23,17 +23,17 @@ using namespace isc::util::encode;
 
 namespace {
 
-/// @brief Defines a pointer to BaseNEncoder instances
+/// @brief Defines a pointer to BaseNEncoder instances.
 typedef boost::shared_ptr<BaseNEncoder> BaseNEncoderPtr;
 
-/// @brief Defines a encoding function.
+/// @brief Defines an encoding function.
 typedef std::function<std::string (const std::vector<uint8_t>&)> EncodeFunc;
 
 /// @brief Defines a decoding function.
 typedef std::function<void (const std::string&, std::vector<uint8_t>&)> DecodeFunc;
 
-/// @brief Test fixture fro exercising BaseNEncoder derivatives.
-class EncodeDecodeTest : public :: testing::Test {
+/// @brief Test fixture for exercising BaseNEncoder derivatives.
+class EncodeDecodeTest : public ::testing::Test {
 public:
 
     /// @brief Constructor
@@ -75,7 +75,7 @@ public:
         // -# convert the encoded result to lower case and verify decoding
         // yields correct result.
         auto expected_output_str = expected_encoded_strings_.begin();
-        for ( const auto& input : valid_input_strings_ ) {
+        for (auto const& input : valid_input_strings_) {
             std::vector<uint8_t>input_data(input.begin(), input.end());
             std::string output_str;
             ASSERT_NO_THROW_LOG(output_str = (encode_func_)(input_data));
@@ -105,7 +105,7 @@ public:
 
         ASSERT_EQ(encoded_strings.size(), expected_strings.size());
         auto expected_str = expected_strings.begin();
-        for ( const auto& encoded_str : encoded_strings ) {
+        for (auto const& encoded_str : encoded_strings) {
             std::vector<uint8_t> decoded_output;
             ASSERT_NO_THROW_LOG((decode_func_)(encoded_str, decoded_output));
             std::string tmp(decoded_output.begin(), decoded_output.end());
@@ -119,7 +119,7 @@ public:
     ///
     /// @param encoded_strings list of invalid encoded strings
     void decodeInvalid(std::vector<std::string>& encoded_strings) {
-        for ( const auto& encoded_str : encoded_strings ) {
+        for (auto const& encoded_str : encoded_strings) {
             std::vector<uint8_t> decoded_output;
             EXPECT_THROW((decode_func_)(encoded_str, decoded_output), BadValue);
         }
@@ -284,12 +284,12 @@ TEST_F(Base64Test, whiteSpace) {
 // Verify invalid encodings are handled properly in Base64
 TEST_F(Base64Test, decodeInvalid) {
     std::vector<std::string> encoded_strings = {
-        // incomplete input
+        // Incomplete input.
         "Zm9vYmF",
-        // only up to 2 padding characters are allowed
+        // Only up to 2 padding characters are allowed.
         "A===",
         "A= ==",
-        // intermediate padding isn't allowed
+        // Intermediate padding isn't allowed.
         "YmE=YmE=",
         // Non canonical form isn't allowed.
         "Zm9=",
@@ -304,11 +304,6 @@ TEST_F(Base64Test, mappingCheck) {
     mapTest();
 }
 
-// Verify mappings for Base32Hex
-TEST_F(Base32HexTest, mappingCheck) {
-    mapTest();
-}
-
 // Verify RFC test vectors for Base32Hex
 TEST_F(Base32HexTest, validEncodeDecode) {
     encodeDecode();
@@ -336,13 +331,13 @@ TEST_F(Base32HexTest, whiteSpace) {
 // Verify invalid encodings are handled properly in Base32Hex
 TEST_F(Base32HexTest, decodeInvalid) {
     std::vector<std::string> encoded_strings = {
-        // Incomplete input
+        // Incomplete input.
         "CPNMUOJ",
-        // invalid number of padding characters
+        // Invalid number of padding characters.
         "CPNMU0==",
         "CO0=====",
         "CO=======",
-        // intermediate padding isn't allowed
+        // Intermediate padding isn't allowed.
         "CPNMUOG=CPNMUOG=",
         // Non canonical form isn't allowed.
         "0P======"
@@ -351,6 +346,11 @@ TEST_F(Base32HexTest, decodeInvalid) {
     decodeInvalid(encoded_strings);
 }
 
+// Verify mappings for Base32Hex
+TEST_F(Base32HexTest, mappingCheck) {
+    mapTest();
+}
+
 // Verify RFC test vectors for Base16
 TEST_F(Base16Test, validEncodeDecode) {
     encodeDecode();
@@ -378,7 +378,7 @@ TEST_F(Base16Test, whiteSpace) {
 // Verify invalid encodings are handled properly in Base16
 TEST_F(Base16Test, decodeInvalid) {
     std::vector<std::string> encoded_strings = {
-        // Non hex digits should fail
+        // Non hex digits should fail.
         "lx",
         // Encoded string must have an even number of characters.
         "dea"