Skip to content

Commit 94ac8f4

Browse files
Razvan Becheriutmarkwalder
Razvan Becheriu
authored andcommitted
[#3209] addressed review
1 parent 51d67d6 commit 94ac8f4

File tree

3 files changed

+44
-44
lines changed

3 files changed

+44
-44
lines changed

src/lib/util/encode/encode.cc

+7-7
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ BaseNEncoder::bitsToDigit(uint8_t bits) {
5050
<< static_cast<uint16_t>(bits) << " invalid for " << algorithm_);
5151
}
5252

53-
return(digit_set_[bits]);
53+
return (digit_set_[bits]);
5454
}
5555

5656
uint8_t
@@ -60,14 +60,14 @@ BaseNEncoder::digitToBits(uint8_t digit) {
6060
<< static_cast<uint16_t>(digit) << " for " << algorithm_);
6161
}
6262

63-
return(bits_table_[digit]);
63+
return (bits_table_[digit]);
6464
}
6565

6666
std::string
6767
BaseNEncoder::encode(const std::vector<uint8_t>& input) {
6868
std::string encoded_output;
6969
if (input.empty()) {
70-
return(encoded_output);
70+
return (encoded_output);
7171
}
7272

7373
uint8_t cur_bit = 0x0;
@@ -130,7 +130,7 @@ BaseNEncoder::encode(const std::vector<uint8_t>& input) {
130130
}
131131
}
132132

133-
return(encoded_output);
133+
return (encoded_output);
134134
}
135135

