Mercurial > libbase64
view libbase64.3 @ 58:7e79e9126366 default tip @
misc: update copyright years
author | David Demelier <markand@malikania.fr> |
---|---|
date | Thu, 04 Jan 2024 10:41:43 +0100 |
parents | bb834d307c82 |
children |
line wrap: on
line source
.\" .\" Copyright (c) 2013-2024 David Demelier <markand@malikania.fr> .\" .\" Permission to use, copy, modify, and/or distribute this software for any .\" purpose with or without fee is hereby granted, provided that the above .\" copyright notice and this permission notice appear in all copies. .\" .\" THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES .\" WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF .\" MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR .\" ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES .\" WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN .\" ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF .\" OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. .\" .Dd $Mdocdate$ .Dt LIBBASE64 3 .Os .\" NAME .Sh NAME .Nm libbase64 , .Nm B64_DECODE_LENGTH , .Nm B64_ENCODE_LENGTH , .Nm b64_decode , .Nm b64_encode .Nd encode and decode base64 .\" SYNOPSIS .Sh SYNOPSIS .In base64.h .Fd #define B64_ENCODE_LENGTH(size) .Fd #define B64_DECODE_LENGTH(size) .Ft size_t .Fn b64_encode "const void *src, size_t srcsz, char *dst, size_t dstsz" .Ft size_t .Fn b64_decode "const char *src, size_t srcsz, void *dst, size_t dstsz" .\" DESCRIPTION .Sh DESCRIPTION This library exposes few functions to encode and decode any kind of input data using base64 format. .Pp The .Fn B64_ENCODE_LENGTH and .Fn B64_DECODE_LENGTH macros can be used to compute the required size to encode or decode respectively depending on the argument .Fa size expressed in bytes. They always return the number of bytes required at most (depending on padding bytes) but the returned value .Em doesn't include the NUL terminator. .Pp The .Fn b64_encode function reads the input string .Fa src up to .Fa srcsz bytes (which can be -1 to read until NUL character) and stores the result into argument .Fa dst . The function writes up to .Fa dstsz bytes at most (including the NUL terminator). .Pp The .Fn b64_decode functions read the base64 encoded (or base64url encoded) input string .Fa src up to .Fa srcsz (which can be -1 to read until NUL character) and stores the decoded result into argument .Fa dst . Ths function writes up to .Fa dstsz bytes at most. In contrast to .Fn b64_encode , this function .Em does not append a NUL character since the encoded data may be binary. Make sure to reserve one more byte and add it if needed. .\" RETURN VALUES .Sh RETURN VALUES The functions .Fn b64_encode and .Fn b64_decode returns the number of bytes written into the .Fa dst argument (not including the NUL terminator) or (size_t)-1 on error. In that case .Va errno is set to indicate the error. .\" ERRORS .Sh ERRORS .Bl -tag -width Er .It Bq Er ERANGE The output .Fa dst pointer wasn't large enough to store the encoded/decoded data. .It Bq Er EILSEQ Only set from .Fn b64_decode . The input string .Fa src did not contain valid base64 characters. .El .Sh AUTHORS .Nm was written by David Demelier <markand@malikania.fr>