base32.c revision 0c27b3fe77ac1d5094ba3521e8142d9e7973133f
/*
* Copyright (C) 2008, 2009, 2013-2016 Internet Systems Consortium, Inc. ("ISC")
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*/
/* $Id: base32.c,v 1.6.698.1 2012/02/15 05:00:16 marka 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);
}
{
base32, '='));
}
{
base32hex, '='));
}
{
base32hex, 0));
}
/*%
* 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
const 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);
/*
* If padding is not permitted flag padding as a error.
*/
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);
/*
* Add missing padding if required.
*/
do {
}
return (ISC_R_BADBASE32);
return (ISC_R_SUCCESS);
}
static isc_result_t
{
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);
}