master ohmu/fastfetch-openbsd / src / common / base64.h
ohmu  ·  2026-10-15
 1#pragma once
 2
 3#include "fastfetch.h"
 4
 5// `str`, `out_size` and `output` are dereferenced unconditionally
 6[[gnu::nonnull(2, 3, 4)]] void ffBase64EncodeRaw(uint32_t size, const char* str, uint32_t* out_size, char* output);
 7[[gnu::nonnull(1), nodiscard]] static inline FFstrbuf ffBase64EncodeStrbuf(const FFstrbuf* in) {
 8    FFstrbuf out = ffStrbufCreateA(10 + in->length * 4 / 3);
 9    ffBase64EncodeRaw(in->length, in->chars, &out.length, out.chars);
10    assert(out.length < out.allocated);
11
12    return out;
13}
14
15[[gnu::nonnull(2, 3, 4)]] void ffBase64DecodeRaw(uint32_t size, const char* str, uint32_t* out_size, char* output);
16[[gnu::nonnull(1), nodiscard]] static inline FFstrbuf ffBase64DecodeStrbuf(const FFstrbuf* in) {
17    FFstrbuf out = ffStrbufCreateA(10 + in->length * 3 / 4);
18    ffBase64DecodeRaw(in->length, in->chars, &out.length, out.chars);
19    assert(out.length < out.allocated);
20
21    return out;
22}