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
)
81 if (src
< end
&& src
[0] == '\n')
85 a
= decode_bits(src
[0]);
86 b
= decode_bits(src
[1]);
87 c
= decode_bits(src
[2]);
88 d
= decode_bits(src
[3]);
89 if (a
< 0 || b
< 0 || c
< 0 || d
< 0)
92 *dst
++ = (a
<< 2) | (b
>> 4);
95 *dst
++ = ((b
& 15) << 4) | (c
>> 2);
98 *dst
++ = ((c
& 3) << 6) | d
;