mirror of
https://github.com/proxytunnel/proxytunnel.git
synced 2026-01-23 02:34:59 +00:00
Moved base64 code to base64.[ch]
More cleanups git-svn-id: https://proxytunnel.svn.sourceforge.net/svnroot/proxytunnel/trunk/proxytunnel@19 bc163920-b10d-0410-b2c5-a5491ca2ceef
This commit is contained in:
parent
e4bb139a97
commit
785411bb8b
7 changed files with 89 additions and 54 deletions
74
base64.c
Normal file
74
base64.c
Normal file
|
|
@ -0,0 +1,74 @@
|
|||
/* Proxytunnel - (C) 2001-2002 Jos Visser / Mark Janssen */
|
||||
/* Contact: josv@osp.nl / maniac@maniac.nl */
|
||||
|
||||
/*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include "config.h"
|
||||
#include "cmdline.h"
|
||||
#include "base64.h"
|
||||
|
||||
/* Needed for base64 encoding... */
|
||||
static const char base64digits[] =
|
||||
"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
|
||||
|
||||
/*
|
||||
* Small MAX macro
|
||||
*/
|
||||
#ifndef MAX
|
||||
#define MAX( x, y ) ( ( (x)>(y) ) ? (x) : (y) )
|
||||
#endif
|
||||
|
||||
/*
|
||||
* This base64 code is heavily modified from fetchmail (also GPL'd, of
|
||||
* course) by Brendan Cully <brendan@kublai.com>.
|
||||
*
|
||||
* Original copyright notice:
|
||||
*
|
||||
* The code in the fetchmail distribution is Copyright 1997 by Eric
|
||||
* S. Raymond. Portions are also copyrighted by Carl Harris, 1993
|
||||
* and 1995. Copyright retained for the purpose of protecting free
|
||||
* redistribution of source.
|
||||
*
|
||||
*/
|
||||
|
||||
/* raw bytes to null-terminated base 64 string */
|
||||
void base64(unsigned char *out, const unsigned char *in, int len)
|
||||
{
|
||||
while (len >= 3) {
|
||||
*out++ = base64digits[in[0] >> 2];
|
||||
*out++ = base64digits[((in[0] << 4) & 0x30) | (in[1] >> 4)];
|
||||
*out++ = base64digits[((in[1] << 2) & 0x3c) | (in[2] >> 6)];
|
||||
*out++ = base64digits[in[2] & 0x3f];
|
||||
len -= 3;
|
||||
in += 3;
|
||||
}
|
||||
|
||||
/* clean up remainder */
|
||||
if (len > 0) {
|
||||
unsigned char fragment;
|
||||
|
||||
*out++ = base64digits[in[0] >> 2];
|
||||
fragment = (in[0] << 4) & 0x30;
|
||||
if (len > 1)
|
||||
fragment |= in[1] >> 4;
|
||||
*out++ = base64digits[fragment];
|
||||
*out++ = (len < 2) ? '=' : base64digits[(in[1] << 2) & 0x3c];
|
||||
*out++ = '=';
|
||||
}
|
||||
*out = '\0';
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue