Commit 22876238 authored by Niels Möller's avatar Niels Möller
Browse files

(base64_decode_single): Simplified, got rid of

the done variable.

Rev: src/nettle/base64-decode.c:1.3
parent 094e3713
...@@ -31,6 +31,8 @@ ...@@ -31,6 +31,8 @@
#define TABLE_SPACE -2 #define TABLE_SPACE -2
#define TABLE_END -3 #define TABLE_END -3
/* FIXME: Make sure that all whitespace characters, SPC, HT, VT, FF,
* CR and LF are ignored. */
static const signed char static const signed char
decode_table[0x100] = decode_table[0x100] =
{ {
...@@ -74,9 +76,6 @@ base64_decode_single(struct base64_decode_ctx *ctx, ...@@ -74,9 +76,6 @@ base64_decode_single(struct base64_decode_ctx *ctx,
switch(data) switch(data)
{ {
default: default:
{
unsigned done = 0;
assert(data >= 0 && data < 0x40); assert(data >= 0 && data < 0x40);
if (ctx->status != BASE64_DECODE_OK) if (ctx->status != BASE64_DECODE_OK)
...@@ -88,13 +87,17 @@ base64_decode_single(struct base64_decode_ctx *ctx, ...@@ -88,13 +87,17 @@ base64_decode_single(struct base64_decode_ctx *ctx,
if (ctx->bits >= 8) if (ctx->bits >= 8)
{ {
ctx->bits -= 8; ctx->bits -= 8;
dst[done++] = ctx->word >> ctx->bits; dst[0] = ctx->word >> ctx->bits;
} return 1;
return done;
} }
else return 0;
case TABLE_INVALID: case TABLE_INVALID:
invalid: invalid:
ctx->status = BASE64_DECODE_ERROR; ctx->status = BASE64_DECODE_ERROR;
/* Fall through */
case TABLE_SPACE:
return 0; return 0;
case TABLE_END: case TABLE_END:
...@@ -106,10 +109,6 @@ base64_decode_single(struct base64_decode_ctx *ctx, ...@@ -106,10 +109,6 @@ base64_decode_single(struct base64_decode_ctx *ctx,
ctx->status = BASE64_DECODE_END; ctx->status = BASE64_DECODE_END;
ctx->bits -= 2; ctx->bits -= 2;
/* Fall through */
case TABLE_SPACE:
/* Ignore */
return 0; return 0;
} }
} }
...@@ -120,13 +119,13 @@ base64_decode_update(struct base64_decode_ctx *ctx, ...@@ -120,13 +119,13 @@ base64_decode_update(struct base64_decode_ctx *ctx,
unsigned length, unsigned length,
const uint8_t *src) const uint8_t *src)
{ {
unsigned done = 0; unsigned done;
unsigned i; unsigned i;
if (ctx->status == BASE64_DECODE_ERROR) if (ctx->status == BASE64_DECODE_ERROR)
return 0; return 0;
for (i = 0; i<length; i++) for (i = 0, done = 0; i<length; i++)
done += base64_decode_single(ctx, dst + done, src[i]); done += base64_decode_single(ctx, dst + done, src[i]);
assert(done <= BASE64_DECODE_LENGTH(length)); assert(done <= BASE64_DECODE_LENGTH(length));
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment