]> git.ipfire.org Git - thirdparty/freeradius-server.git/commitdiff
Have base* functions return fr_slen_t
authorArran Cudbard-Bell <a.cudbardb@freeradius.org>
Sun, 4 Sep 2022 04:38:38 +0000 (00:38 -0400)
committerArran Cudbard-Bell <a.cudbardb@freeradius.org>
Sun, 4 Sep 2022 20:49:47 +0000 (16:49 -0400)
src/lib/util/base16.c
src/lib/util/base32.c
src/lib/util/base64.c
src/lib/util/sbuff.h

index 5667ea2d069a637a3982b8c0c122c66fdbf6c6fc..4eeeb455c65330bc427a467a3c6ae286a51f5e22 100644 (file)
@@ -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;
                }
index 8a59aa18deccc20e70dc5bebe8f0a4bb5982e5f5..a6697a196beeb08823071e003e13ee099d757a2d 100644 (file)
@@ -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;
index 15f6895849170247ca97070a8f38c5303e0f688f..4d4d9905ed76081a03a350b91a07326af3ddd572 100644 (file)
@@ -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);
index 95136eb15b983de2eab980dc1bd8050fefd11e77..245c766addcf3d772124d5c9fc65885d4e3e63d2 100644 (file)
@@ -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.