CMS 3D CMS Logo

Functions | Variables
PixelBase64.cc File Reference
#include "CalibFormats/SiPixelObjects/interface/PixelBase64.h"
#include <iostream>

Go to the source code of this file.

Functions

std::string base64_decode (std::string const &encoded_string)
 
std::string base64_encode (unsigned char const *bytes_to_encode, unsigned int in_len)
 
static bool is_base64 (unsigned char c)
 

Variables

static const std::string base64_chars
 

Function Documentation

◆ base64_decode()

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

Definition at line 78 of file PixelBase64.cc.

References base64_chars, mps_fire::i, is_base64(), dqmiolumiharvest::j, runTheMatrix::ret, and AlCaHLTBitMon_QueryRunRegistry::string.

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

◆ base64_encode()

std::string base64_encode ( unsigned char const *  bytes_to_encode,
unsigned int  in_len 
)

Definition at line 38 of file PixelBase64.cc.

References base64_chars, mps_fire::i, dqmiolumiharvest::j, runTheMatrix::ret, and AlCaHLTBitMon_QueryRunRegistry::string.

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

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

◆ is_base64()

static bool is_base64 ( unsigned char  c)
inlinestatic

Definition at line 36 of file PixelBase64.cc.

References HltBtagPostValidation_cff::c.

Referenced by base64_decode().

36 { return (isalnum(c) || (c == '+') || (c == '/')); }

Variable Documentation

◆ base64_chars

const std::string base64_chars
static
Initial value:
=
"ABCDEFGHIJKLMNOPQRSTUVWXYZ"
"abcdefghijklmnopqrstuvwxyz"
"0123456789+/"

Definition at line 31 of file PixelBase64.cc.

Referenced by base64_decode(), and base64_encode().