You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

29 lines
969 B

// intellectual property is bullshit bgdc
#ifndef BASE64_H
#define BASE64_H
#include <stdbool.h>
#include <stddef.h>
#include <inttypes.h>
// Encode a block to base64. The destination buffer must contain at least
// (4/3) * rounded_up(len, 3) bytes (that is, enough bytes to encode src
// including padding bytes).
//
// Returns the total number of bytes used.
size_t base64_encode(uint8_t * dest, uint8_t const * src, size_t len);
// Decode a block from base64. The destination buffer must contain at least
// (3/4) * rounded_up(len, 4) bytes (that is, enough bytes to encode src
// including possible padding bytes).
//
// This is a "dirty" decode -- embedded whitespace is not tolerated, and out-
// of-range characters result in corrupted results (though they will not cause
// any UB, out-of-bounds access, etc).
//
// Returns the total number of bytes used.
size_t base64_decode(uint8_t * dest, uint8_t const * src, size_t len);
#endif // !defined(BASE64_H)