2 #include <linux/errno.h>
5 * base64 encode/decode.
8 const char *pem_key = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
10 static int encode_bits(int c)
15 static int decode_bits(char c)
17 if (c >= 'A' && c <= 'Z')
19 if (c >= 'a' && c <= 'z')
21 if (c >= '0' && c <= '9')
28 return 0; /* just non-negative, please */
32 int ceph_armor(char *dst, const char *src, const char *end)
38 unsigned char a, b, c;
41 *dst++ = encode_bits(a >> 2);
44 *dst++ = encode_bits(((a & 3) << 4) | (b >> 4));
47 *dst++ = encode_bits(((b & 15) << 2) |
49 *dst++ = encode_bits(c & 63);
51 *dst++ = encode_bits((b & 15) << 2);
55 *dst++ = encode_bits(((a & 3) << 4));
70 int ceph_unarmor(char *dst, const char *src, const char *end)
77 if (src < end && src[0] == '\n')
81 a = decode_bits(src[0]);
82 b = decode_bits(src[1]);
83 c = decode_bits(src[2]);
84 d = decode_bits(src[3]);
85 if (a < 0 || b < 0 || c < 0 || d < 0)
88 *dst++ = (a << 2) | (b >> 4);
91 *dst++ = ((b & 15) << 4) | (c >> 2);
94 *dst++ = ((c & 3) << 6) | d;