oath_base32_decode(3)

πŸ’… oath_base32_decode β€” like, the liboath decoder, bestie

okay so this is a page from liboath (yes, that liboath) and it's all about oath_base32_decode, an API function. buckle up, it's actually so straightforward πŸŽ€


✨ SYNOPSIS ✨

#include <oath.h>

int oath_base32_decode(const char * in, size_t inlen, char ** out,
       size_t * outlen);

that's the whole signature, no cap. four arguments, one int back. let's get into it πŸ¦‹


🌸 ARGUMENTS 🌸

  • const char * in β€” the input string holding your base32 encoded data, and it's inlen bytes long. that's it, that's the vibe.
  • size_t inlen β€” literally just the length of that input base32 string in. the count. the number. πŸ’…
  • char ** out β€” a pointer to the output variable that'll hold the binary data of length outlen… or you can pass NULL if you're feeling mysterious. πŸ™ˆ
  • size_t * outlen β€” a pointer to the output variable holding the length of out. also allowed to be NULL. choose your own adventure ✨

πŸ’– DESCRIPTION πŸ’–

so the whole gig: it decodes a base32 encoded string into binary data. that's the function. iconic behaviour, honestly πŸ‘‘

space characters? ignored. not a problem. and pad characters are added if needed β€” so if your input is missing its padding, the function just handles it for you, no drama 🧚

but non-base32 data? not ignored. not ignored, bestie. that's a hard no β€” it'll lead to an OATH_INVALID_BASE32 error. so keep your input clean or face the consequences πŸ’€

the in parameter should contain inlen bytes of base32 encoded data. the function allocates a new string in *out to hold the decoded data, and sets *outlen to the length of the data. cute, right? it does the malloc-ing for you 🫢

now the fun edge cases:

  • if out is NULL, then *outlen will be set to what would have been the length of *out on successful encoding. so you can like, peek at the size first πŸ‘€
  • if you the caller are not interested in knowing the length of the output data out, then outlen may be set to NULL. no pressure.
  • and yes β€” it is permitted, but useless, to have both out and outlen NULL. you can. it just does nothing for you. it's giving "why are you here" energy 😭

πŸ”₯ RETURNS πŸ”₯

  • OATH_OK (which is zero) on success ⭐
  • OATH_INVALID_BASE32 if the input contains non-base32 characters 🚫
  • OATH_MALLOC_ERROR on memory allocation errors πŸ’€

that's the whole return menu, fr fr.


πŸŽ€ SINCE πŸŽ€

1.12.0 β€” been around a minute, lowkey a classic πŸ’œ


πŸ› REPORTING BUGS πŸ›

found a bug? report it to <oath-toolkit-help@nongnu.org> β€” they wanna hear it, no cap.


Copyright Β© 2009-2026 Simon Josefsson.

copying and distribution of this file, with or without modification, are permitted in any medium without royalty provided the copyright notice and this notice are preserved. slay, honestly β€” that's a very generous license 🌈


and that's the page!! this beauty shipped as part of liboath version 2.6.15, manual page oath_base32_decode(3) β€” go decode something cute, bestie πŸ’…βœ¨πŸ¦‹

πŸ“¦ where this page comes from