in src/azure_base64.c [130:187]
static void Base64decode(unsigned char *decodedString, const char *base64String)
{
size_t numberOfEncodedChars;
size_t indexOfFirstEncodedChar;
size_t decodedIndex;
//
// We can only operate on individual bytes. If we attempt to work
// on anything larger we could get an alignment fault on some
// architectures
//
numberOfEncodedChars = numberOfBase64Characters(base64String);
indexOfFirstEncodedChar = 0;
decodedIndex = 0;
while (numberOfEncodedChars >= 4)
{
unsigned char c1;
unsigned char c2;
unsigned char c3;
unsigned char c4;
(void)base64toValue(base64String[indexOfFirstEncodedChar], &c1);
(void)base64toValue(base64String[indexOfFirstEncodedChar + 1], &c2);
(void)base64toValue(base64String[indexOfFirstEncodedChar + 2], &c3);
(void)base64toValue(base64String[indexOfFirstEncodedChar + 3], &c4);
decodedString[decodedIndex] = (c1 << 2) | (c2 >> 4);
decodedIndex++;
decodedString[decodedIndex] = ((c2 & 0x0f) << 4) | (c3 >> 2);
decodedIndex++;
decodedString[decodedIndex] = ((c3 & 0x03) << 6) | c4;
decodedIndex++;
numberOfEncodedChars -= 4;
indexOfFirstEncodedChar += 4;
}
if (numberOfEncodedChars == 2)
{
unsigned char c1;
unsigned char c2;
(void)base64toValue(base64String[indexOfFirstEncodedChar], &c1);
(void)base64toValue(base64String[indexOfFirstEncodedChar + 1], &c2);
decodedString[decodedIndex] = (c1 << 2) | (c2 >> 4);
}
else if (numberOfEncodedChars == 3)
{
unsigned char c1;
unsigned char c2;
unsigned char c3;
(void)base64toValue(base64String[indexOfFirstEncodedChar], &c1);
(void)base64toValue(base64String[indexOfFirstEncodedChar + 1], &c2);
(void)base64toValue(base64String[indexOfFirstEncodedChar + 2], &c3);
decodedString[decodedIndex] = (c1 << 2) | (c2 >> 4);
decodedIndex++;
decodedString[decodedIndex] = ((c2 & 0x0f) << 4) | (c3 >> 2);
}
}