OmniSciDB  343343d194
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
mapd Namespace Reference

Functions

std::string decode_base64_uri (const std::string &data, bool trim_nulls)
 
std::string decode_base64 (const std::string &val, bool trim_nulls)
 
std::string decode_base64 (const std::string &val)
 
static std::string encode_base64 (const std::string &val)
 

Function Documentation

std::string mapd::decode_base64 ( const std::string &  val,
bool  trim_nulls 
)
inline

Definition at line 26 of file base64.h.

References anonymous_namespace{ExecuteTest.cpp}::c().

Referenced by decode_base64(), decode_base64_uri(), anonymous_namespace{omnisql.cpp}::get_license_claims(), and anonymous_namespace{omnisql.cpp}::set_license_key().

26  {
27  // For some strings, signatature particualary it is important no to trim
28  // '\0' characters
29  using namespace boost::archive::iterators;
30  using It = transform_width<binary_from_base64<std::string::const_iterator>, 8, 6>;
31 
32  if (!trim_nulls) {
33  return std::string(It(val.begin()), It(val.end()));
34  }
35  return boost::algorithm::trim_right_copy_if(
36  std::string(It(std::begin(val)), It(std::end(val))),
37  [](char c) { return c == '\0'; });
38 }
void c(const std::string &query_string, const ExecutorDeviceType device_type)

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

std::string mapd::decode_base64 ( const std::string &  val)
inline

Definition at line 40 of file base64.h.

References decode_base64().

40  {
41  return decode_base64(val, true);
42 }
std::string decode_base64(const std::string &val, bool trim_nulls)
Definition: base64.h:26

+ Here is the call graph for this function:

std::string mapd::decode_base64_uri ( const std::string &  data,
bool  trim_nulls 
)

Definition at line 20 of file base64.cpp.

References anonymous_namespace{ExecuteTest.cpp}::c(), and decode_base64().

20  {
21  // Allocate a string large enough to hold exta '=' as padding
22  std::string uri_dec;
23  size_t data_len = data.length();
24  // base64_uri encoding removes '=' padding at the end of the string.
25  size_t padding = 4 - (data_len % 4);
26  if (padding == 4) {
27  padding = 0;
28  }
29  uri_dec.resize(data_len + padding);
30 
31  // base64_uri encoding replaces all '+' and '/' with '-' and '_' respectively.
32  std::transform(
33  data.begin(), data.end(), uri_dec.begin(), [](unsigned char c) -> unsigned char {
34  switch (c) {
35  case '-':
36  return '+';
37  case '_':
38  return '/';
39  default:
40  return c;
41  }
42  });
43  if (padding != 0) {
44  uri_dec.replace(uri_dec.begin() + data_len, uri_dec.end(), padding, '=');
45  }
46  // in the case of a signature from a JWT trim_nulls should be false
47  return mapd::decode_base64(uri_dec, trim_nulls);
48 }
void c(const std::string &query_string, const ExecutorDeviceType device_type)
std::string decode_base64(const std::string &val, bool trim_nulls)
Definition: base64.h:26

+ Here is the call graph for this function:

static std::string mapd::encode_base64 ( const std::string &  val)
inlinestatic

Definition at line 44 of file base64.h.

44  {
45  using namespace boost::archive::iterators;
46  using It = base64_from_binary<transform_width<std::string::const_iterator, 6, 8>>;
47  auto tmp = std::string(It(std::begin(val)), It(std::end(val)));
48  return tmp.append((3 - val.size() % 3) % 3, '=');
49 }