proxygen
proxygen::StructuredHeadersStandardTest Class Reference
Inheritance diagram for proxygen::StructuredHeadersStandardTest:
testing::Test proxygen::IllegalItemTest proxygen::IllegalListTest proxygen::LegalBinaryContentTests proxygen::LegalFloatTests proxygen::LegalIntegerTests proxygen::LegalStringTests

Public Member Functions

bool decode32 (std::string input, std::string &output)
 
- Public Member Functions inherited from testing::Test
virtual ~Test ()
 
virtual ~Test ()
 
virtual ~Test ()
 

Private Member Functions

std::string convertBase32ToBinary (const std::string &input)
 
bool decode32Block (std::string input, uint32_t blockNum, std::string &outputBuffer)
 

Additional Inherited Members

- Public Types inherited from testing::Test
typedef internal::SetUpTestCaseFunc SetUpTestCaseFunc
 
typedef internal::TearDownTestCaseFunc TearDownTestCaseFunc
 
typedef internal::SetUpTestCaseFunc SetUpTestCaseFunc
 
typedef internal::TearDownTestCaseFunc TearDownTestCaseFunc
 
typedef internal::SetUpTestCaseFunc SetUpTestCaseFunc
 
typedef internal::TearDownTestCaseFunc TearDownTestCaseFunc
 
- Static Public Member Functions inherited from testing::Test
static void SetUpTestCase ()
 
static void TearDownTestCase ()
 
static bool HasFatalFailure ()
 
static bool HasNonfatalFailure ()
 
static bool HasFailure ()
 
static void RecordProperty (const std::string &key, const std::string &value)
 
static void RecordProperty (const std::string &key, int value)
 
static void SetUpTestCase ()
 
static void TearDownTestCase ()
 
static bool HasFatalFailure ()
 
static bool HasNonfatalFailure ()
 
static bool HasFailure ()
 
static void RecordProperty (const std::string &key, const std::string &value)
 
static void RecordProperty (const std::string &key, int value)
 
static void SetUpTestCase ()
 
static void TearDownTestCase ()
 
static bool HasFatalFailure ()
 
static bool HasNonfatalFailure ()
 
static bool HasFailure ()
 
static void RecordProperty (const std::string &key, const std::string &value)
 
static void RecordProperty (const std::string &key, int value)
 
- Protected Member Functions inherited from testing::Test
 Test ()
 
virtual void SetUp ()
 
virtual void TearDown ()
 
 Test ()
 
virtual void SetUp ()
 
virtual void TearDown ()
 
 Test ()
 
virtual void SetUp ()
 
virtual void TearDown ()
 

Detailed Description

Definition at line 86 of file StructuredHeadersStandardTest.cpp.

Member Function Documentation

std::string proxygen::StructuredHeadersStandardTest::convertBase32ToBinary ( const std::string input)
inlineprivate

Definition at line 130 of file StructuredHeadersStandardTest.cpp.

References c, gmock_output_test::output, and string.

Referenced by decode32Block().

130  {
131  std::string base32CharSet("ABCDEFGHIJKLMNOPQRSTUVWXYZ234567");
133 
134  for (char c : input) {
135  auto it = base32CharSet.find(c);
136  if (it == std::string::npos) {
137  return "";
138  } else {
139  // foundCharacter is the position within the base32CharSet where c
140  // was found
141  char foundCharacter = char(it);
142  output.push_back(foundCharacter);
143  }
144  }
145 
146  return output;
147  }
const char * string
Definition: Conv.cpp:212
char c
bool proxygen::StructuredHeadersStandardTest::decode32 ( std::string  input,
std::string output 
)
inline

Definition at line 89 of file StructuredHeadersStandardTest.cpp.

References decode32Block(), i, string, and uint32_t.

Referenced by proxygen::TEST_P().

89  {
90 
91  uint32_t numBlocks = input.length() / 8;
92  uint32_t blockRemainder = input.length() % 8;
93 
94  std::string outputBuffer(5, '\0');
95 
96  // decode each whole block of the input
97  for (uint32_t j = 0; j < numBlocks; j++) {
98  if (!decode32Block(input, j, outputBuffer)) {
99  return false;
100  }
101  output += outputBuffer;
102  }
103 
104  std::string padding(8, '\0');
105  // set the initial bytes of the padding to be the trailing bytes of the
106  // input string that have been left over
107  for (uint32_t i = 0; i < blockRemainder; i++) {
108  padding[i] = input[input.size() - blockRemainder + i];
109  }
110 
111  if (!decode32Block(padding, 0, outputBuffer)) {
112  return false;
113  }
114 
115  // The second argument to the function is the size of the decoded content,
116  // where the encoded content is of size (blockRemainder * 5) / 8
117  outputBuffer = outputBuffer.substr(0, (blockRemainder * 5) / 8);
118  output += outputBuffer;
119 
120  return true;
121  }
bool decode32Block(std::string input, uint32_t blockNum, std::string &outputBuffer)
const char * string
Definition: Conv.cpp:212
bool proxygen::StructuredHeadersStandardTest::decode32Block ( std::string  input,
uint32_t  blockNum,
std::string outputBuffer 
)
inlineprivate

Definition at line 156 of file StructuredHeadersStandardTest.cpp.

References buffer(), c, convertBase32ToBinary(), i, and int64_t.

Referenced by decode32().

158  {
159 
160  // Remove any padding and make each character of the input represent the
161  // byte value of that character, as per the rfc4648 encoding
162  boost::trim_right_if(input, [](char c){return c == '=';});
163  input = convertBase32ToBinary(input);
164 
165  // 8 byte buffer
166  int64_t buffer = 0;
167 
168  for(int i = 0; i < 8; i++) {
169 
170  if(input[i + blockNum * 8] >= 32) {
171  // a base32 value cannot be greater than or equal to 32
172  return false;
173  }
174 
175  buffer = (buffer << 5);
176  buffer = buffer | input[i + blockNum * 8];
177  }
178 
179  // set the contents of outputBuffer to contain the contents of buffer
180  for (int i = 0; i < 5; i++) {
181  outputBuffer[i] = char(buffer & 0xFF);
182  buffer = buffer >> 8;
183  }
184  // we perform a reversal because outputBuffer has the contents of buffer
185  // but in reverse order
186  std::reverse(outputBuffer.begin(), outputBuffer.end());
187 
188  return true;
189  }
std::vector< uint8_t > buffer(kBufferSize+16)
std::string convertBase32ToBinary(const std::string &input)
char c

The documentation for this class was generated from the following file: