poly-1-fw/base64.h

29 lines
969 B
C
Raw Normal View History

2022-09-03 23:26:48 +00:00
// 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).
//
2022-10-06 02:38:08 +00:00
// 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).
//
2022-09-03 23:26:48 +00:00
// 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)