CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
Functions
PixelBase64.h File Reference
#include <string>

Go to the source code of this file.

Functions

std::string base64_decode (std::string const &s)
 
std::string base64_encode (unsigned char const *, unsigned int len)
 

Function Documentation

std::string base64_decode ( std::string const &  s)

Definition at line 84 of file PixelBase64.cc.

References base64_chars, i, is_base64(), j, and run_regression::ret.

84  {
85  int in_len = encoded_string.size();
86  int i = 0;
87  int j = 0;
88  int in_ = 0;
89  unsigned char char_array_4[4], char_array_3[3];
90  std::string ret;
91 
92  while (in_len-- && ( encoded_string[in_] != '=') && is_base64(encoded_string[in_])) {
93  char_array_4[i++] = encoded_string[in_]; in_++;
94  if (i ==4) {
95  for (i = 0; i <4; i++)
96  char_array_4[i] = base64_chars.find(char_array_4[i]);
97 
98  char_array_3[0] = (char_array_4[0] << 2) + ((char_array_4[1] & 0x30) >> 4);
99  char_array_3[1] = ((char_array_4[1] & 0xf) << 4) + ((char_array_4[2] & 0x3c) >> 2);
100  char_array_3[2] = ((char_array_4[2] & 0x3) << 6) + char_array_4[3];
101 
102  for (i = 0; (i < 3); i++)
103  ret += char_array_3[i];
104  i = 0;
105  }
106  }
107 
108  if (i) {
109  for (j = i; j <4; j++)
110  char_array_4[j] = 0;
111 
112  for (j = 0; j <4; j++)
113  char_array_4[j] = base64_chars.find(char_array_4[j]);
114 
115  char_array_3[0] = (char_array_4[0] << 2) + ((char_array_4[1] & 0x30) >> 4);
116  char_array_3[1] = ((char_array_4[1] & 0xf) << 4) + ((char_array_4[2] & 0x3c) >> 2);
117  char_array_3[2] = ((char_array_4[2] & 0x3) << 6) + char_array_4[3];
118 
119  for (j = 0; (j < i - 1); j++) ret += char_array_3[j];
120  }
121 
122  return ret;
123 }
int i
Definition: DBlmapReader.cc:9
static const std::string base64_chars
Definition: PixelBase64.cc:31
static bool is_base64(unsigned char c)
Definition: PixelBase64.cc:37
int j
Definition: DBlmapReader.cc:9
std::string base64_encode ( unsigned char const *  ,
unsigned int  len 
)

Definition at line 41 of file PixelBase64.cc.

References base64_chars, i, j, and run_regression::ret.

Referenced by base64_encode_alloc(), pos::PixelConfigBase::getComment(), pos::PixelROCMaskBits::writeXML(), and pos::PixelROCTrimBits::writeXML().

41  {
42  std::string ret;
43  int i = 0;
44  int j = 0;
45  unsigned char char_array_3[3];
46  unsigned char char_array_4[4];
47 
48  while (in_len--) {
49  char_array_3[i++] = *(bytes_to_encode++);
50  if (i == 3) {
51  char_array_4[0] = (char_array_3[0] & 0xfc) >> 2;
52  char_array_4[1] = ((char_array_3[0] & 0x03) << 4) + ((char_array_3[1] & 0xf0) >> 4);
53  char_array_4[2] = ((char_array_3[1] & 0x0f) << 2) + ((char_array_3[2] & 0xc0) >> 6);
54  char_array_4[3] = char_array_3[2] & 0x3f;
55 
56  for(i = 0; (i <4) ; i++)
57  ret += base64_chars[char_array_4[i]];
58  i = 0;
59  }
60  }
61 
62  if (i)
63  {
64  for(j = i; j < 3; j++)
65  char_array_3[j] = '\0';
66 
67  char_array_4[0] = (char_array_3[0] & 0xfc) >> 2;
68  char_array_4[1] = ((char_array_3[0] & 0x03) << 4) + ((char_array_3[1] & 0xf0) >> 4);
69  char_array_4[2] = ((char_array_3[1] & 0x0f) << 2) + ((char_array_3[2] & 0xc0) >> 6);
70  char_array_4[3] = char_array_3[2] & 0x3f;
71 
72  for (j = 0; (j < i + 1); j++)
73  ret += base64_chars[char_array_4[j]];
74 
75  while((i++ < 3))
76  ret += '=';
77 
78  }
79 
80  return ret;
81 
82 }
int i
Definition: DBlmapReader.cc:9
static const std::string base64_chars
Definition: PixelBase64.cc:31
int j
Definition: DBlmapReader.cc:9