chiark
/
gitweb
/
~mdw
/
mLib
/ commitdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
| commitdiff |
tree
raw
|
patch
|
inline
| side by side (from parent 1:
88bd7f6
)
Allow Base64 encode and decode of arbitrary rubbish.
author
mdw
<mdw>
Tue, 18 May 1999 21:45:27 +0000
(21:45 +0000)
committer
mdw
<mdw>
Tue, 18 May 1999 21:45:27 +0000
(21:45 +0000)
base64.c
patch
|
blob
|
blame
|
history
base64.h
patch
|
blob
|
blame
|
history
diff --git
a/base64.c
b/base64.c
index e5cdcfae1dd22f544fbb091e25be7d70b18f9e27..5f5009a9a86854eb71b5040f86fcd0e6269763a1 100644
(file)
--- a/
base64.c
+++ b/
base64.c
@@
-1,6
+1,6
@@
/* -*-c-*-
*
/* -*-c-*-
*
- * $Id: base64.c,v 1.
1 1999/05/17 20:35:00
mdw Exp $
+ * $Id: base64.c,v 1.
2 1999/05/18 21:45:27
mdw Exp $
*
* Base64 encoding and decoding.
*
*
* Base64 encoding and decoding.
*
@@
-30,6
+30,9
@@
/*----- Revision history --------------------------------------------------*
*
* $Log: base64.c,v $
/*----- Revision history --------------------------------------------------*
*
* $Log: base64.c,v $
+ * Revision 1.2 1999/05/18 21:45:27 mdw
+ * Allow Base64 encode and decode of arbitrary rubbish.
+ *
* Revision 1.1 1999/05/17 20:35:00 mdw
* Base64 encoding and decoding support.
*
* Revision 1.1 1999/05/17 20:35:00 mdw
* Base64 encoding and decoding support.
*
@@
-66,7
+69,7
@@
static const signed char base64_decodeMap[] = {
/* --- @base64_encode@ --- *
*
* Arguments: @base64_ctx *ctx@ = pointer to a context block
/* --- @base64_encode@ --- *
*
* Arguments: @base64_ctx *ctx@ = pointer to a context block
- * @const
unsigned char *src
@ = pointer to a source buffer
+ * @const
void *p
@ = pointer to a source buffer
* @size_t sz@ = size of the source buffer
* @dstr *d@ = pointer to destination string
*
* @size_t sz@ = size of the source buffer
* @dstr *d@ = pointer to destination string
*
@@
-77,22
+80,23
@@
static const signed char base64_decodeMap[] = {
*/
void base64_encode(base64_ctx *ctx,
*/
void base64_encode(base64_ctx *ctx,
- const
unsigned char *src
, size_t sz,
+ const
void *p
, size_t sz,
dstr *d)
{
dstr *d)
{
- if (
src
) {
+ if (
p
) {
unsigned long acc = ctx->acc;
unsigned qsz = ctx->qsz;
unsigned long acc = ctx->acc;
unsigned qsz = ctx->qsz;
+ const unsigned char *src = p;
while (sz) {
acc = (acc << 8) | *src++;
qsz++;
sz--;
if (qsz == 3) {
while (sz) {
acc = (acc << 8) | *src++;
qsz++;
sz--;
if (qsz == 3) {
-
dstr_putc
(d, base64_encodeMap[(acc >> 18) & 0x3f]);
-
dstr_putc
(d, base64_encodeMap[(acc >> 12) & 0x3f]);
-
dstr_putc
(d, base64_encodeMap[(acc >> 6) & 0x3f]);
-
dstr_putc
(d, base64_encodeMap[(acc >> 0) & 0x3f]);
+
DPUTC
(d, base64_encodeMap[(acc >> 18) & 0x3f]);
+
DPUTC
(d, base64_encodeMap[(acc >> 12) & 0x3f]);
+
DPUTC
(d, base64_encodeMap[(acc >> 6) & 0x3f]);
+
DPUTC
(d, base64_encodeMap[(acc >> 0) & 0x3f]);
ctx->lnlen += 4;
if (ctx->maxline && ctx->lnlen >= ctx->maxline) {
dstr_puts(d, ctx->indent);
ctx->lnlen += 4;
if (ctx->maxline && ctx->lnlen >= ctx->maxline) {
dstr_puts(d, ctx->indent);
@@
-114,18
+118,18
@@
void base64_encode(base64_ctx *ctx,
break;
case 1:
acc <<= 16;
break;
case 1:
acc <<= 16;
-
dstr_putc
(d, base64_encodeMap[(acc >> 18) & 0x3f]);
-
dstr_putc
(d, base64_encodeMap[(acc >> 12) & 0x3f]);
-
dstr_putc
(d, '=');
-
dstr_putc
(d, '=');
+
DPUTC
(d, base64_encodeMap[(acc >> 18) & 0x3f]);
+
DPUTC
(d, base64_encodeMap[(acc >> 12) & 0x3f]);
+
DPUTC
(d, '=');
+
DPUTC
(d, '=');
ctx->lnlen += 4;
break;
case 2:
acc <<= 8;
ctx->lnlen += 4;
break;
case 2:
acc <<= 8;
-
dstr_putc
(d, base64_encodeMap[(acc >> 18) & 0x3f]);
-
dstr_putc
(d, base64_encodeMap[(acc >> 12) & 0x3f]);
-
dstr_putc
(d, base64_encodeMap[(acc >> 6) & 0x3f]);
-
dstr_putc
(d, '=');
+
DPUTC
(d, base64_encodeMap[(acc >> 18) & 0x3f]);
+
DPUTC
(d, base64_encodeMap[(acc >> 12) & 0x3f]);
+
DPUTC
(d, base64_encodeMap[(acc >> 6) & 0x3f]);
+
DPUTC
(d, '=');
ctx->lnlen += 4;
break;
}
ctx->lnlen += 4;
break;
}
@@
-137,7
+141,7
@@
void base64_encode(base64_ctx *ctx,
/* --- @base64_decode@ --- *
*
* Arguments: @base64_ctx *ctx@ = pointer to a context block
/* --- @base64_decode@ --- *
*
* Arguments: @base64_ctx *ctx@ = pointer to a context block
- * @const
unsigned char *src
@ = pointer to a source buffer
+ * @const
void *p
@ = pointer to a source buffer
* @size_t sz@ = size of the source buffer
* @dstr *d@ = pointer to destination string
*
* @size_t sz@ = size of the source buffer
* @dstr *d@ = pointer to destination string
*
@@
-148,12
+152,13
@@
void base64_encode(base64_ctx *ctx,
*/
void base64_decode(base64_ctx *ctx,
*/
void base64_decode(base64_ctx *ctx,
- const
unsigned char *src
, size_t sz,
+ const
void *p
, size_t sz,
dstr *d)
{
dstr *d)
{
- if (
src
) {
+ if (
p
) {
unsigned long acc = ctx->acc;
unsigned qsz = ctx->qsz;
unsigned long acc = ctx->acc;
unsigned qsz = ctx->qsz;
+ const char *src = p;
int ch;
while (sz) {
int ch;
while (sz) {
@@
-177,9
+182,9
@@
void base64_decode(base64_ctx *ctx,
/* --- Maybe write out a completed triplet --- */
if (qsz == 4) {
/* --- Maybe write out a completed triplet --- */
if (qsz == 4) {
-
dstr_putc
(d, (acc >> 16) & 0xff);
-
dstr_putc
(d, (acc >> 8) & 0xff);
-
dstr_putc
(d, (acc >> 0) & 0xff);
+
DPUTC
(d, (acc >> 16) & 0xff);
+
DPUTC
(d, (acc >> 8) & 0xff);
+
DPUTC
(d, (acc >> 0) & 0xff);
acc = 0;
qsz = 0;
}
acc = 0;
qsz = 0;
}
@@
-209,7
+214,7
@@
void base64_decode(base64_ctx *ctx,
acc <<= 6 * (4 - qsz);
qsz *= 6;
while (qsz > 8) {
acc <<= 6 * (4 - qsz);
qsz *= 6;
while (qsz > 8) {
-
dstr_putc
(d, (acc >> 16) & 0xff);
+
DPUTC
(d, (acc >> 16) & 0xff);
acc <<= 8;
qsz -= 8;
}
acc <<= 8;
qsz -= 8;
}
diff --git
a/base64.h
b/base64.h
index c5943d3e5c98b3b5633d39e3acd9369a4977679a..09bca75d59c1af6efc7810b6ffba78d9f6e11f6a 100644
(file)
--- a/
base64.h
+++ b/
base64.h
@@
-1,6
+1,6
@@
/* -*-c-*-
*
/* -*-c-*-
*
- * $Id: base64.h,v 1.
1 1999/05/17 20:35:00
mdw Exp $
+ * $Id: base64.h,v 1.
2 1999/05/18 21:45:27
mdw Exp $
*
* Base64 encoding and decoding
*
*
* Base64 encoding and decoding
*
@@
-30,6
+30,9
@@
/*----- Revision history --------------------------------------------------*
*
* $Log: base64.h,v $
/*----- Revision history --------------------------------------------------*
*
* $Log: base64.h,v $
+ * Revision 1.2 1999/05/18 21:45:27 mdw
+ * Allow Base64 encode and decode of arbitrary rubbish.
+ *
* Revision 1.1 1999/05/17 20:35:00 mdw
* Base64 encoding and decoding support.
*
* Revision 1.1 1999/05/17 20:35:00 mdw
* Base64 encoding and decoding support.
*
@@
-61,7
+64,7
@@
typedef struct base64_ctx {
/* --- @base64_encode@ --- *
*
* Arguments: @base64_ctx *ctx@ = pointer to a context block
/* --- @base64_encode@ --- *
*
* Arguments: @base64_ctx *ctx@ = pointer to a context block
- * @const
unsigned char *src
@ = pointer to a source buffer
+ * @const
void *p
@ = pointer to a source buffer
* @size_t sz@ = size of the source buffer
* @dstr *d@ = pointer to destination string
*
* @size_t sz@ = size of the source buffer
* @dstr *d@ = pointer to destination string
*
@@
-72,13
+75,13
@@
typedef struct base64_ctx {
*/
extern void base64_encode(base64_ctx */*ctx*/,
*/
extern void base64_encode(base64_ctx */*ctx*/,
- const
unsigned char */*src
*/, size_t /*sz*/,
+ const
void */*p
*/, size_t /*sz*/,
dstr */*d*/);
/* --- @base64_decode@ --- *
*
* Arguments: @base64_ctx *ctx@ = pointer to a context block
dstr */*d*/);
/* --- @base64_decode@ --- *
*
* Arguments: @base64_ctx *ctx@ = pointer to a context block
- * @const
unsigned char *src
@ = pointer to a source buffer
+ * @const
void *p
@ = pointer to a source buffer
* @size_t sz@ = size of the source buffer
* @dstr *d@ = pointer to destination string
*
* @size_t sz@ = size of the source buffer
* @dstr *d@ = pointer to destination string
*
@@
-89,7
+92,7
@@
extern void base64_encode(base64_ctx */*ctx*/,
*/
extern void base64_decode(base64_ctx */*ctx*/,
*/
extern void base64_decode(base64_ctx */*ctx*/,
- const
unsigned char */*src
*/, size_t /*sz*/,
+ const
void */*p
*/, size_t /*sz*/,
dstr */*d*/);
/* --- @base64_init@ --- *
dstr */*d*/);
/* --- @base64_init@ --- *