base32.c revision e851ea826066ac5a5b01c2c23218faa0273a12e8
/*
* Copyright (C) 2008, 2009, 2013 Internet Systems Consortium, Inc. ("ISC")
*
* purpose with or without fee is hereby granted, provided that the above
* copyright notice and this permission notice appear in all copies.
*
* THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH
* REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
* AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT,
* INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
* LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
* OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
* PERFORMANCE OF THIS SOFTWARE.
*/
/* $Id: base32.c,v 1.6 2009/10/21 01:22:29 each Exp $ */
/*! \file */
#include <config.h>
#define RETERR(x) do { \
isc_result_t _r = (x); \
if (_r != ISC_R_SUCCESS) \
return (_r); \
} while (0)
/*@{*/
/*!
* sure where they should go. -- bwelling
*/
static isc_result_t
static isc_result_t
/*@}*/
static const char base32[] =
"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567=abcdefghijklmnopqrstuvwxyz234567";
static const char base32hex[] =
"0123456789ABCDEFGHIJKLMNOPQRSTUV=0123456789abcdefghijklmnopqrstuv";
static isc_result_t
{
char buf[9];
unsigned int loops = 0;
wordlength = 8;
break;
}
break;
}
break;
}
break;
}
loops++;
{
loops = 0;
}
}
return (ISC_R_SUCCESS);
}
{
}
{
base32hex));
}
/*%
* State of a base32 decoding process in progress.
*/
typedef struct {
int length; /*%< Desired length of binary data or -1 */
int digits; /*%< Number of buffered base32 digits */
int val[8];
const char *base; /*%< Which encoding we are using */
int seen_32; /*%< Number of significant bytes if non zero */
static inline void
{
}
static inline isc_result_t
char *s;
unsigned int last;
return (ISC_R_BADBASE32);
return (ISC_R_BADBASE32);
/*
* Handle lower case.
*/
if (last > 32)
last -= 33;
/*
* Check that padding is contiguous.
*/
return (ISC_R_BADBASE32);
/*
* Check that padding starts at the right place and that
* bits that should be zero are.
* Record how many significant bytes in answer (seen_32).
*/
case 0:
case 1:
return (ISC_R_BADBASE32);
case 2:
return (ISC_R_BADBASE32);
break;
case 3:
return (ISC_R_BADBASE32);
case 4:
return (ISC_R_BADBASE32);
break;
case 5:
return (ISC_R_BADBASE32);
break;
case 6:
return (ISC_R_BADBASE32);
case 7:
return (ISC_R_BADBASE32);
break;
}
/*
* Zero fill pad values.
*/
int n = 5;
unsigned char buf[5];
}
return (ISC_R_BADBASE32);
else
}
}
return (ISC_R_SUCCESS);
}
static inline isc_result_t
return (ISC_R_UNEXPECTEDEND);
return (ISC_R_BADBASE32);
return (ISC_R_SUCCESS);
}
static isc_result_t
int length)
{
unsigned int i;
if (length > 0)
else
break;
}
return (ISC_R_SUCCESS);
}
}
}
static isc_result_t
for (;;) {
int c = *cstr++;
if (c == '\0')
break;
if (c == ' ' || c == '\t' || c == '\n' || c== '\r')
continue;
}
return (ISC_R_SUCCESS);
}
}
}
static isc_result_t
}
return (ISC_R_SUCCESS);
}
}
}
static isc_result_t
unsigned int l;
return (ISC_R_NOSPACE);
isc_buffer_add(target, l);
return (ISC_R_SUCCESS);
}
static isc_result_t
return (ISC_R_NOSPACE);
return (ISC_R_SUCCESS);
}