aboutsummaryrefslogtreecommitdiff
path: root/libssh
diff options
context:
space:
mode:
authorAndreas Schneider <mail@cynapses.org>2009-05-05 09:07:09 +0000
committerAndreas Schneider <mail@cynapses.org>2009-05-05 09:07:09 +0000
commitf7d2040d5a7e2764bbe2983beab5e0e2bf3cbd9e (patch)
tree9a7fe8cfeed57f4d367de028cb711d94212adcc2 /libssh
parent2e5f1c8955cb705db46e397703d16e46da2b11f8 (diff)
downloadlibssh-f7d2040d5a7e2764bbe2983beab5e0e2bf3cbd9e.tar.gz
libssh-f7d2040d5a7e2764bbe2983beab5e0e2bf3cbd9e.tar.xz
libssh-f7d2040d5a7e2764bbe2983beab5e0e2bf3cbd9e.zip
Format _bin_to_base64().
git-svn-id: svn+ssh://svn.berlios.de/svnroot/repos/libssh/trunk@740 7dcaeef0-15fb-0310-b436-a5af3365683c
Diffstat (limited to 'libssh')
-rw-r--r--libssh/base64.c46
1 files changed, 24 insertions, 22 deletions
diff --git a/libssh/base64.c b/libssh/base64.c
index 42ee52b..51563ef 100644
--- a/libssh/base64.c
+++ b/libssh/base64.c
@@ -228,29 +228,31 @@ static int get_equals(char *string) {
}
/* thanks sysk for debugging my mess :) */
-#define BITS(n) ((1<<n)-1)
-static void _bin_to_base64(unsigned char *dest, unsigned char source[3], int len){
- switch (len){
- case 1:
- dest[0]=alphabet[(source[0]>>2)];
- dest[1]=alphabet[((source[0] & BITS(2)) << 4)];
- dest[2]='=';
- dest[3]='=';
- break;
- case 2:
- dest[0]=alphabet[source[0]>>2];
- dest[1]=alphabet[(source[1]>>4) | ((source[0] & BITS(2)) << 4)];
- dest[2]=alphabet[(source[1]&BITS(4)) << 2];
- dest[3]='=';
- break;
- case 3:
- dest[0]=alphabet[(source[0]>>2)];
- dest[1]=alphabet[(source[1]>>4) | ((source[0] & BITS(2)) << 4)];
- dest[2]=alphabet[ (source[2] >> 6) | (source[1]&BITS(4)) << 2];
- dest[3]=alphabet[source[2]&BITS(6)];
- break;
- }
+#define BITS(n) ((1 << (n)) - 1)
+static void _bin_to_base64(unsigned char *dest, unsigned char source[3],
+ int len) {
+ switch (len) {
+ case 1:
+ dest[0] = alphabet[(source[0] >> 2)];
+ dest[1] = alphabet[((source[0] & BITS(2)) << 4)];
+ dest[2] = '=';
+ dest[3] = '=';
+ break;
+ case 2:
+ dest[0] = alphabet[source[0] >> 2];
+ dest[1] = alphabet[(source[1] >> 4) | ((source[0] & BITS(2)) << 4)];
+ dest[2] = alphabet[(source[1] & BITS(4)) << 2];
+ dest[3] = '=';
+ break;
+ case 3:
+ dest[0] = alphabet[(source[0] >> 2)];
+ dest[1] = alphabet[(source[1] >> 4) | ((source[0] & BITS(2)) << 4)];
+ dest[2] = alphabet[ (source[2] >> 6) | (source[1] & BITS(4)) << 2];
+ dest[3] = alphabet[source[2] & BITS(6)];
+ break;
+ }
}
+
/** \brief Converts binary data to a base64 string
* \returns the converted string
* \internal