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-Data-Checksums.html
27  * outPack = glib
28  * outFile = Checksum
29  * strct   = GChecksum
30  * realStrct=
31  * ctorStrct=
32  * clss    = Checksum
33  * interf  = 
34  * class Code: No
35  * interface Code: No
36  * template for:
37  * extend  = 
38  * implements:
39  * prefixes:
40  * 	- g_checksum_
41  * omit structs:
42  * omit prefixes:
43  * omit code:
44  * omit signals:
45  * imports:
46  * 	- glib.Str
47  * structWrap:
48  * 	- GChecksum* -> Checksum
49  * module aliases:
50  * local aliases:
51  * overrides:
52  */
53 
54 module glib.Checksum;
55 
56 public  import gtkc.glibtypes;
57 
58 private import gtkc.glib;
59 private import glib.ConstructionException;
60 
61 
62 private import glib.Str;
63 
64 
65 
66 
67 /**
68  * Description
69  * GLib provides a generic API for computing checksums (or "digests")
70  * for a sequence of arbitrary bytes, using various hashing algorithms
71  * like MD5, SHA-1 and SHA-256. Checksums are commonly used in various
72  * environments and specifications.
73  * GLib supports incremental checksums using the GChecksum data
74  * structure, by calling g_checksum_update() as long as there's data
75  * available and then using g_checksum_get_string() or
76  * g_checksum_get_digest() to compute the checksum and return it either
77  * as a string in hexadecimal form, or as a raw sequence of bytes. To
78  * compute the checksum for binary blobs and NUL-terminated strings in
79  * one go, use the convenience functions g_compute_checksum_for_data()
80  * and g_compute_checksum_for_string(), respectively.
81  * Support for checksums has been added in GLib 2.16
82  */
83 public class Checksum
84 {
85 	
86 	/** the main Gtk struct */
87 	protected GChecksum* gChecksum;
88 	
89 	
90 	public GChecksum* getChecksumStruct()
91 	{
92 		return gChecksum;
93 	}
94 	
95 	
96 	/** the main Gtk struct as a void* */
97 	protected void* getStruct()
98 	{
99 		return cast(void*)gChecksum;
100 	}
101 	
102 	/**
103 	 * Sets our main struct and passes it to the parent class
104 	 */
105 	public this (GChecksum* gChecksum)
106 	{
107 		this.gChecksum = gChecksum;
108 	}
109 	
110 	/**
111 	 */
112 	
113 	/**
114 	 * Gets the length in bytes of digests of type checksum_type
115 	 * Since 2.16
116 	 * Params:
117 	 * checksumType = a GChecksumType
118 	 * Returns: the checksum length, or -1 if checksum_type is not supported.
119 	 */
120 	public static gssize typeGetLength(GChecksumType checksumType)
121 	{
122 		// gssize g_checksum_type_get_length (GChecksumType checksum_type);
123 		return g_checksum_type_get_length(checksumType);
124 	}
125 	
126 	/**
127 	 * Creates a new GChecksum, using the checksum algorithm checksum_type.
128 	 * If the checksum_type is not known, NULL is returned.
129 	 * A GChecksum can be used to compute the checksum, or digest, of an
130 	 * arbitrary binary blob, using different hashing algorithms.
131 	 * A GChecksum works by feeding a binary blob through g_checksum_update()
132 	 * until there is data to be checked; the digest can then be extracted
133 	 * using g_checksum_get_string(), which will return the checksum as a
134 	 * hexadecimal string; or g_checksum_get_digest(), which will return a
135 	 * vector of raw bytes. Once either g_checksum_get_string() or
136 	 * g_checksum_get_digest() have been called on a GChecksum, the checksum
137 	 * will be closed and it won't be possible to call g_checksum_update()
138 	 * on it anymore.
139 	 * Since 2.16
140 	 * Params:
141 	 * checksumType = the desired type of checksum
142 	 * Throws: ConstructionException GTK+ fails to create the object.
143 	 */
144 	public this (GChecksumType checksumType)
145 	{
146 		// GChecksum * g_checksum_new (GChecksumType checksum_type);
147 		auto p = g_checksum_new(checksumType);
148 		if(p is null)
149 		{
150 			throw new ConstructionException("null returned by g_checksum_new(checksumType)");
151 		}
152 		this(cast(GChecksum*) p);
153 	}
154 	
155 	/**
156 	 * Copies a GChecksum. If checksum has been closed, by calling
157 	 * g_checksum_get_string() or g_checksum_get_digest(), the copied
158 	 * checksum will be closed as well.
159 	 * Since 2.16
160 	 * Returns: the copy of the passed GChecksum. Use g_checksum_free() when finished using it.
161 	 */
162 	public Checksum copy()
163 	{
164 		// GChecksum * g_checksum_copy (const GChecksum *checksum);
165 		auto p = g_checksum_copy(gChecksum);
166 		
167 		if(p is null)
168 		{
169 			return null;
170 		}
171 		
172 		return new Checksum(cast(GChecksum*) p);
173 	}
174 	
175 	/**
176 	 * Frees the memory allocated for checksum.
177 	 * Since 2.16
178 	 */
179 	public void free()
180 	{
181 		// void g_checksum_free (GChecksum *checksum);
182 		g_checksum_free(gChecksum);
183 	}
184 	
185 	/**
186 	 * Resets the state of the checksum back to its initial state.
187 	 * Since 2.18
188 	 */
189 	public void reset()
190 	{
191 		// void g_checksum_reset (GChecksum *checksum);
192 		g_checksum_reset(gChecksum);
193 	}
194 	
195 	/**
196 	 * Feeds data into an existing GChecksum. The checksum must still be
197 	 * open, that is g_checksum_get_string() or g_checksum_get_digest() must
198 	 * not have been called on checksum.
199 	 * Since 2.16
200 	 * Params:
201 	 * data = buffer used to compute the checksum
202 	 * length = size of the buffer, or -1 if it is a null-terminated string.
203 	 */
204 	public void update(char* data, gssize length)
205 	{
206 		// void g_checksum_update (GChecksum *checksum,  const guchar *data,  gssize length);
207 		g_checksum_update(gChecksum, data, length);
208 	}
209 	
210 	/**
211 	 * Gets the digest as an hexadecimal string.
212 	 * Once this function has been called the GChecksum can no longer be
213 	 * updated with g_checksum_update().
214 	 * The hexadecimal characters will be lower case.
215 	 * Since 2.16
216 	 * Returns: the hexadecimal representation of the checksum. The returned string is owned by the checksum and should not be modified or freed.
217 	 */
218 	public string getString()
219 	{
220 		// const gchar * g_checksum_get_string (GChecksum *checksum);
221 		return Str.toString(g_checksum_get_string(gChecksum));
222 	}
223 	
224 	/**
225 	 * Gets the digest from checksum as a raw binary vector and places it
226 	 * into buffer. The size of the digest depends on the type of checksum.
227 	 * Once this function has been called, the GChecksum is closed and can
228 	 * no longer be updated with g_checksum_update().
229 	 * Since 2.16
230 	 * Params:
231 	 * buffer = output buffer
232 	 * digestLen = an inout parameter. The caller initializes it to the size of buffer.
233 	 * After the call it contains the length of the digest.
234 	 */
235 	public void getDigest(ubyte* buffer, gsize* digestLen)
236 	{
237 		// void g_checksum_get_digest (GChecksum *checksum,  guint8 *buffer,  gsize *digest_len);
238 		g_checksum_get_digest(gChecksum, buffer, digestLen);
239 	}
240 	
241 	/**
242 	 * Computes the checksum for a binary data of length. This is a
243 	 * convenience wrapper for g_checksum_new(), g_checksum_get_string()
244 	 * and g_checksum_free().
245 	 * The hexadecimal string returned will be in lower case.
246 	 * Since 2.16
247 	 * Params:
248 	 * checksumType = a GChecksumType
249 	 * data = binary blob to compute the digest of
250 	 * length = length of data
251 	 * Returns: the digest of the binary data as a string in hexadecimal. The returned string should be freed with g_free() when done using it.
252 	 */
253 	public static string gComputeChecksumForData(GChecksumType checksumType, char* data, gsize length)
254 	{
255 		// gchar * g_compute_checksum_for_data (GChecksumType checksum_type,  const guchar *data,  gsize length);
256 		return Str.toString(g_compute_checksum_for_data(checksumType, data, length));
257 	}
258 	
259 	/**
260 	 * Computes the checksum of a string.
261 	 * The hexadecimal string returned will be in lower case.
262 	 * Since 2.16
263 	 * Params:
264 	 * checksumType = a GChecksumType
265 	 * str = the string to compute the checksum of
266 	 * length = the length of the string, or -1 if the string is null-terminated.
267 	 * Returns: the checksum as a hexadecimal string. The returned string should be freed with g_free() when done using it.
268 	 */
269 	public static string gComputeChecksumForString(GChecksumType checksumType, string str, gssize length)
270 	{
271 		// gchar * g_compute_checksum_for_string (GChecksumType checksum_type,  const gchar *str,  gssize length);
272 		return Str.toString(g_compute_checksum_for_string(checksumType, Str.toStringz(str), length));
273 	}
274 }