MCPcopy Index your code
hub / github.com/RsyncProject/rsync / base64_encode

Function base64_encode

authenticate.c:33–58  ·  view source on GitHub ↗

encode a buffer using base64 - simple and slow algorithm. null terminates the result. ***************************************************************************/

Source from the content-addressed store, hash-verified

31the result.
32 ***************************************************************************/
33void base64_encode(const char *buf, int len, char *out, int pad)
34{
35 char *b64 = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
36 int bit_offset, byte_offset, idx, i;
37 const uchar *d = (const uchar *)buf;
38 int bytes = (len*8 + 5)/6;
39
40 for (i = 0; i < bytes; i++) {
41 byte_offset = (i*6)/8;
42 bit_offset = (i*6)%8;
43 if (bit_offset < 3) {
44 idx = (d[byte_offset] >> (2-bit_offset)) & 0x3F;
45 } else {
46 idx = (d[byte_offset] << (bit_offset-2)) & 0x3F;
47 if (byte_offset+1 < len) {
48 idx |= (d[byte_offset+1] >> (8-(bit_offset-2)));
49 }
50 }
51 out[i] = b64[idx];
52 }
53
54 while (pad && (i % 4))
55 out[i++] = '=';
56
57 out[i] = '\0';
58}
59
60/* Generate a challenge buffer and return it base64-encoded. */
61static void gen_challenge(const char *addr, char *challenge)

Callers 3

gen_challengeFunction · 0.85
generate_hashFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected