From: Arran Cudbard-Bell Date: Sun, 4 Sep 2022 04:38:38 +0000 (-0400) Subject: Have base* functions return fr_slen_t X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=89d8a8d0a6ce1752947cdc7ba89761dca5c7c387;p=thirdparty%2Ffreeradius-server.git Have base* functions return fr_slen_t --- diff --git a/src/lib/util/base16.c b/src/lib/util/base16.c index 5667ea2d069..4eeeb455c65 100644 --- a/src/lib/util/base16.c +++ b/src/lib/util/base16.c @@ -138,11 +138,11 @@ ssize_t fr_base16_encode_nstd(fr_sbuff_t *out, fr_dbuff_t *in, char const alphab * at the end of the string. * @param[in] alphabet to use for decoding. * @return - * - <= 0 on failure. The offset where the decoding error occurred as a negative integer. + * - < 0 on failure. The offset where the decoding error occurred as a negative integer. * - Length of decoded data. */ -ssize_t fr_base16_decode_nstd(fr_sbuff_parse_error_t *err, fr_dbuff_t *out, fr_sbuff_t *in, - bool no_trailing, uint8_t const alphabet[static UINT8_MAX + 1]) +fr_slen_t fr_base16_decode_nstd(fr_sbuff_parse_error_t *err, fr_dbuff_t *out, fr_sbuff_t *in, + bool no_trailing, uint8_t const alphabet[static UINT8_MAX + 1]) { fr_sbuff_t our_in = FR_SBUFF(in); fr_dbuff_t our_out = FR_DBUFF(out); @@ -156,7 +156,7 @@ ssize_t fr_base16_decode_nstd(fr_sbuff_parse_error_t *err, fr_dbuff_t *out, fr_s if (!a || !b) { if (a && !b && no_trailing) { if (err) *err = FR_SBUFF_PARSE_ERROR_TRAILING; - return -fr_sbuff_used(&our_in); + return fr_sbuff_error(&our_in); } break; } diff --git a/src/lib/util/base32.c b/src/lib/util/base32.c index 8a59aa18dec..a6697a196be 100644 --- a/src/lib/util/base32.c +++ b/src/lib/util/base32.c @@ -309,11 +309,11 @@ ssize_t fr_base32_encode_nstd(fr_sbuff_t *out, fr_dbuff_t *in, * at the end of the string. * @param[in] alphabet to use for decoding. * @return - * - <= 0 on failure. The offset where the decoding error occurred as a negative integer. + * - < 0 on failure. The offset where the decoding error occurred as a negative integer. * - Length of decoded data. */ -ssize_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]) +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]) { fr_sbuff_t our_in = FR_SBUFF(in); fr_dbuff_t our_out = FR_DBUFF(out); @@ -348,7 +348,7 @@ ssize_t fr_base32_decode_nstd(fr_sbuff_parse_error_t *err, fr_dbuff_t *out, fr_s if (err) *err = FR_SBUFF_PARSE_ERROR_OUT_OF_SPACE; - return -fr_sbuff_used(&our_in); + return fr_sbuff_error(&our_in); } fr_sbuff_advance(&our_in, 8); @@ -423,7 +423,7 @@ ssize_t fr_base32_decode_nstd(fr_sbuff_parse_error_t *err, fr_dbuff_t *out, fr_s bad_format: if (err) *err = FR_SBUFF_PARSE_ERROR_FORMAT; - return -fr_sbuff_used(&our_in); + return fr_sbuff_error(&our_in); } if (expect_padding) { @@ -454,7 +454,7 @@ ssize_t fr_base32_decode_nstd(fr_sbuff_parse_error_t *err, fr_dbuff_t *out, fr_s if (err) *err = FR_SBUFF_PARSE_ERROR_TRAILING; - return -fr_sbuff_used(&our_in); + return fr_sbuff_error(&our_in); } if (err) *err = FR_SBUFF_PARSE_OK; diff --git a/src/lib/util/base64.c b/src/lib/util/base64.c index 15f68958491..4d4d9905ed7 100644 --- a/src/lib/util/base64.c +++ b/src/lib/util/base64.c @@ -395,11 +395,11 @@ ssize_t fr_base64_encode_nstd(fr_sbuff_t *out, fr_dbuff_t *in, * at the end of the string. * @param[in] alphabet to use for decoding. * @return - * - <= 0 on failure. The offset where the decoding error occurred as a negative integer. + * - < 0 on failure. The offset where the decoding error occurred as a negative integer. * - Length of decoded data. */ -ssize_t fr_base64_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]) +fr_slen_t fr_base64_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]) { fr_sbuff_t our_in = FR_SBUFF(in); fr_dbuff_t our_out = FR_DBUFF(out); @@ -427,7 +427,7 @@ ssize_t fr_base64_decode_nstd(fr_sbuff_parse_error_t *err, fr_dbuff_t *out, fr_s if (err) *err = FR_SBUFF_PARSE_ERROR_OUT_OF_SPACE; - return -fr_sbuff_used(&our_in); + return fr_sbuff_error(&our_in); } fr_sbuff_advance(&our_in, 4); @@ -474,7 +474,7 @@ ssize_t fr_base64_decode_nstd(fr_sbuff_parse_error_t *err, fr_dbuff_t *out, fr_s bad_format: if (err) *err = FR_SBUFF_PARSE_ERROR_FORMAT; - return -fr_sbuff_used(&our_in); + return fr_sbuff_error(&our_in); } if (expect_padding) { @@ -499,7 +499,7 @@ ssize_t fr_base64_decode_nstd(fr_sbuff_parse_error_t *err, fr_dbuff_t *out, fr_s if (err) *err = FR_SBUFF_PARSE_ERROR_TRAILING; - return -fr_sbuff_used(&our_in); + return fr_sbuff_error(&our_in); } fr_sbuff_set(in, &our_in); diff --git a/src/lib/util/sbuff.h b/src/lib/util/sbuff.h index 95136eb15b9..245c766addc 100644 --- a/src/lib/util/sbuff.h +++ b/src/lib/util/sbuff.h @@ -897,7 +897,6 @@ static inline fr_sbuff_t *fr_sbuff_init_talloc(TALLOC_CTX *ctx, ((size_t)(fr_sbuff_start(_sbuff_or_marker) > fr_sbuff_current(_sbuff_or_marker) ? \ 0 : (fr_sbuff_current(_sbuff_or_marker) - fr_sbuff_start(_sbuff_or_marker)))) - /** Sets an error marker in the parent * * If an error already exists at this level it will be used instead of the provided error.