29size_t rs_unbase64(
char *s)
32 "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
33 int bit_offset, byte_offset, idx, i, n;
34 unsigned char *d = (
unsigned char *)s;
39 while (*s && (p = strchr(b64, *s))) {
41 byte_offset = (i * 6) / 8;
42 bit_offset = (i * 6) % 8;
43 d[byte_offset] &= (
unsigned char)~((1 << (8 - bit_offset)) - 1);
45 d[byte_offset] |= (
unsigned char)(idx << (2 - bit_offset));
48 d[byte_offset] |= (
unsigned char)(idx >> (bit_offset - 2));
49 d[byte_offset + 1] = (
unsigned char)(idx << (8 - (bit_offset - 2)));
59void rs_base64(
unsigned char const *buf,
int n,
char *out)
62 "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
66 bytes = ((n * 8) + 5) / 6;
68 for (i = 0; i < bytes; i++) {
69 int byte = (i * 6) / 8;
70 int bit = (i * 6) % 8;
75 *out = b64[(buf[byte] >> (2 - bit)) & 0x3F];
78 *out = b64[(buf[byte] << (bit - 2)) & 0x3F];
81 b64[(buf[byte] << (bit - 2) | buf[
byte + 1] >> (10 - bit)) &
Public header for librsync.