1
1

Improve bin_to_base64() and use const for source.

git-svn-id: svn+ssh://svn.berlios.de/svnroot/repos/libssh/trunk@743 7dcaeef0-15fb-0310-b436-a5af3365683c
Этот коммит содержится в:
Andreas Schneider 2009-05-05 09:16:08 +00:00
родитель fdc1073e8a
Коммит c7806a6a16
2 изменённых файлов: 30 добавлений и 19 удалений

Просмотреть файл

@ -647,7 +647,7 @@ u32 buffer_pass_bytes(BUFFER *buffer, u32 len);
/* in base64.c */
BUFFER *base64_to_bin(const char *source);
unsigned char *bin_to_base64(unsigned char *source, int len);
unsigned char *bin_to_base64(const unsigned char *source, int len);
/* gzip.c */
int compress_buffer(SSH_SESSION *session,BUFFER *buf);

Просмотреть файл

@ -231,7 +231,7 @@ 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],
static void _bin_to_base64(unsigned char *dest, const unsigned char source[3],
int len) {
switch (len) {
case 1:
@ -255,22 +255,33 @@ static void _bin_to_base64(unsigned char *dest, unsigned char source[3],
}
}
/** \brief Converts binary data to a base64 string
* \returns the converted string
* \internal
/**
* @internal
*
* @brief Converts binary data to a base64 string.
*
* @returns the converted string
*/
unsigned char *bin_to_base64(unsigned char *source, int len){
int flen=len + (3 - (len %3)); /* round to upper 3 multiple */
unsigned char *buffer;
unsigned char *bin_to_base64(const unsigned char *source, int len) {
unsigned char *base64;
unsigned char *ptr;
int flen = len + (3 - (len % 3)); /* round to upper 3 multiple */
flen = (4 * flen) / 3 + 1;
ptr=buffer=malloc(flen);
base64 = malloc(flen);
if (base64 == NULL) {
return NULL;
}
ptr = base64;
while(len > 0){
_bin_to_base64(ptr, source, len > 3 ? 3 : len);
ptr += 4;
source += 3;
len -= 3;
}
ptr[0]=0;
return buffer;
ptr[0] = '\0';
return base64;
}