-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
yaml --- r: 188691 b: refs/heads/master c: 8b6e4f2 h: refs/heads/master i: 188689: b0a30b9 188687: 26bdcad v: v3
- Loading branch information
Sage Weil
committed
Feb 10, 2010
1 parent
69a72d0
commit 7e22f60
Showing
6 changed files
with
558 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,2 @@ | ||
--- | ||
refs/heads/master: c7e337d6490d6f2f5e66ddf1b04d00b0dbd10108 | ||
refs/heads/master: 8b6e4f2d8b21c25225b1ce8d53a2e03b92cc8522 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,99 @@ | ||
|
||
#include <linux/errno.h> | ||
|
||
/* | ||
* base64 encode/decode. | ||
*/ | ||
|
||
const char *pem_key = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"; | ||
|
||
static int encode_bits(int c) | ||
{ | ||
return pem_key[c]; | ||
} | ||
|
||
static int decode_bits(char c) | ||
{ | ||
if (c >= 'A' && c <= 'Z') | ||
return c - 'A'; | ||
if (c >= 'a' && c <= 'z') | ||
return c - 'a' + 26; | ||
if (c >= '0' && c <= '9') | ||
return c - '0' + 52; | ||
if (c == '+') | ||
return 62; | ||
if (c == '/') | ||
return 63; | ||
if (c == '=') | ||
return 0; /* just non-negative, please */ | ||
return -EINVAL; | ||
} | ||
|
||
int ceph_armor(char *dst, const char *src, const char *end) | ||
{ | ||
int olen = 0; | ||
int line = 0; | ||
|
||
while (src < end) { | ||
unsigned char a, b, c; | ||
|
||
a = *src++; | ||
*dst++ = encode_bits(a >> 2); | ||
if (src < end) { | ||
b = *src++; | ||
*dst++ = encode_bits(((a & 3) << 4) | (b >> 4)); | ||
if (src < end) { | ||
c = *src++; | ||
*dst++ = encode_bits(((b & 15) << 2) | | ||
(c >> 6)); | ||
*dst++ = encode_bits(c & 63); | ||
} else { | ||
*dst++ = encode_bits((b & 15) << 2); | ||
*dst++ = '='; | ||
} | ||
} else { | ||
*dst++ = encode_bits(((a & 3) << 4)); | ||
*dst++ = '='; | ||
*dst++ = '='; | ||
} | ||
olen += 4; | ||
line += 4; | ||
if (line == 64) { | ||
line = 0; | ||
*(dst++) = '\n'; | ||
olen++; | ||
} | ||
} | ||
return olen; | ||
} | ||
|
||
int ceph_unarmor(char *dst, const char *src, const char *end) | ||
{ | ||
int olen = 0; | ||
|
||
while (src < end) { | ||
int a, b, c, d; | ||
|
||
if (src < end && src[0] == '\n') | ||
src++; | ||
if (src + 4 > end) | ||
return -EINVAL; | ||
a = decode_bits(src[0]); | ||
b = decode_bits(src[1]); | ||
c = decode_bits(src[2]); | ||
d = decode_bits(src[3]); | ||
if (a < 0 || b < 0 || c < 0 || d < 0) | ||
return -EINVAL; | ||
|
||
*dst++ = (a << 2) | (b >> 4); | ||
if (src[2] == '=') | ||
return olen + 1; | ||
*dst++ = ((b & 15) << 4) | (c >> 2); | ||
if (src[3] == '=') | ||
return olen + 2; | ||
*dst++ = ((c & 3) << 6) | d; | ||
olen += 3; | ||
src += 4; | ||
} | ||
return olen; | ||
} |
Oops, something went wrong.