MCPcopy Create free account
hub / github.com/SIPp/sipp / base64_decode_string

Function base64_decode_string

src/auth.cpp:717–760  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

715}
716
717static char* base64_decode_string(const char* buf, unsigned int len, int* newlen)
718{
719 unsigned long i;
720 int j, x1, x2, x3, x4;
721 char *out;
722 out = (char *)malloc( ( len * 3/4 ) + 8 );
723 for(i=0, j=0; i + 3 < len; i += 4) {
724 x1=base64_val(buf[i]);
725 x2=base64_val(buf[i+1]);
726 x3=base64_val(buf[i+2]);
727 x4=base64_val(buf[i+3]);
728 out[j++]=(x1<<2) | ((x2 & 0x30)>>4);
729 out[j++]=((x2 & 0x0F)<<4) | ((x3 & 0x3C)>>2);
730 out[j++]=((x3 & 0x03)<<6) | (x4 & 0x3F);
731 }
732 if (i<len) {
733 x1 = base64_val(buf[i]);
734 if (i+1<len)
735 x2=base64_val(buf[i+1]);
736 else
737 x2=-1;
738 if (i+2<len)
739 x3=base64_val(buf[i+2]);
740 else
741 x3=-1;
742 if(i+3<len)
743 x4=base64_val(buf[i+3]);
744 else x4=-1;
745 if (x2!=-1) {
746 out[j++]=(x1<<2) | ((x2 & 0x30)>>4);
747 if (x3==-1) {
748 out[j++]=((x2 & 0x0F)<<4) | ((x3 & 0x3C)>>2);
749 if (x4==-1) {
750 out[j++]=((x3 & 0x03)<<6) | (x4 & 0x3F);
751 }
752 }
753 }
754
755 }
756
757 out[j++] = 0;
758 *newlen=j;
759 return out;
760}
761
762char base64[65] = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
763

Callers 1

createAuthHeaderAKAv1MD5Function · 0.85

Calls 1

base64_valFunction · 0.85

Tested by

no test coverage detected