kit

kit
git clone https://git.ryansepassi.com/git/kit.git
Log | Files | Refs | README

b64.h (946B)


      1 #ifndef KIT_DIST_B64_H
      2 #define KIT_DIST_B64_H
      3 
      4 #include <stddef.h>
      5 #include <stdint.h>
      6 
      7 /* Standard base64 (RFC 4648, `+/` alphabet, `=` padding). Real, not a stub:
      8  * minisign keys and signatures are base64 and round-tripping must be exact. */
      9 
     10 /* Bytes needed to hold the base64 encoding of `n` raw bytes, plus a NUL. */
     11 #define DIST_B64_ENCODED_CAP(n) ((((n) + 2u) / 3u) * 4u + 1u)
     12 
     13 /* Encode `n` bytes into `out` (must hold DIST_B64_ENCODED_CAP(n)). Writes a
     14  * NUL terminator. Returns the number of base64 characters (excluding NUL). */
     15 size_t dist_b64_encode(char* out, const uint8_t* in, size_t n);
     16 
     17 /* Decode base64 text `in` of `inlen` chars into `out`, storing the decoded
     18  * length in *outlen. `out` must hold at least (inlen/4)*3 bytes. Embedded
     19  * whitespace is rejected (callers pass a single trimmed line). Returns DIST_OK
     20  * or DIST_ERR. */
     21 int dist_b64_decode(uint8_t* out, size_t* outlen, const char* in, size_t inlen);
     22 
     23 #endif