.\" Copyright (c) 2001-2002 Packet Design, LLC. .\" All rights reserved. .\" .\" Subject to the following obligations and disclaimer of warranty, .\" use and redistribution of this software, in source or object code .\" forms, with or without modifications are expressly permitted by .\" Packet Design; provided, however, that: .\" .\" (i) Any and all reproductions of the source or object code .\" must include the copyright notice above and the following .\" disclaimer of warranties; and .\" (ii) No rights are granted, in any manner or form, to use .\" Packet Design trademarks, including the mark "PACKET DESIGN" .\" on advertising, endorsements, or otherwise except as such .\" appears in the above copyright notice or in the software. .\" .\" THIS SOFTWARE IS BEING PROVIDED BY PACKET DESIGN "AS IS", AND .\" TO THE MAXIMUM EXTENT PERMITTED BY LAW, PACKET DESIGN MAKES NO .\" REPRESENTATIONS OR WARRANTIES, EXPRESS OR IMPLIED, REGARDING .\" THIS SOFTWARE, INCLUDING WITHOUT LIMITATION, ANY AND ALL IMPLIED .\" WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, .\" OR NON-INFRINGEMENT. PACKET DESIGN DOES NOT WARRANT, GUARANTEE, .\" OR MAKE ANY REPRESENTATIONS REGARDING THE USE OF, OR THE RESULTS .\" OF THE USE OF THIS SOFTWARE IN TERMS OF ITS CORRECTNESS, ACCURACY, .\" RELIABILITY OR OTHERWISE. IN NO EVENT SHALL PACKET DESIGN BE .\" LIABLE FOR ANY DAMAGES RESULTING FROM OR ARISING OUT OF ANY USE .\" OF THIS SOFTWARE, INCLUDING WITHOUT LIMITATION, ANY DIRECT, .\" INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, PUNITIVE, OR CONSEQUENTIAL .\" DAMAGES, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES, LOSS OF .\" USE, DATA OR PROFITS, HOWEVER CAUSED AND UNDER ANY THEORY OF .\" LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT .\" (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF .\" THE USE OF THIS SOFTWARE, EVEN IF PACKET DESIGN IS ADVISED OF .\" THE POSSIBILITY OF SUCH DAMAGE. .\" .\" Author: Archie Cobbs .\" .\" $Id: base64.3,v 1.1.1.1 2012/02/21 23:25:53 misho Exp $ .\" .Dd April 22, 2002 .Dt BASE64 3 .Os .Sh NAME .Nm b64_encoder_create , .Nm b64_decoder_create .Nd base-64 encoder and decoder .Sh LIBRARY PDEL Library (libpdel, \-lpdel) .Sh SYNOPSIS .In pdel/io/filter.h .In pdel/io/base64.h .Ft "struct filter *" .Fn b64_encoder_create "const char *charset" .Ft "struct filter *" .Fn b64_decoder_create "const char *charset" "int strict" .Vt extern const char "b64_rfc2045_charset[]" ; .Sh DESCRIPTION These routines create filter objects (see .Xr filter 3) that encode and decode binary data using base-64 encoding. .Pp Both functions take a .Fa charset argument. If equal to .Dv NULL , then the default (RFC 2045) character set is used. Otherwise, .Fa charset must point to a string with 65 unique characters. The first 64 are used to encode the data, while the last character is used as a pad character when the data length is not a multiple of three. .Pp .Fn b64_encoder_create returns a new encoding filter. For every three bytes input to the filter, four bytes from the chosen character set will be output. If the input length is not a multiple of three, then one or two pad characters will be added at the end of the output, so that the output length of the filter is always a multiple of four. .Pp .Fn b64_decoder_create returns a new decoding filter. Every four bytes input to the filter are decoded into up to three bytes of output. If .Fa strict is non-zero, then any malformed input causes an internal error to be generated in the filter, with .Va errno set to .Er EINVAL. Malformed input is any input character not from the chosen character set. In any case, the pad character is always ignored. If .Fa strict is zero, then any unrecognized characters are simply ignored, rather than causing an error. .Pp .Fn b64_encoder_create always generates strings that are accepted by .Fn b64_decoder_create in strict mode, when created with the same character set. .Pp The RFC 2045 character set is avilable in .Va b64_rfc2045_charset . .Sh RETURN VALUES If there was a system error, .Fn b64_encoder_create and .Fn b64_encoder_create return .Dv NULL with .Va errno set to the appropriate value. If an invalid .Fa charset is passed, .Va errno will be set to .Er EINVAL. .Sh SEE ALSO .Xr filter 3 , .Xr libpdel 3 .Rs .%A N. Freed .%A N. Borenstein .%T "Multipurpose Internet Mail Extensions (MIME) Part One: Format of Internet Message Bodies" .%O RFC 2045 .Re .Sh HISTORY The PDEL library was developed at Packet Design, LLC. .Dv "http://www.packetdesign.com/" .Sh AUTHORS .An Archie Cobbs Aq archie@freebsd.org