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] &= (
unsigned char)~((1 << (8 - bit_offset)) - 1);
46 d[byte_offset] |= (
unsigned char)(idx << (2 - bit_offset));
49 d[byte_offset] |= (
unsigned char)(idx >> (bit_offset - 2));
50 d[byte_offset + 1] = (
unsigned char)(idx << (8 - (bit_offset - 2)));
60void rs_base64(
unsigned char const *buf,
int n,
char *out)
63 "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
67 bytes = ((n * 8) + 5) / 6;
69 for (i = 0; i < bytes; i++) {
70 int byte = (i * 6) / 8;
71 int bit = (i * 6) % 8;
76 *out = b64[(buf[byte] >> (2 - bit)) & 0x3F];
79 *out = b64[(buf[byte] << (bit - 2)) & 0x3F];
82 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.