136136
void
@@ -301,7 +301,7 @@ const std::vector<uint8_t> Base16Encoder::BITS_TABLE = {
301301
string
302302
encodeBase64(const vector<uint8_t>& binary) {
303303
static Base64Encoder encoder;
304-
return(encoder.encode(binary));
304+
return (encoder.encode(binary));
305305
}
306306

307307
void
@@ -313,7 +313,7 @@ decodeBase64 (const std::string& encoded_str, std::vector<uint8_t>& output) {
313313
string
314314
encodeBase32Hex(const vector<uint8_t>& binary) {
315315
static Base32HexEncoder encoder;
316-
return(encoder.encode(binary));
316+
return (encoder.encode(binary));
317317
}
318318

319319
void
@@ -325,7 +325,7 @@ decodeBase32Hex(const std::string& encoded_str, std::vector<uint8_t>& output) {
325325
string
326326
encodeHex(const vector<uint8_t>& binary) {
327327
static Base16Encoder encoder;
328-
return(encoder.encode(binary));
328+
return (encoder.encode(binary));
329329
}
330330

331331
void

src/lib/util/encode/encode.h

+18-18
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,9 @@ class BaseNEncoder {
2929
/// @param digits_per_group number of digits contained in a group
3030
/// @param pad_char character used for padding out to group size (0 means no
3131
/// padding)
32-
/// @param max_pad maximum number of pad characters in a group
32+
/// @param max_pad maximum number of pad characters in a group
3333
/// @param case_sensitive indicates if the algorithm's digit set is
34-
/// case sensitive.
34+
/// case sensitive
3535
BaseNEncoder(const std::string& algorithm,
3636
const char* digit_set,
3737
const std::vector<uint8_t>& bits_table,
@@ -79,71 +79,71 @@ class BaseNEncoder {
7979
///
8080
/// @return string containing the algorithm name
8181
std::string getAlgorithm() const {
82-
return(algorithm_);
82+
return (algorithm_);
8383
}
8484

8585
/// @brief Get the digit set
8686
///
8787
/// @return string containing the set of digits
8888
const char* getDigitSet() const {
89-
return(digit_set_);
89+
return (digit_set_);
9090
}
9191

9292
/// @brief Get the digit lookup table
9393
///
9494
/// @return vector containing the lookup table
9595
const std::vector<uint8_t>& getBitsTable() const {
96-
return(bits_table_);
96+
return (bits_table_);
9797
}
9898

9999
/// @brief Get the number of data bits represented by a digit
100100
///
101101
/// @return number of data bits per digit
102102
size_t getBitsPerDigit() {
103-
return(bits_per_digit_);
103+
return (bits_per_digit_);
104104
}
105105

106106
/// @brief Get the number of digits contained in a group
107107
///
108108
/// @return number of digits per group
109109
size_t getDigitsPerGroup() const {
110-
return(digits_per_group_);
110+
return (digits_per_group_);
111111
}
112112

113113
/// @brief Get the character used for padding out to group size (0 means no padding)
114114
///
115115
/// @return Character used as a pad byte
116116
uint8_t getPadChar() const {
117-
return(pad_char_);
117+
return (pad_char_);
118118
}
119119

120120
/// @brief Get the maximum number of pad characters in a group
121121
///
122122
/// @return Maximum number of pad characters
123123
size_t getMaxPad() {
124-
return(max_pad_);
124+
return (max_pad_);
125125
}
126126

127127
/// @brief Get the maxium index value of the digit set
128128
///
129129
/// @return Maxium index value of the digit set
130130
size_t getMaxBitsToDigit() {
131-
return(max_bits_to_digit_);
131+
return (max_bits_to_digit_);
132132
}
133133

134134
/// @brief Get the maxium index value of the algorithm bit table
135135
///
136136
/// @return Maxium index value of the algorithm bit table
137137
size_t getMaxDigitToBits() {
138-
return(max_digit_to_bits_);
138+
return (max_digit_to_bits_);
139139
}
140140

141141
/// @brief Indicates whether or not the algorithm's digit set
142142
/// is case-sensitive.
143143
///
144-
/// @return true if the digit set is case-sensitive.
144+
/// @return true if the digit set is case-sensitive, false otherwise
145145
bool isCaseSensitive() {
146-
return(case_sensitive_);
146+
return (case_sensitive_);
147147
}
148148

149149
protected:
@@ -157,7 +157,7 @@ class BaseNEncoder {
157157
///
158158
/// The table must map all 256 ASCII chars to their corresponding
159159
/// algorithm-specific data value. A data value of 0xee marks
160-
/// a char as whitespace, 0xff marks a char is invalid.
160+
/// a char as whitespace, 0xff marks a char is invalid
161161
std::vector<uint8_t>bits_table_;
162162

163163
/// @brief Number of data bits represented by a digit
@@ -172,7 +172,7 @@ class BaseNEncoder {
172172
/// @brief Maximum number of pad characters in a group
173173
size_t max_pad_;
174174

175-
/// @brief Indicates whether or not the algorithm's digit set is case-sensitive.
175+
/// @brief Indicates whether or not the algorithm's digit set is case-sensitive
176176
bool case_sensitive_;
177177

178178
/// @brief Maxium index value of the digit set
@@ -278,10 +278,10 @@ std::string encodeHex(const std::vector<uint8_t>& binary);
278278
/// @throw BadValue if the input string is invalid.
279279
void decodeHex(const std::string& encoded_str, std::vector<uint8_t>& output);
280280

281-
/// @brief Encode in hexadecimal inline
281+
/// @brief Encode in hexadecimal inline.
282282
///
283-
/// @param value the value to encode
284-
/// @return 0x followed by the value encoded in hex
283+
/// @param value the value to encode.
284+
/// @return 0x followed by the value encoded in hex.
285285
inline std::string toHex(std::string value) {
286286
std::vector<uint8_t> bin(value.begin(), value.end());
287287
return ("0x" + encodeHex(bin));

src/lib/util/tests/encode_unittest.cc

+19-19
Original file line numberDiff line numberDiff line change
@@ -23,17 +23,17 @@ using namespace isc::util::encode;
2323

2424
namespace {
2525

26-
/// @brief Defines a pointer to BaseNEncoder instances
26+
/// @brief Defines a pointer to BaseNEncoder instances.
2727
typedef boost::shared_ptr<BaseNEncoder> BaseNEncoderPtr;
2828

29-
/// @brief Defines a encoding function.
29+
/// @brief Defines an encoding function.
3030
typedef std::function<std::string (const std::vector<uint8_t>&)> EncodeFunc;
3131

3232
/// @brief Defines a decoding function.
3333
typedef std::function<void (const std::string&, std::vector<uint8_t>&)> DecodeFunc;
3434

35-
/// @brief Test fixture fro exercising BaseNEncoder derivatives.
36-
class EncodeDecodeTest : public :: testing::Test {
35+
/// @brief Test fixture for exercising BaseNEncoder derivatives.
36+
class EncodeDecodeTest : public ::testing::Test {
3737
public:
3838

3939
/// @brief Constructor
@@ -75,7 +75,7 @@ class EncodeDecodeTest : public :: testing::Test {
7575
// -# convert the encoded result to lower case and verify decoding
7676
// yields correct result.
7777
auto expected_output_str = expected_encoded_strings_.begin();
78-
for ( const auto& input : valid_input_strings_ ) {
78+
for (auto const& input : valid_input_strings_) {
7979
std::vector<uint8_t>input_data(input.begin(), input.end());
8080
std::string output_str;
8181
ASSERT_NO_THROW_LOG(output_str = (encode_func_)(input_data));
@@ -105,7 +105,7 @@ class EncodeDecodeTest : public :: testing::Test {
105105

106106
ASSERT_EQ(encoded_strings.size(), expected_strings.size());
107107
auto expected_str = expected_strings.begin();
108-
for ( const auto& encoded_str : encoded_strings ) {
108+
for (auto const& encoded_str : encoded_strings) {
109109
std::vector<uint8_t> decoded_output;
110110
ASSERT_NO_THROW_LOG((decode_func_)(encoded_str, decoded_output));
111111
std::string tmp(decoded_output.begin(), decoded_output.end());
@@ -119,7 +119,7 @@ class EncodeDecodeTest : public :: testing::Test {
119119
///
120120
/// @param encoded_strings list of invalid encoded strings
121121
void decodeInvalid(std::vector<std::string>& encoded_strings) {
122-
for ( const auto& encoded_str : encoded_strings ) {
122+
for (auto const& encoded_str : encoded_strings) {
123123
std::vector<uint8_t> decoded_output;
124124
EXPECT_THROW((decode_func_)(encoded_str, decoded_output), BadValue);
125125
}
@@ -284,12 +284,12 @@ TEST_F(Base64Test, whiteSpace) {
284284
// Verify invalid encodings are handled properly in Base64
285285
TEST_F(Base64Test, decodeInvalid) {
286286
std::vector<std::string> encoded_strings = {
287-
// incomplete input
287+
// Incomplete input.
288288
"Zm9vYmF",
289-
// only up to 2 padding characters are allowed
289+
// Only up to 2 padding characters are allowed.
290290
"A===",
291291
"A= ==",
292-
// intermediate padding isn't allowed
292+
// Intermediate padding isn't allowed.
293293
"YmE=YmE=",
294294
// Non canonical form isn't allowed.
295295
"Zm9=",
@@ -304,11 +304,6 @@ TEST_F(Base64Test, mappingCheck) {
304304
mapTest();
305305
}
306306

307-
// Verify mappings for Base32Hex
308-
TEST_F(Base32HexTest, mappingCheck) {
309-
mapTest();
310-
}
311-
312307
// Verify RFC test vectors for Base32Hex
313308
TEST_F(Base32HexTest, validEncodeDecode) {
314309
encodeDecode();
@@ -336,13 +331,13 @@ TEST_F(Base32HexTest, whiteSpace) {
336331
// Verify invalid encodings are handled properly in Base32Hex
337332
TEST_F(Base32HexTest, decodeInvalid) {
338333
std::vector<std::string> encoded_strings = {
339-
// Incomplete input
334+
// Incomplete input.
340335
"CPNMUOJ",
341-
// invalid number of padding characters
336+
// Invalid number of padding characters.
342337
"CPNMU0==",
343338
"CO0=====",
344339
"CO=======",
345-
// intermediate padding isn't allowed
340+
// Intermediate padding isn't allowed.
346341
"CPNMUOG=CPNMUOG=",
347342
// Non canonical form isn't allowed.
348343
"0P======"
@@ -351,6 +346,11 @@ TEST_F(Base32HexTest, decodeInvalid) {
351346
decodeInvalid(encoded_strings);
352347
}
353348

349+
// Verify mappings for Base32Hex
350+
TEST_F(Base32HexTest, mappingCheck) {
351+
mapTest();
352+
}
353+
354354
// Verify RFC test vectors for Base16
355355
TEST_F(Base16Test, validEncodeDecode) {
356356
encodeDecode();
@@ -378,7 +378,7 @@ TEST_F(Base16Test, whiteSpace) {
378378
// Verify invalid encodings are handled properly in Base16
379379
TEST_F(Base16Test, decodeInvalid) {
380380
std::vector<std::string> encoded_strings = {
381-
// Non hex digits should fail
381+
// Non hex digits should fail.
382382
"lx",
383383
// Encoded string must have an even number of characters.
384384
"dea"

0 commit comments

Comments
 (0)