return r;
}
-int pakfire_b64decode(unsigned char** output, size_t* length, const char* input) {
+int pakfire_b64decode(unsigned char** output, size_t* length, const char* input, ssize_t l) {
unsigned char* buffer = NULL;
size_t block;
int r;
if (!input || !output || !length)
return -EINVAL;
- // Determine the length of the input
- size_t l = strlen(input);
+ // Determine the length of the input if none given
+ if (l < 0)
+ l = strlen(input);
// Remove any trailing whitespace
while (l >= 1 && isspace(input[l - 1]))
#define PAKFIRE_BASE64_H
#include <stddef.h>
+#include <sys/types.h>
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);
+int pakfire_b64decode(unsigned char** output, size_t* length, const char* input, ssize_t l);
#endif /* PAKFIRE_BASE64_H */
// The second line should hold the key
case 2:
// Decode the key
- r = pakfire_b64decode(&buffer, &buffer_length, line);
+ r = pakfire_b64decode(&buffer, &buffer_length, line, -1);
if (r < 0) {
ERROR(ctx, "Could not decode the key: %s\n", strerror(-r));
goto ERROR;
continue;
// Decode the signature
- r = pakfire_b64decode(&buffer, &buffer_length, line);
+ r = pakfire_b64decode(&buffer, &buffer_length, line, -1);
if (r < 0) {
ERROR(key->ctx, "Could not decode the signature: %s\n", strerror(-r));
goto ERROR;
printf("%s\n", base64);
// Decode the data
- ASSERT_SUCCESS(pakfire_b64decode(&output, &length, base64));
+ ASSERT_SUCCESS(pakfire_b64decode(&output, &length, base64, -1));
// Print the decoded data
printf("%.*s\n", (int)length, (char*)output);