mrc0mmand / rpms / libguestfs

Forked from rpms/libguestfs 3 years ago
Clone
ffd6ed
/* base64.h -- Encode binary data using printable characters.
ffd6ed
   Copyright (C) 2004-2006, 2009-2014 Free Software Foundation, Inc.
ffd6ed
   Written by Simon Josefsson.
ffd6ed
ffd6ed
   This program is free software; you can redistribute it and/or modify
ffd6ed
   it under the terms of the GNU General Public License as published by
ffd6ed
   the Free Software Foundation; either version 3, or (at your option)
ffd6ed
   any later version.
ffd6ed
ffd6ed
   This program is distributed in the hope that it will be useful,
ffd6ed
   but WITHOUT ANY WARRANTY; without even the implied warranty of
ffd6ed
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
ffd6ed
   GNU General Public License for more details.
ffd6ed
ffd6ed
   You should have received a copy of the GNU General Public License
ffd6ed
   along with this program; if not, see <http://www.gnu.org/licenses/>.  */
ffd6ed
ffd6ed
#ifndef BASE64_H
ffd6ed
# define BASE64_H
ffd6ed
ffd6ed
/* Get size_t. */
ffd6ed
# include <stddef.h>
ffd6ed
ffd6ed
/* Get bool. */
ffd6ed
# include <stdbool.h>
ffd6ed
ffd6ed
# ifdef __cplusplus
ffd6ed
extern "C" {
ffd6ed
# endif
ffd6ed
ffd6ed
/* This uses that the expression (n+(k-1))/k means the smallest
ffd6ed
   integer >= n/k, i.e., the ceiling of n/k.  */
ffd6ed
# define BASE64_LENGTH(inlen) ((((inlen) + 2) / 3) * 4)
ffd6ed
ffd6ed
struct base64_decode_context
ffd6ed
{
ffd6ed
  unsigned int i;
ffd6ed
  char buf[4];
ffd6ed
};
ffd6ed
ffd6ed
extern bool isbase64 (char ch) _GL_ATTRIBUTE_CONST;
ffd6ed
ffd6ed
extern void base64_encode (const char *restrict in, size_t inlen,
ffd6ed
                           char *restrict out, size_t outlen);
ffd6ed
ffd6ed
extern size_t base64_encode_alloc (const char *in, size_t inlen, char **out);
ffd6ed
ffd6ed
extern void base64_decode_ctx_init (struct base64_decode_context *ctx);
ffd6ed
ffd6ed
extern bool base64_decode_ctx (struct base64_decode_context *ctx,
ffd6ed
                               const char *restrict in, size_t inlen,
ffd6ed
                               char *restrict out, size_t *outlen);
ffd6ed
ffd6ed
extern bool base64_decode_alloc_ctx (struct base64_decode_context *ctx,
ffd6ed
                                     const char *in, size_t inlen,
ffd6ed
                                     char **out, size_t *outlen);
ffd6ed
ffd6ed
#define base64_decode(in, inlen, out, outlen) \
ffd6ed
        base64_decode_ctx (NULL, in, inlen, out, outlen)
ffd6ed
ffd6ed
#define base64_decode_alloc(in, inlen, out, outlen) \
ffd6ed
        base64_decode_alloc_ctx (NULL, in, inlen, out, outlen)
ffd6ed
ffd6ed
# ifdef __cplusplus
ffd6ed
}
ffd6ed
# endif
ffd6ed
ffd6ed
#endif /* BASE64_H */