File: libb64.h

package info (click to toggle)
p4est 2.3.6-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 8,536 kB
  • sloc: ansic: 87,528; makefile: 855; sh: 635; perl: 272; python: 226; awk: 40; javascript: 23
file content (139 lines) | stat: -rw-r--r-- 3,937 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139

/*
 * adapted from libb64 by CB
 */

/* #define SC_BASE64_WRAP */

#include <stdlib.h>

/*
cdecode.h - c header for a base64 decoding algorithm

This is part of the libb64 project, and has been placed in the public domain.
For details, see http://sourceforge.net/projects/libb64
*/

#ifndef BASE64_CDECODE_H
#define BASE64_CDECODE_H

#ifdef __cplusplus
extern              "C"
{
#if 0
}
#endif
#endif

typedef enum
{
  step_a, step_b, step_c, step_d
}
base64_decodestep;

typedef struct
{
  base64_decodestep   step;
  char                plainchar;
}
base64_decodestate;

/** This function needs to be called to initialize the internal decoder state.
 * Does not allocate any memory so no cleanup function is necessary after use.
 * \param [out] state_in        Internal state of decoder.
 */
void                base64_init_decodestate (base64_decodestate * state_in);

/** Decode a chunk of data.
 * This function can be called multiple times for the same state_in.
 * \param [in] code_in          Data in base64 encoding.
 * \param [in] length_in        Length of code_in in bytes.
 * \param [out] plaintext_out   Memory of at least length_in bytes that will
 *                              contain the plaintext on output.
 * \param [in,out] state_in     Internal state of decoder.
 * \return                      Byte length of decoded data in plaintext_out.
 */
size_t              base64_decode_block (const char *code_in,
                                         size_t length_in,
                                         char *plaintext_out,
                                         base64_decodestate * state_in);

#ifdef __cplusplus
#if 0
{
#endif
}
#endif

#endif /* BASE64_CDECODE_H */

/*
cencode.h - c header for a base64 encoding algorithm

This is part of the libb64 project, and has been placed in the public domain.
For details, see http://sourceforge.net/projects/libb64
*/

#ifndef BASE64_CENCODE_H
#define BASE64_CENCODE_H

#ifdef __cplusplus
extern              "C"
{
#if 0
}
#endif
#endif

typedef enum
{
  step_A, step_B, step_C
}
base64_encodestep;

typedef struct
{
  base64_encodestep   step;
  char                result;
  int                 stepcount;
}
base64_encodestate;

/** This function needs to be called to initialize the internal encoder state.
 * Does not allocate any memory so no cleanup function is necessary after use.
 * \param [out] state_in        Internal state of encoder.
 */
void                base64_init_encodestate (base64_encodestate * state_in);

/** Encode a chunk of data.
 * This function can be called multiple times for the same state_in.
 * \param [in] plaintext_in     Data to be base64 encoded.
 * \param [in] length_in        Length of plaintext_in in bytes.
 * \param [out] code_out        Memory of at least 2 * length_in that will
 *                              contain the base64 encoded data on output.
 * \param [in,out] state_in     Internal state of encoder.
 * \return                      Byte length of encoded data in code_out.
 */
size_t              base64_encode_block (const char *plaintext_in,
                                         size_t length_in, char *code_out,
                                         base64_encodestate * state_in);

/** Flush remaining code bytes after all input data have been encoded.
 * Must be called when the encoding is done to create valid base64 data.
 * \param [out] code_out        Memory of at least 4 bytes that will contain
 *                              the final encoded bits.
 * \param [in,out] state_in     Internal state of encoder.
 *                              Needs base64_init_encodestate to be used again.
 * \return                      Number of final bytes written to code_out.
 */
size_t              base64_encode_blockend (char *code_out,
                                            base64_encodestate * state_in);

#ifdef __cplusplus
#if 0
{
#endif
}
#endif

#endif /* BASE64_CENCODE_H */