#include <dns/master_lexer.h>
+#include <string>
#include <vector>
#include <stdint.h>
void strToCharString(const MasterToken::StringRegion& str_region,
CharString& result);
+/// \brief Convert a CharString into a textual DNS character-string.
+///
+/// This method converts a binary 8-bit representation of a DNS
+/// character string into a textual string representation, escaping any
+/// special characters in the process. For example, characters like
+/// double-quotes, semi-colon and backspace are prefixed with backspace
+/// character, and characters not in the printable range of [0x20, 0x7e]
+/// (inclusive) are converted to the \xxx 3-digit decimal
+/// representation.
+///
+/// \param char_string The \c CharString to convert.
+/// \return A string representation of \c char_string.
+std::string charStringToString(const CharString& char_string);
+
} // namespace detail
} // namespace generic
} // namespace rdata
using namespace isc::dns::rdata;
using isc::dns::rdata::generic::detail::CharString;
using isc::dns::rdata::generic::detail::strToCharString;
+using isc::dns::rdata::generic::detail::charStringToString;
using isc::util::unittests::matchWireData;
namespace {
InvalidRdataText);
}
+TEST_F(CharStringTest, charStringToString) {
+ const uint8_t double_quotes_buf[] = {
+ sizeof("Test\"Test\"") - 1,
+ 'T', 'e', 's', 't', '"', 'T', 'e', 's', 't', '"'
+ };
+ const CharString double_quotes
+ (double_quotes_buf, double_quotes_buf + sizeof(double_quotes_buf));
+ EXPECT_EQ("Test\\\"Test\\\"",
+ charStringToString(double_quotes));
+
+ const uint8_t semicolon_buf[] = {
+ sizeof("Test;Test") - 1,
+ 'T', 'e', 's', 't', ';', 'T', 'e', 's', 't'
+ };
+ const CharString semicolon
+ (semicolon_buf, semicolon_buf + sizeof(semicolon_buf));
+ EXPECT_EQ("Test\\;Test",
+ charStringToString(semicolon));
+
+ const uint8_t backslash_buf[] = {
+ sizeof("Test\\Test") - 1,
+ 'T', 'e', 's', 't', '\\', 'T', 'e', 's', 't'
+ };
+ const CharString backslash
+ (backslash_buf, backslash_buf + sizeof(backslash_buf));
+ EXPECT_EQ("Test\\\\Test",
+ charStringToString(backslash));
+
+ const uint8_t before_x20_buf[] = {
+ sizeof("Test\x1fTest") - 1,
+ 'T', 'e', 's', 't', 0x1f, 'T', 'e', 's', 't'
+ };
+ const CharString before_x20
+ (before_x20_buf, before_x20_buf + sizeof(before_x20_buf));
+ EXPECT_EQ("Test\\031Test",
+ charStringToString(before_x20));
+
+ const uint8_t from_x20_to_x7e_buf[] = {
+ sizeof("Test ~ Test") - 1,
+ 'T', 'e', 's', 't', ' ', '~', ' ', 'T', 'e', 's', 't'
+ };
+ const CharString from_x20_to_x7e
+ (from_x20_to_x7e_buf,
+ from_x20_to_x7e_buf + sizeof(from_x20_to_x7e_buf));
+ EXPECT_EQ("Test ~ Test",
+ charStringToString(from_x20_to_x7e));
+
+ const uint8_t after_0x7e_buf[] = {
+ sizeof("Test\x7fTest") - 1,
+ 'T', 'e', 's', 't', 0x7f, 'T', 'e', 's', 't'
+ };
+ const CharString after_0x7e
+ (after_0x7e_buf, after_0x7e_buf + sizeof(after_0x7e_buf));
+ EXPECT_EQ("Test\\127Test",
+ charStringToString(after_0x7e));
+}
+
} // unnamed namespace