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 public struct Base64
33 {
34 	/**
35 	 * Incrementally decode a sequence of binary data from its Base-64 stringified
36 	 * representation. By calling this function multiple times you can convert
37 	 * data in chunks to avoid having to have the full encoded data in memory.
38 	 *
39 	 * The output buffer must be large enough to fit all the data that will
40 	 * be written to it. Since base64 encodes 3 bytes in 4 chars you need
41 	 * at least: (@len / 4) * 3 + 3 bytes (+ 3 may be needed in case of non-zero
42 	 * state).
43 	 *
44 	 * Params:
45 	 *     inn = binary input data
46 	 *     len = max length of @in data to decode
47 	 *     output = output buffer
48 	 *     state = Saved state between steps, initialize to 0
49 	 *     save = Saved state between steps, initialize to 0
50 	 *
51 	 * Return: The number of bytes of output that was written
52 	 *
53 	 * Since: 2.12
54 	 */
55 	public static size_t decodeStep(string inn, ref ubyte[] output, ref int state, ref uint save)
56 	{
57 		auto p = g_base64_decode_step(Str.toStringz(inn), cast(int)inn.length, cast(char*)output.ptr, &state, &save);
58 		
59 		return p;
60 	}
61 
62 	/**
63 	 */
64 
65 	/**
66 	 * Decode a sequence of Base-64 encoded text into binary data.  Note
67 	 * that the returned binary data is not necessarily zero-terminated,
68 	 * so it should not be used as a character string.
69 	 *
70 	 * Params:
71 	 *     text = zero-terminated string with base64 text to decode
72 	 *     outLen = The length of the decoded data is written here
73 	 *
74 	 * Return: newly allocated buffer containing the binary data
75 	 *     that @text represents. The returned buffer must
76 	 *     be freed with g_free().
77 	 *
78 	 * Since: 2.12
79 	 */
80 	public static string decode(string text)
81 	{
82 		size_t outLen;
83 		
84 		return Str.toString(g_base64_decode(Str.toStringz(text), &outLen));
85 	}
86 
87 	/**
88 	 * Decode a sequence of Base-64 encoded text into binary data
89 	 * by overwriting the input data.
90 	 *
91 	 * Params:
92 	 *     text = zero-terminated
93 	 *         string with base64 text to decode
94 	 *     outLen = The length of the decoded data is written here
95 	 *
96 	 * Return: The binary data that @text responds. This pointer
97 	 *     is the same as the input @text.
98 	 *
99 	 * Since: 2.20
100 	 */
101 	public static string decodeInplace(ref char[] text)
102 	{
103 		size_t outLen = cast(size_t)text.length;
104 		
105 		auto p = g_base64_decode_inplace(text.ptr, &outLen);
106 		
107 		text = text[0..outLen];
108 		
109 		return Str.toString(p);
110 	}
111 
112 	/**
113 	 * Encode a sequence of binary data into its Base-64 stringified
114 	 * representation.
115 	 *
116 	 * Params:
117 	 *     data = the binary data to encode
118 	 *     len = the length of @data
119 	 *
120 	 * Return: a newly allocated, zero-terminated Base-64
121 	 *     encoded string representing @data. The returned string must
122 	 *     be freed with g_free().
123 	 *
124 	 * Since: 2.12
125 	 */
126 	public static string encode(string data)
127 	{
128 		return Str.toString(g_base64_encode(Str.toStringz(data), cast(size_t)data.length));
129 	}
130 
131 	/**
132 	 * Flush the status from a sequence of calls to g_base64_encode_step().
133 	 *
134 	 * The output buffer must be large enough to fit all the data that will
135 	 * be written to it. It will need up to 4 bytes, or up to 5 bytes if
136 	 * line-breaking is enabled.
137 	 *
138 	 * Params:
139 	 *     breakLines = whether to break long lines
140 	 *     output = pointer to destination buffer
141 	 *     state = Saved state from g_base64_encode_step()
142 	 *     save = Saved state from g_base64_encode_step()
143 	 *
144 	 * Return: The number of bytes of output that was written
145 	 *
146 	 * Since: 2.12
147 	 */
148 	public static size_t encodeClose(bool breakLines, out char[] output, ref int state, ref int save)
149 	{
150 		return g_base64_encode_close(breakLines, output.ptr, &state, &save);
151 	}
152 
153 	/**
154 	 * Incrementally encode a sequence of binary data into its Base-64 stringified
155 	 * representation. By calling this function multiple times you can convert
156 	 * data in chunks to avoid having to have the full encoded data in memory.
157 	 *
158 	 * When all of the data has been converted you must call
159 	 * g_base64_encode_close() to flush the saved state.
160 	 *
161 	 * The output buffer must be large enough to fit all the data that will
162 	 * be written to it. Due to the way base64 encodes you will need
163 	 * at least: (@len / 3 + 1) * 4 + 4 bytes (+ 4 may be needed in case of
164 	 * non-zero state). If you enable line-breaking you will need at least:
165 	 * ((@len / 3 + 1) * 4 + 4) / 72 + 1 bytes of extra space.
166 	 *
167 	 * @break_lines is typically used when putting base64-encoded data in emails.
168 	 * It breaks the lines at 72 columns instead of putting all of the text on
169 	 * the same line. This avoids problems with long lines in the email system.
170 	 * Note however that it breaks the lines with `LF` characters, not
171 	 * `CR LF` sequences, so the result cannot be passed directly to SMTP
172 	 * or certain other protocols.
173 	 *
174 	 * Params:
175 	 *     inn = the binary data to encode
176 	 *     len = the length of @in
177 	 *     breakLines = whether to break long lines
178 	 *     output = pointer to destination buffer
179 	 *     state = Saved state between steps, initialize to 0
180 	 *     save = Saved state between steps, initialize to 0
181 	 *
182 	 * Return: The number of bytes of output that was written
183 	 *
184 	 * Since: 2.12
185 	 */
186 	public static size_t encodeStep(string inn, bool breakLines, out char[] output, ref int state, ref int save)
187 	{
188 		return g_base64_encode_step(Str.toStringz(inn), cast(size_t)inn.length, breakLines, output.ptr, &state, &save);
189 	}
190 }