diff options
author | Eric S. Raymond <esr@thyrsus.com> | 2015-03-02 12:59:41 -0500 |
---|---|---|
committer | Eric S. Raymond <esr@thyrsus.com> | 2015-03-02 12:59:41 -0500 |
commit | a5a7c1f8ae3c1e030442a322e3fb9960d10eae48 (patch) | |
tree | 4faaa0ec8f06d73e086b8187d4b8a832d913a996 /bsd_base64.c | |
parent | 8ab0b3e8b416e691279c04aaba68034b1886be75 (diff) | |
download | gpsd-a5a7c1f8ae3c1e030442a322e3fb9960d10eae48.tar.gz |
Remove some unused code and some port cruft.
All regression tests pass.
Diffstat (limited to 'bsd_base64.c')
-rw-r--r-- | bsd_base64.c | 153 |
1 files changed, 10 insertions, 143 deletions
diff --git a/bsd_base64.c b/bsd_base64.c index 9a7b5f70..e3810ac6 100644 --- a/bsd_base64.c +++ b/bsd_base64.c @@ -42,18 +42,14 @@ */ #include <stdlib.h> -#include "gpsd_config.h" -#if !defined(HAVE_B64_NTOP) && !defined(HAVE___B64_NTOP) - #include <sys/types.h> #include <ctype.h> #include <stdio.h> #include <stdlib.h> #include <string.h> +#include <assert.h> -#include "bsd_base64.h" - -#define Assert(Cond) if (!(Cond)) abort() +#include "gpsd.h" /* we only need the prototype */ static const char Base64[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"; @@ -141,10 +137,10 @@ b64_ntop(unsigned char const *src, size_t srclength, char *target, output[1] = ((input[0] & 0x03) << 4) + (input[1] >> 4); output[2] = ((input[1] & 0x0f) << 2) + (input[2] >> 6); output[3] = input[2] & 0x3f; - Assert(output[0] < 64); - Assert(output[1] < 64); - Assert(output[2] < 64); - Assert(output[3] < 64); + assert(output[0] < 64); + assert(output[1] < 64); + assert(output[2] < 64); + assert(output[3] < 64); if (datalength + 4 > targsize) return (-1); @@ -165,9 +161,9 @@ b64_ntop(unsigned char const *src, size_t srclength, char *target, output[0] = input[0] >> 2; output[1] = ((input[0] & 0x03) << 4) + (input[1] >> 4); output[2] = ((input[1] & 0x0f) << 2) + (input[2] >> 6); - Assert(output[0] < 64); - Assert(output[1] < 64); - Assert(output[2] < 64); + assert(output[0] < 64); + assert(output[1] < 64); + assert(output[2] < 64); if (datalength + 4 > targsize) return (-1); @@ -185,133 +181,4 @@ b64_ntop(unsigned char const *src, size_t srclength, char *target, return (datalength); } -#ifdef __UNUSED__ -/*@ -matchanyintegral +type @*/ - -/* skips all whitespace anywhere. - converts characters, four at a time, starting at (or after) - src from base - 64 numbers into three 8 bit bytes in the target area. - it returns the number of data bytes stored at the target, or -1 on error. - */ - -/*@ +matchanyintegral +charint @*/ -int b64_pton(char const *src, unsigned char *target, size_t targsize) -{ - size_t tarindex; - int state, ch; - char *pos; - - state = 0; - tarindex = 0; - - while ((ch = *src++) != '\0') { - if (isspace(ch)) /* Skip whitespace anywhere. */ - continue; - - if (ch == Pad64) - break; - - if ((pos = strchr(Base64, ch)) == NULL) /* A non-base64 character. */ - return (-1); - - switch (state) { - case 0: - if (target) { - if (tarindex >= targsize) - return (-1); - target[tarindex] = (pos - Base64) << 2; - } - state = 1; - break; - case 1: - if (target) { - if (tarindex + 1 >= targsize) - return (-1); - target[tarindex] |= (pos - Base64) >> 4; - target[tarindex + 1] = ((pos - Base64) & 0x0f) - << 4; - } - tarindex++; - state = 2; - break; - case 2: - if (target) { - if (tarindex + 1 >= targsize) - return (-1); - target[tarindex] |= (pos - Base64) >> 2; - target[tarindex + 1] = ((pos - Base64) & 0x03) - << 6; - } - tarindex++; - state = 3; - break; - case 3: - if (target) { - if (tarindex >= targsize) - return (-1); - target[tarindex] |= (pos - Base64); - } - tarindex++; - state = 0; - break; - } - } - - /* - * We are done decoding Base-64 chars. Let's see if we ended - * on a byte boundary, and/or with erroneous trailing characters. - */ - - if (ch == Pad64) { /* We got a pad char. */ - ch = *src++; /* Skip it, get next. */ - switch (state) { - case 0: /* Invalid = in first position */ - case 1: /* Invalid = in second position */ - return (-1); - - case 2: /* Valid, means one byte of info */ - /* Skip any number of spaces. */ - for (; ch != '\0'; ch = *src++) - if (!isspace(ch)) - break; - /* Make sure there is another trailing = sign. */ - if (ch != Pad64) - return (-1); - ch = *src++; /* Skip the = */ - /* Fall through to "single trailing =" case. */ - /* FALLTHROUGH */ - /*@ -casebreak @*/ - case 3: /* Valid, means two bytes of info */ - /* - * We know this char is an =. Is there anything but - * whitespace after it? - */ - for (; ch != '\0'; ch = *src++) - if (!isspace(ch)) - return (-1); - - /* - * Now make sure for cases 2 and 3 that the "extra" - * bits that slopped past the last full byte were - * zeros. If we don't check them, they become a - * subliminal channel. - */ - if (target != 0 && target[tarindex] != 0) - return (-1); - } - } else { - /* - * We ended by seeing the end of the string. Make sure we - * have no partial bytes lying around. - */ - if (state != 0) - return (-1); - } - - return (tarindex); -} - -/*@ +matchanyintegral -charint @*/ -#endif /* __UNUSED__ */ - -#endif /* !defined(HAVE_B64_NTOP) && !defined(HAVE___B64_NTOP) */ +/* end */ |