2 #include <linux/errno.h>
4 int ceph_armor(char *dst, const char *src, const char *end);
5 int ceph_unarmor(char *dst, const char *src, const char *end);
8 * base64 encode/decode.
11 static const char *pem_key =
12 "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
14 static int encode_bits(int c)
19 static int decode_bits(char c)
21 if (c >= 'A' && c <= 'Z')
23 if (c >= 'a' && c <= 'z')
25 if (c >= '0' && c <= '9')
32 return 0; /* just non-negative, please */
36 int ceph_armor(char *dst, const char *src, const char *end)
42 unsigned char a, b, c;
45 *dst++ = encode_bits(a >> 2);
48 *dst++ = encode_bits(((a & 3) << 4) | (b >> 4));
51 *dst++ = encode_bits(((b & 15) << 2) |
53 *dst++ = encode_bits(c & 63);
55 *dst++ = encode_bits((b & 15) << 2);
59 *dst++ = encode_bits(((a & 3) << 4));
74 int ceph_unarmor(char *dst, const char *src, const char *end)
87 a = decode_bits(src[0]);
88 b = decode_bits(src[1]);
89 c = decode_bits(src[2]);
90 d = decode_bits(src[3]);
91 if (a < 0 || b < 0 || c < 0 || d < 0)
94 *dst++ = (a << 2) | (b >> 4);
97 *dst++ = ((b & 15) << 4) | (c >> 2);
100 *dst++ = ((c & 3) << 6) | d;