]> git.ipfire.org Git - pakfire.git/commitdiff
base64: No longer require the input length
authorMichael Tremer <michael.tremer@ipfire.org>
Sat, 21 Jun 2025 13:02:44 +0000 (13:02 +0000)
committerMichael Tremer <michael.tremer@ipfire.org>
Sat, 21 Jun 2025 13:02:44 +0000 (13:02 +0000)
Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
src/pakfire/base64.c
src/pakfire/base64.h
src/pakfire/jwt.c
src/pakfire/key.c
tests/libpakfire/util.c

index c0af7b9674254af5a388288f342a976d016feb61..49180b1b26e1c88bef47f9a3eac752c61b1fa3d2 100644 (file)
@@ -67,7 +67,7 @@ ERROR:
        return r;
 }
 
-int pakfire_b64decode(unsigned char** output, size_t* length, const char* input, ssize_t l) {
+int pakfire_b64decode(unsigned char** output, size_t* length, const char* input) {
        unsigned char* buffer = NULL;
        size_t block;
        int r;
@@ -76,9 +76,8 @@ int pakfire_b64decode(unsigned char** output, size_t* length, const char* input,
        if (!input || !output || !length)
                return -EINVAL;
 
-       // Determine the length of the input if none given
-       if (l < 0)
-               l = strlen(input);
+       // Determine the length of the input
+       size_t l = strlen(input);
 
        // Remove any trailing whitespace
        while (l >= 1 && isspace(input[l - 1]))
index 21fe7c2484e318362c54116cf99a54232a87aa9e..a310c9cafdbf1e1e2a92a2485deba5ddaa5b4d13 100644 (file)
@@ -26,7 +26,7 @@
 
 int pakfire_b64encode(char** output, const unsigned char* input, const size_t length);
 
-int pakfire_b64decode(unsigned char** output, size_t* length, const char* input, ssize_t l);
+int pakfire_b64decode(unsigned char** output, size_t* length, const char* input);
 
 int pakfire_b64normalize(char** output, const char* input, ssize_t length);
 
index 20fa9fb68680c8668f9f4b984bea47dd05dc0c63..4474104e2e704ddfff8029200b98e4eb97572554 100644 (file)
@@ -79,7 +79,7 @@ static int pakfire_jwt_decode_payload(char** payload, size_t* length, const char
                goto ERROR;
 
        // Decode the payload
-       r = pakfire_b64decode((unsigned char**)payload, length, normalized, -1);
+       r = pakfire_b64decode((unsigned char**)payload, length, normalized);
 
 ERROR:
        if (normalized)
index eaee51454555a5bc1a5e55ebf9cc5bda4e9aedcd..db945dec6471b11d9d4ace9eeec01938100c9a7a 100644 (file)
@@ -430,7 +430,7 @@ int pakfire_key_import(struct pakfire_key** key,
                        // The second line should hold the key
                        case 2:
                                // Decode the key
-                               r = pakfire_b64decode(&buffer, &buffer_length, line, -1);
+                               r = pakfire_b64decode(&buffer, &buffer_length, line);
                                if (r < 0) {
                                        ERROR(ctx, "Could not decode the key: %s\n", strerror(-r));
                                        goto ERROR;
@@ -912,7 +912,7 @@ static int pakfire_key_read_signature(struct pakfire_key* key,
                        continue;
 
                // Decode the signature
-               r = pakfire_b64decode(&buffer, &buffer_length, line, -1);
+               r = pakfire_b64decode(&buffer, &buffer_length, line);
                if (r < 0) {
                        ERROR(key->ctx, "Could not decode the signature: %s\n", strerror(-r));
                        goto ERROR;
index 4053f164ed551f098c2a6020a11451c7617d0d88..ff710304dd3820efaed19ea94d5b0d56b345b054 100644 (file)
@@ -67,7 +67,7 @@ static int test_base64(const struct test* t) {
        printf("%s\n", base64);
 
        // Decode the data
-       ASSERT_SUCCESS(pakfire_b64decode(&output, &length, base64, -1));
+       ASSERT_SUCCESS(pakfire_b64decode(&output, &length, base64));
 
        // Print the decoded data
        printf("%.*s\n", (int)length, (char*)output);