<< static_cast<uint16_t>(bits) << " invalid for " << algorithm_);
}
- return(digit_set_[bits]);
+ return (digit_set_[bits]);
}
uint8_t
<< 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;
}
}
- return(encoded_output);
+ return (encoded_output);
}
void
string
encodeBase64(const vector<uint8_t>& binary) {
static Base64Encoder encoder;
- return(encoder.encode(binary));
+ return (encoder.encode(binary));
}
void
string
encodeBase32Hex(const vector<uint8_t>& binary) {
static Base32HexEncoder encoder;
- return(encoder.encode(binary));
+ return (encoder.encode(binary));
}
void
string
encodeHex(const vector<uint8_t>& binary) {
static Base16Encoder encoder;
- return(encoder.encode(binary));
+ return (encoder.encode(binary));
}
void
/// @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,
///
/// @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:
///
/// 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
/// @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
/// @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));
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
// -# 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));
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());
///
/// @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);
}
// 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=",
mapTest();
}
-// Verify mappings for Base32Hex
-TEST_F(Base32HexTest, mappingCheck) {
- mapTest();
-}
-
// Verify RFC test vectors for Base32Hex
TEST_F(Base32HexTest, validEncodeDecode) {
encodeDecode();
// 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======"
decodeInvalid(encoded_strings);
}
+// Verify mappings for Base32Hex
+TEST_F(Base32HexTest, mappingCheck) {
+ mapTest();
+}
+
// Verify RFC test vectors for Base16
TEST_F(Base16Test, validEncodeDecode) {
encodeDecode();
// 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"