33 "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
34 int bit_offset, byte_offset, idx, i, n;
35 unsigned char *d = (
unsigned char *)s;
40 while (*s && (p = strchr(b64, *s))) {
42 byte_offset = (i * 6) / 8;
43 bit_offset = (i * 6) % 8;
44 d[byte_offset] &= ~((1 << (8 - bit_offset)) - 1);
46 d[byte_offset] |= (idx << (2 - bit_offset));
49 d[byte_offset] |= (idx >> (bit_offset - 2));
50 d[byte_offset + 1] = 0;
51 d[byte_offset + 1] |= (idx << (8 - (bit_offset - 2))) & 0xFF;
62 void rs_base64(
unsigned char const *buf,
int n,
char *out)
65 "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
69 bytes = ((n * 8) + 5) / 6;
71 for (i = 0; i < bytes; i++) {
72 int byte = (i * 6) / 8;
73 int bit = (i * 6) % 8;
78 *out = b64[(buf[byte] >> (2 - bit)) & 0x3F];
81 *out = b64[(buf[byte] << (bit - 2)) & 0x3F];
84 b64[(buf[byte] << (bit - 2) | buf[
byte + 1] >> (10 - bit)) &
Public header for librsync.
LIBRSYNC_EXPORT void rs_base64(unsigned char const *buf, int n, char *out)
Encode a buffer as base64.
LIBRSYNC_EXPORT size_t rs_unbase64(char *s)
Decode a base64 buffer in place.