Project

General

Profile

Statistics
| Branch: | Tag: | Revision:

gdp / ep / ep_b64.h @ master

History | View | Annotate | Download (3.11 KB)

1 a901db09 Eric Allman
/* vim: set ai sw=8 sts=8 ts=8 :*/
2 0c663d10 Eric Allman
3 055d3009 Eric Allman
/***********************************************************************
4
**  ----- BEGIN LICENSE BLOCK -----
5
**        LIBEP: Enhanced Portability Library (Reduced Edition)
6
**
7 c87dd166 Eric Allman
**        Copyright (c) 2008-2019, Eric P. Allman.  All rights reserved.
8
**        Copyright (c) 2015-2019, Regents of the University of California.
9 6bd5476b Eric Allman
**        All rights reserved.
10 055d3009 Eric Allman
**
11 6bd5476b Eric Allman
**        Permission is hereby granted, without written agreement and without
12
**        license or royalty fees, to use, copy, modify, and distribute this
13
**        software and its documentation for any purpose, provided that the above
14
**        copyright notice and the following two paragraphs appear in all copies
15
**        of this software.
16 055d3009 Eric Allman
**
17 6bd5476b Eric Allman
**        IN NO EVENT SHALL REGENTS BE LIABLE TO ANY PARTY FOR DIRECT, INDIRECT,
18
**        SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES, INCLUDING LOST
19
**        PROFITS, ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION,
20
**        EVEN IF REGENTS HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
21 055d3009 Eric Allman
**
22 6bd5476b Eric Allman
**        REGENTS SPECIFICALLY DISCLAIMS ANY WARRANTIES, INCLUDING, BUT NOT
23 055d3009 Eric Allman
**        LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
24 6bd5476b Eric Allman
**        FOR A PARTICULAR PURPOSE. THE SOFTWARE AND ACCOMPANYING DOCUMENTATION,
25
**        IF ANY, PROVIDED HEREUNDER IS PROVIDED "AS IS". REGENTS HAS NO
26
**        OBLIGATION TO PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS,
27
**        OR MODIFICATIONS.
28 055d3009 Eric Allman
**  ----- END LICENSE BLOCK -----
29
***********************************************************************/
30
31 767deba9 Eric Allman
/*
32
**  EP_B64.H --- Base 64 encoding/decoding
33
**
34
**        There are multiple ways of encoding Base64 depending on use.
35
**        Pretty much everyone agrees that values 0-61 are from the
36
**        set [A-Za-z0-9], but 62 and 63 are special characters which
37
**        vary based on context.  The "encoding" parameter is two or three
38
**        characters.  The first two are the encoding for those last two
39
**        values, and the last optional character represents flags as
40
**        a binary value added to the '@' character (so @ = 0, A = 1,
41
**        etc.)
42
**
43
**        XXX need to tell line length for encoding and whether other
44
**        characters are ignored for decoding.
45
*/
46
47
#ifndef _EP_B64_H_
48
#define _EP_B64_H_
49
50
#include <ep/ep.h>
51 e844af35 Eric Allman
__BEGIN_DECLS
52 767deba9 Eric Allman
53 37c00e89 Eric Allman
extern EP_STAT        ep_b64_encode(const void *bin,                // raw binary input
54 767deba9 Eric Allman
                                size_t bsize,                // sizeof bin
55
                                char *txt,                // text output buffer
56
                                size_t tsize,                // size of txt
57 37c00e89 Eric Allman
                                const char *encoding);        // encoding
58
extern EP_STAT        ep_b64_decode(const char *txt,                // text input
59 767deba9 Eric Allman
                                size_t tsize,                // sizeof txt
60
                                void *bin,                // output binary buffer
61
                                size_t bsize,                // sizeof bin
62 37c00e89 Eric Allman
                                const char *encoding);        // encoding
63 767deba9 Eric Allman
64
// flag bits; only the bottom six bits are available; bottom two bits
65
// encode wrap length
66
#define EP_B64_NOWRAP                0x00        // never wrap lines
67
#define EP_B64_WRAP64                0x01        // wrap at 64 characters
68
#define EP_B64_WRAP76                0x02        // wrap at 76 characters
69
#define EP_B64_WRAPMASK                0x03        // bit mask for wrapping
70
#define EP_B64_PAD                0x04        // pad with '='
71
#define EP_B64_IGNCRUD                0x08        // ignore unrecognized chars
72
73
// encodings for common standards
74
#define EP_B64_ENC_MIME                "+/N"        // WRAP76  PAD  IGNCRUD
75
#define EP_B64_ENC_PEM                "+/E"        // WRAP64  PAD -IGNCRUD
76
#define EP_B64_ENC_URL                "-_@"        // NOWRAP -PAD -IGNCRUD
77
78 e844af35 Eric Allman
__END_DECLS
79
80 767deba9 Eric Allman
#endif // _EP_B64_H_