1 /*
2  * This file is part of gtkD.
3  *
4  * gtkD is free software; you can redistribute it and/or modify
5  * it under the terms of the GNU Lesser General Public License
6  * as published by the Free Software Foundation; either version 3
7  * of the License, or (at your option) any later version, with
8  * some exceptions, please read the COPYING file.
9  *
10  * gtkD is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13  * GNU Lesser General Public License for more details.
14  *
15  * You should have received a copy of the GNU Lesser General Public License
16  * along with gtkD; if not, write to the Free Software
17  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110, USA
18  */
19 
20 // generated automatically - do not change
21 // find conversion definition on APILookup.txt
22 // implement new conversion functionalities on the wrap.utils pakage
23 
24 
25 module glib.Base64;
26 
27 private import glib.Str;
28 private import gtkc.glib;
29 public  import gtkc.glibtypes;
30 
31 
32 /** */
33 public struct Base64
34 {
35 	/**
36 	 * Incrementally decode a sequence of binary data from its Base-64 stringified
37 	 * representation. By calling this function multiple times you can convert
38 	 * data in chunks to avoid having to have the full encoded data in memory.
39 	 *
40 	 * The output buffer must be large enough to fit all the data that will
41 	 * be written to it. Since base64 encodes 3 bytes in 4 chars you need
42 	 * at least: (@len / 4) * 3 + 3 bytes (+ 3 may be needed in case of non-zero
43 	 * state).
44 	 *
45 	 * Params:
46 	 *     inn = binary input data
47 	 *     len = max length of @in data to decode
48 	 *     output = output buffer
49 	 *     state = Saved state between steps, initialize to 0
50 	 *     save = Saved state between steps, initialize to 0
51 	 *
52 	 * Return: The number of bytes of output that was written
53 	 *
54 	 * Since: 2.12
55 	 */
56 	public static size_t decodeStep(string inn, ref ubyte[] output, ref int state, ref uint save)
57 	{
58 		auto p = g_base64_decode_step(Str.toStringz(inn), cast(int)inn.length, cast(char*)output.ptr, &state, &save);
59 		
60 		return p;
61 	}
62 
63 	/**
64 	 */
65 
66 	/**
67 	 * Decode a sequence of Base-64 encoded text into binary data
68 	 * by overwriting the input data.
69 	 *
70 	 * Params:
71 	 *     text = zero-terminated
72 	 *         string with base64 text to decode
73 	 *
74 	 * Return: The binary data that @text responds. This pointer
75 	 *     is the same as the input @text.
76 	 *
77 	 * Since: 2.20
78 	 */
79 	public static char[] decodeInplace(ref char[] text)
80 	{
81 		size_t outLen = cast(size_t)text.length;
82 		
83 		auto p = g_base64_decode_inplace(text.ptr, &outLen);
84 		
85 		text = text[0..outLen];
86 		
87 		return p[0 .. outLen];
88 	}
89 
90 	/**
91 	 * Decode a sequence of Base-64 encoded text into binary data.  Note
92 	 * that the returned binary data is not necessarily zero-terminated,
93 	 * so it should not be used as a character string.
94 	 *
95 	 * Params:
96 	 *     text = zero-terminated string with base64 text to decode
97 	 *
98 	 * Return: newly allocated buffer containing the binary data
99 	 *     that @text represents. The returned buffer must
100 	 *     be freed with g_free().
101 	 *
102 	 * Since: 2.12
103 	 */
104 	public static char[] decode(string text)
105 	{
106 		size_t outLen;
107 		
108 		auto p = g_base64_decode(Str.toStringz(text), &outLen);
109 		
110 		return p[0 .. outLen];
111 	}
112 
113 	/**
114 	 * Encode a sequence of binary data into its Base-64 stringified
115 	 * representation.
116 	 *
117 	 * Params:
118 	 *     data = the binary data to encode
119 	 *     len = the length of @data
120 	 *
121 	 * Return: a newly allocated, zero-terminated Base-64
122 	 *     encoded string representing @data. The returned string must
123 	 *     be freed with g_free().
124 	 *
125 	 * Since: 2.12
126 	 */
127 	public static string encode(char[] data)
128 	{
129 		return Str.toString(g_base64_encode(data.ptr, cast(size_t)data.length));
130 	}
131 
132 	/**
133 	 * Flush the status from a sequence of calls to g_base64_encode_step().
134 	 *
135 	 * The output buffer must be large enough to fit all the data that will
136 	 * be written to it. It will need up to 4 bytes, or up to 5 bytes if
137 	 * line-breaking is enabled.
138 	 *
139 	 * Params:
140 	 *     breakLines = whether to break long lines
141 	 *     output = pointer to destination buffer
142 	 *     state = Saved state from g_base64_encode_step()
143 	 *     save = Saved state from g_base64_encode_step()
144 	 *
145 	 * Return: The number of bytes of output that was written
146 	 *
147 	 * Since: 2.12
148 	 */
149 	public static size_t encodeClose(bool breakLines, out char[] output, ref int state, ref int save)
150 	{
151 		return g_base64_encode_close(breakLines, output.ptr, &state, &save);
152 	}
153 
154 	/**
155 	 * Incrementally encode a sequence of binary data into its Base-64 stringified
156 	 * representation. By calling this function multiple times you can convert
157 	 * data in chunks to avoid having to have the full encoded data in memory.
158 	 *
159 	 * When all of the data has been converted you must call
160 	 * g_base64_encode_close() to flush the saved state.
161 	 *
162 	 * The output buffer must be large enough to fit all the data that will
163 	 * be written to it. Due to the way base64 encodes you will need
164 	 * at least: (@len / 3 + 1) * 4 + 4 bytes (+ 4 may be needed in case of
165 	 * non-zero state). If you enable line-breaking you will need at least:
166 	 * ((@len / 3 + 1) * 4 + 4) / 72 + 1 bytes of extra space.
167 	 *
168 	 * @break_lines is typically used when putting base64-encoded data in emails.
169 	 * It breaks the lines at 72 columns instead of putting all of the text on
170 	 * the same line. This avoids problems with long lines in the email system.
171 	 * Note however that it breaks the lines with `LF` characters, not
172 	 * `CR LF` sequences, so the result cannot be passed directly to SMTP
173 	 * or certain other protocols.
174 	 *
175 	 * Params:
176 	 *     inn = the binary data to encode
177 	 *     len = the length of @in
178 	 *     breakLines = whether to break long lines
179 	 *     output = pointer to destination buffer
180 	 *     state = Saved state between steps, initialize to 0
181 	 *     save = Saved state between steps, initialize to 0
182 	 *
183 	 * Return: The number of bytes of output that was written
184 	 *
185 	 * Since: 2.12
186 	 */
187 	public static size_t encodeStep(char[] inn, bool breakLines, out char[] output, ref int state, ref int save)
188 	{
189 		return g_base64_encode_step(inn.ptr, cast(size_t)inn.length, breakLines, output.ptr, &state, &save);
190 	}
191 }