project_files/frontlib/base64/base64.h
changeset 7316 f7b49b2c5d84
parent 7271 5608ac657362
child 8260 83d85e32c713
equal deleted inserted replaced
7314:6171f0bad318 7316:f7b49b2c5d84
     1 /* base64.h -- Encode binary data using printable characters.
     1 /* base64.h -- Encode binary data using printable characters.
     2    Copyright (C) 2004, 2005, 2006 Free Software Foundation, Inc.
     2    Copyright (C) 2004-2006, 2009-2012 Free Software Foundation, Inc.
     3    Written by Simon Josefsson.
     3    Written by Simon Josefsson.
     4 
     4 
     5    This program is free software; you can redistribute it and/or modify
     5    This program is free software; you can redistribute it and/or modify
     6    it under the terms of the GNU General Public License as published by
     6    it under the terms of the GNU General Public License as published by
     7    the Free Software Foundation; either version 2, or (at your option)
     7    the Free Software Foundation; either version 2, or (at your option)
    11    but WITHOUT ANY WARRANTY; without even the implied warranty of
    11    but WITHOUT ANY WARRANTY; without even the implied warranty of
    12    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    12    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    13    GNU General Public License for more details.
    13    GNU General Public License for more details.
    14 
    14 
    15    You should have received a copy of the GNU General Public License
    15    You should have received a copy of the GNU General Public License
    16    along with this program; if not, write to the Free Software Foundation,
    16    along with this program; if not, see <http://www.gnu.org/licenses/>.  */
    17    Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.  */
       
    18 
    17 
    19 #ifndef BASE64_H
    18 #ifndef BASE64_H
    20 # define BASE64_H
    19 # define BASE64_H
    21 
    20 
    22 /* Get size_t. */
    21 /* Get size_t. */
    27 
    26 
    28 /* This uses that the expression (n+(k-1))/k means the smallest
    27 /* This uses that the expression (n+(k-1))/k means the smallest
    29    integer >= n/k, i.e., the ceiling of n/k.  */
    28    integer >= n/k, i.e., the ceiling of n/k.  */
    30 # define BASE64_LENGTH(inlen) ((((inlen) + 2) / 3) * 4)
    29 # define BASE64_LENGTH(inlen) ((((inlen) + 2) / 3) * 4)
    31 
    30 
       
    31 struct base64_decode_context
       
    32 {
       
    33   unsigned int i;
       
    34   char buf[4];
       
    35 };
       
    36 
    32 extern bool isbase64 (char ch);
    37 extern bool isbase64 (char ch);
    33 
    38 
    34 extern void base64_encode (const char *restrict in, size_t inlen,
    39 extern void base64_encode (const char *restrict in, size_t inlen,
    35 			   char *restrict out, size_t outlen);
    40                            char *restrict out, size_t outlen);
    36 
    41 
    37 extern size_t base64_encode_alloc (const char *in, size_t inlen, char **out);
    42 extern size_t base64_encode_alloc (const char *in, size_t inlen, char **out);
    38 
    43 
    39 extern bool base64_decode (const char *restrict in, size_t inlen,
    44 extern void base64_decode_ctx_init (struct base64_decode_context *ctx);
    40 			   char *restrict out, size_t *outlen);
       
    41 
    45 
    42 extern bool base64_decode_alloc (const char *in, size_t inlen,
    46 extern bool base64_decode_ctx (struct base64_decode_context *ctx,
    43 				 char **out, size_t *outlen);
    47                                const char *restrict in, size_t inlen,
       
    48                                char *restrict out, size_t *outlen);
       
    49 
       
    50 extern bool base64_decode_alloc_ctx (struct base64_decode_context *ctx,
       
    51                                      const char *in, size_t inlen,
       
    52                                      char **out, size_t *outlen);
       
    53 
       
    54 #define base64_decode(in, inlen, out, outlen) \
       
    55         base64_decode_ctx (NULL, in, inlen, out, outlen)
       
    56 
       
    57 #define base64_decode_alloc(in, inlen, out, outlen) \
       
    58         base64_decode_alloc_ctx (NULL, in, inlen, out, outlen)
    44 
    59 
    45 #endif /* BASE64_H */
    60 #endif /* BASE64_H */