25 RCSID(
"$Id: 480c5928eb239fdedda986c0ed5d2a4eb229c43d $")
29 #include <freeradius-devel/util/value.h>
30 #define us(x) (uint8_t) x
191 bool add_padding,
char const alphabet[
static UINT8_MAX])
212 alphabet[(a >> 3) & 0x1f],
213 alphabet[((a << 2) | (b >> 6)) & 0x1f],
214 alphabet[(b >> 1) & 0x1f],
215 alphabet[((b << 4) | (c >> 4)) & 0x1f],
216 alphabet[((c << 1) | (d >> 7)) & 0x1f],
217 alphabet[(d >> 2) & 0x1f],
218 alphabet[((d << 3) | (e >> 5)) & 0x1f],
232 alphabet[(a >> 3) & 0x1f],
233 alphabet[((a << 2) | (b >> 6)) & 0x1f],
234 alphabet[(b >> 1) & 0x1f],
235 alphabet[((b << 4) | (c >> 4)) & 0x1f],
236 alphabet[((c << 1) | (d >> 7)) & 0x1f],
237 alphabet[(d >> 2) & 0x1f],
238 alphabet[(d << 3) & 0x1f]);
251 alphabet[(a >> 3) & 0x1f],
252 alphabet[((a << 2) | (b >> 6)) & 0x1f],
253 alphabet[(b >> 1) & 0x1f],
254 alphabet[((b << 4) | (c >> 4)) & 0x1f],
255 alphabet[(c << 1) & 0x1f]);
267 alphabet[(a >> 3) & 0x1f],
268 alphabet[((a << 2) | (b >> 6)) & 0x1f],
269 alphabet[(b >> 1) & 0x1f],
270 alphabet[(b << 4) & 0x1f]);
281 alphabet[(a >> 3) & 0x1f],
282 alphabet[(a << 2) & 0x1f]);
295 fr_sbuff_terminate(&our_out);
316 bool expect_padding,
bool no_trailing,
uint8_t const alphabet[
static UINT8_MAX])
340 (alphabet[
us(p[0])] << 3) | (alphabet[
us(p[1])] >> 2),
341 (alphabet[
us(p[1])] << 6) | (alphabet[
us(p[2])] << 1) | (alphabet[
us(p[3])] >> 4),
342 (alphabet[
us(p[3])] << 4) | (alphabet[
us(p[4])] >> 1),
343 (alphabet[
us(p[4])] << 7) | (alphabet[
us(p[5])] << 2) | (alphabet[
us(p[6])] >> 3),
344 (alphabet[
us(p[6])] << 5) | alphabet[
us(p[7])]) != 5) {
357 fr_sbuff_marker(&m_final, &our_in);
377 (alphabet[
us(p[0])] << 3) | (alphabet[
us(p[1])] >> 2)) != 1)
goto oob;
387 (alphabet[
us(p[0])] << 3) | (alphabet[
us(p[1])] >> 2),
388 (alphabet[
us(p[1])] << 6) | (alphabet[
us(p[2])] << 1) | (alphabet[
us(p[3])] >> 4))
399 (alphabet[
us(p[0])] << 3) | (alphabet[
us(p[1])] >> 2),
400 (alphabet[
us(p[1])] << 6) | (alphabet[
us(p[2])] << 1) | (alphabet[
us(p[3])] >> 4),
401 (alphabet[
us(p[3])] << 4) | (alphabet[
us(p[4])] >> 1)) != 3)
goto oob;
411 (alphabet[
us(p[0])] << 3) | (alphabet[
us(p[1])] >> 2),
412 (alphabet[
us(p[1])] << 6) | (alphabet[
us(p[2])] << 1) | (alphabet[
us(p[3])] >> 4),
413 (alphabet[
us(p[3])] << 4) | (alphabet[
us(p[4])] >> 1),
414 (alphabet[
us(p[4])] << 7) | (alphabet[
us(p[5])] << 2) | (alphabet[
us(p[6])] >> 3))
429 if (expect_padding) {
431 for (i = 0; i < pad; i++) {
434 "Expected %u padding char(s)", pad);
char const fr_base32_alphabet_encode[UINT8_MAX]
Encode/decode binary data using printable characters (base32 format)
ssize_t fr_base32_encode_nstd(fr_sbuff_t *out, fr_dbuff_t *in, bool add_padding, char const alphabet[static UINT8_MAX])
Base 64 encode binary data.
uint8_t const fr_base32_alphabet_decode[UINT8_MAX]
uint8_t const fr_base32_hex_alphabet_decode[UINT8_MAX]
fr_slen_t fr_base32_decode_nstd(fr_sbuff_parse_error_t *err, fr_dbuff_t *out, fr_sbuff_t *in, bool expect_padding, bool no_trailing, uint8_t const alphabet[static UINT8_MAX])
char const fr_base32_hex_alphabet_encode[UINT8_MAX]
static bool fr_is_base32_nstd(char c, uint8_t const alphabet[static UINT8_MAX])
Check if char is in base32 alphabet.
#define F1(_idx, _val)
Fill macros for array initialisation.
#define fr_dbuff_advance(_dbuff_or_marker, _len)
Advance 'current' position in dbuff or marker by _len bytes.
#define fr_dbuff_used(_dbuff_or_marker)
Return the number of bytes remaining between the start of the dbuff or marker and the current positio...
#define fr_dbuff_current(_dbuff_or_marker)
Return the 'current' position of a dbuff or marker.
#define fr_dbuff_extend_lowat(_status, _dbuff_or_marker, _lowat)
Extend if we're below _lowat.
#define fr_dbuff_in_bytes(_dbuff_or_marker,...)
Copy a byte sequence into a dbuff or marker.
#define FR_DBUFF(_dbuff_or_marker)
Create a new dbuff pointing to the same underlying buffer.
@ FR_SBUFF_PARSE_ERROR_FORMAT
Format of data was invalid.
@ FR_SBUFF_PARSE_OK
No error.
@ FR_SBUFF_PARSE_ERROR_OUT_OF_SPACE
No space available in output buffer.
@ FR_SBUFF_PARSE_ERROR_TRAILING
Trailing characters found.
bool fr_sbuff_next_if_char(fr_sbuff_t *sbuff, char c)
Return true if the current char matches, and if it does, advance.
#define FR_SBUFF_IN_CHAR_RETURN(_sbuff,...)
#define fr_sbuff_set(_dst, _src)
#define fr_sbuff_current(_sbuff_or_marker)
#define fr_sbuff_char(_sbuff_or_marker, _eob)
#define FR_SBUFF_IN_STRCPY_LITERAL_RETURN(_sbuff, _str)
#define fr_sbuff_extend(_sbuff_or_marker)
#define FR_SBUFF_ERROR_RETURN(_sbuff_or_marker)
#define FR_SBUFF(_sbuff_or_marker)
#define fr_sbuff_advance(_sbuff_or_marker, _len)
#define fr_sbuff_behind(_sbuff_or_marker)
#define fr_sbuff_extend_lowat(_status, _sbuff_or_marker, _lowat)
void fr_strerror_clear(void)
Clears all pending messages from the talloc pools.
#define fr_strerror_printf(_fmt,...)
Log to thread local error buffer.
#define fr_strerror_const(_msg)
return fr_dbuff_set(dbuff, &our_dbuff)
FR_SBUFF_SET_RETURN(sbuff, &our_sbuff)
static size_t char ** out