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  * Conversion parameters:
26  * inFile  = glib-Base64-Encoding.html
27  * outPack = glib
28  * outFile = Base64
29  * strct   = 
30  * realStrct=
31  * ctorStrct=
32  * clss    = Base64
33  * interf  = 
34  * class Code: No
35  * interface Code: No
36  * template for:
37  * extend  = 
38  * implements:
39  * prefixes:
40  * 	- g_base64_
41  * omit structs:
42  * omit prefixes:
43  * omit code:
44  * omit signals:
45  * imports:
46  * 	- glib.Str
47  * structWrap:
48  * module aliases:
49  * local aliases:
50  * overrides:
51  */
52 
53 module glib.Base64;
54 
55 public  import gtkc.glibtypes;
56 
57 private import gtkc.glib;
58 private import glib.ConstructionException;
59 
60 private import glib.Str;
61 
62 
63 
64 /**
65  * Base64 is an encoding that allows a sequence of arbitrary bytes to be
66  * encoded as a sequence of printable ASCII characters. For the definition
67  * of Base64, see RFC
68  * 1421 or RFC
69  * 2045. Base64 is most commonly used as a MIME transfer encoding
70  * for email.
71  *
72  * GLib supports incremental encoding using g_base64_encode_step() and
73  * g_base64_encode_close(). Incremental decoding can be done with
74  * g_base64_decode_step(). To encode or decode data in one go, use
75  * g_base64_encode() or g_base64_decode(). To avoid memory allocation when
76  * decoding, you can use g_base64_decode_inplace().
77  *
78  * Support for Base64 encoding has been added in GLib 2.12.
79  */
80 public class Base64
81 {
82 	
83 	/**
84 	 */
85 	
86 	/**
87 	 * Incrementally encode a sequence of binary data into its Base-64 stringified
88 	 * representation. By calling this function multiple times you can convert
89 	 * data in chunks to avoid having to have the full encoded data in memory.
90 	 * When all of the data has been converted you must call
91 	 * g_base64_encode_close() to flush the saved state.
92 	 * The output buffer must be large enough to fit all the data that will
93 	 * be written to it. Due to the way base64 encodes you will need
94 	 * at least: (len / 3 + 1) * 4 + 4 bytes (+ 4 may be needed in case of
95 	 * Since 2.12
96 	 * Params:
97 	 * in = the binary data to encode. [array length=len][element-type guint8]
98 	 * breakLines = whether to break long lines
99 	 * out = pointer to destination buffer. [out][array][element-type guint8]
100 	 * state = Saved state between steps, initialize to 0. [inout]
101 	 * save = Saved state between steps, initialize to 0. [inout]
102 	 * Returns: The number of bytes of output that was written
103 	 */
104 	public static gsize encodeStep(char[] inn, int breakLines, string f_out, ref int state, ref int save)
105 	{
106 		// gsize g_base64_encode_step (const guchar *in,  gsize len,  gboolean break_lines,  gchar *out,  gint *state,  gint *save);
107 		return g_base64_encode_step(inn.ptr, cast(int) inn.length, breakLines, Str.toStringz(f_out), &state, &save);
108 	}
109 	
110 	/**
111 	 * Flush the status from a sequence of calls to g_base64_encode_step().
112 	 * The output buffer must be large enough to fit all the data that will
113 	 * be written to it. It will need up to 4 bytes, or up to 5 bytes if
114 	 * line-breaking is enabled.
115 	 * Since 2.12
116 	 * Params:
117 	 * breakLines = whether to break long lines
118 	 * out = pointer to destination buffer. [out][array][element-type guint8]
119 	 * state = Saved state from g_base64_encode_step(). [inout]
120 	 * save = Saved state from g_base64_encode_step(). [inout]
121 	 * Returns: The number of bytes of output that was written
122 	 */
123 	public static gsize encodeClose(int breakLines, string f_out, ref int state, ref int save)
124 	{
125 		// gsize g_base64_encode_close (gboolean break_lines,  gchar *out,  gint *state,  gint *save);
126 		return g_base64_encode_close(breakLines, Str.toStringz(f_out), &state, &save);
127 	}
128 	
129 	/**
130 	 * Encode a sequence of binary data into its Base-64 stringified
131 	 * representation.
132 	 * Since 2.12
133 	 * Params:
134 	 * data = the binary data to encode. [array length=len][element-type guint8]
135 	 * Returns: a newly allocated, zero-terminated Base-64 encoded string representing data. The returned string must be freed with g_free(). [transfer full]
136 	 */
137 	public static string encode(char[] data)
138 	{
139 		// gchar * g_base64_encode (const guchar *data,  gsize len);
140 		return Str.toString(g_base64_encode(data.ptr, cast(int) data.length));
141 	}
142 	
143 	/**
144 	 * Incrementally decode a sequence of binary data from its Base-64 stringified
145 	 * representation. By calling this function multiple times you can convert
146 	 * data in chunks to avoid having to have the full encoded data in memory.
147 	 * The output buffer must be large enough to fit all the data that will
148 	 * be written to it. Since base64 encodes 3 bytes in 4 chars you need
149 	 * at least: (len / 4) * 3 + 3 bytes (+ 3 may be needed in case of non-zero
150 	 * state).
151 	 * Since 2.12
152 	 * Params:
153 	 * in = binary input data. [array length=len][element-type guint8]
154 	 * out = output buffer. [out][array][element-type guint8]
155 	 * state = Saved state between steps, initialize to 0. [inout]
156 	 * save = Saved state between steps, initialize to 0. [inout]
157 	 * Returns: The number of bytes of output that was written
158 	 */
159 	public static gsize decodeStep(string inn, char* f_out, ref int state, ref uint save)
160 	{
161 		// gsize g_base64_decode_step (const gchar *in,  gsize len,  guchar *out,  gint *state,  guint *save);
162 		return g_base64_decode_step(cast(char*)inn.ptr, cast(int) inn.length, f_out, &state, &save);
163 	}
164 	
165 	/**
166 	 * Decode a sequence of Base-64 encoded text into binary data. Note
167 	 * that the returned binary data is not necessarily zero-terminated,
168 	 * so it should not be used as a character string.
169 	 * Since 2.12
170 	 * Params:
171 	 * text = zero-terminated string with base64 text to decode
172 	 * Returns: newly allocated buffer containing the binary data that text represents. The returned buffer must be freed with g_free(). [transfer full][array length=out_len][element-type guint8]
173 	 */
174 	public static char[] decode(string text)
175 	{
176 		// guchar * g_base64_decode (const gchar *text,  gsize *out_len);
177 		gsize outLen;
178 		auto p = g_base64_decode(Str.toStringz(text), &outLen);
179 		
180 		if(p is null)
181 		{
182 			return null;
183 		}
184 		
185 		return p[0 .. outLen];
186 	}
187 	
188 	/**
189 	 * Decode a sequence of Base-64 encoded text into binary data
190 	 * by overwriting the input data.
191 	 * Since 2.20
192 	 * Params:
193 	 * text = zero-terminated
194 	 * string with base64 text to decode. [inout][array length=out_len][element-type guint8]
195 	 * Returns: The binary data that text responds. This pointer is the same as the input text. [transfer none]
196 	 */
197 	public static char[] decodeInplace(string text)
198 	{
199 		// guchar * g_base64_decode_inplace (gchar *text,  gsize *out_len);
200 		gsize outLen;
201 		auto p = g_base64_decode_inplace(Str.toStringz(text), &outLen);
202 		
203 		if(p is null)
204 		{
205 			return null;
206 		}
207 		
208 		return p[0 .. outLen];
209 	}
210 }