Back to index

nagios-plugins  1.4.16
base64.h
Go to the documentation of this file.
00001 /* base64.h -- Encode binary data using printable characters.
00002    Copyright (C) 2004, 2005, 2006, 2009, 2010 Free Software Foundation, Inc.
00003    Written by Simon Josefsson.
00004 
00005    This program is free software; you can redistribute it and/or modify
00006    it under the terms of the GNU General Public License as published by
00007    the Free Software Foundation; either version 3, or (at your option)
00008    any later version.
00009 
00010    This program is distributed in the hope that it will be useful,
00011    but WITHOUT ANY WARRANTY; without even the implied warranty of
00012    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00013    GNU General Public License for more details.
00014 
00015    You should have received a copy of the GNU General Public License
00016    along with this program; if not, write to the Free Software Foundation,
00017    Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.  */
00018 
00019 #ifndef BASE64_H
00020 # define BASE64_H
00021 
00022 /* Get size_t. */
00023 # include <stddef.h>
00024 
00025 /* Get bool. */
00026 # include <stdbool.h>
00027 
00028 /* This uses that the expression (n+(k-1))/k means the smallest
00029    integer >= n/k, i.e., the ceiling of n/k.  */
00030 # define BASE64_LENGTH(inlen) ((((inlen) + 2) / 3) * 4)
00031 
00032 struct base64_decode_context
00033 {
00034   unsigned int i;
00035   char buf[4];
00036 };
00037 
00038 extern bool isbase64 (char ch);
00039 
00040 extern void base64_encode (const char *restrict in, size_t inlen,
00041                            char *restrict out, size_t outlen);
00042 
00043 extern size_t base64_encode_alloc (const char *in, size_t inlen, char **out);
00044 
00045 extern void base64_decode_ctx_init (struct base64_decode_context *ctx);
00046 
00047 extern bool base64_decode_ctx (struct base64_decode_context *ctx,
00048                                const char *restrict in, size_t inlen,
00049                                char *restrict out, size_t *outlen);
00050 
00051 extern bool base64_decode_alloc_ctx (struct base64_decode_context *ctx,
00052                                      const char *in, size_t inlen,
00053                                      char **out, size_t *outlen);
00054 
00055 #define base64_decode(in, inlen, out, outlen) \
00056         base64_decode_ctx (NULL, in, inlen, out, outlen)
00057 
00058 #define base64_decode_alloc(in, inlen, out, outlen) \
00059         base64_decode_alloc_ctx (NULL, in, inlen, out, outlen)
00060 
00061 #endif /* BASE64_H */