1// Package glib was automatically generated by github.com/bnema/puregotk DO NOT EDIT
2package glib
3
4import (
5 "structs"
6 "unsafe"
7
8 "github.com/ebitengine/purego"
9
10 "github.com/bnema/puregotk/pkg/core"
11 "github.com/bnema/puregotk/v4/gobject/types"
12)
13
14// GLib provides a generic API for computing checksums (or ‘digests’)
15// for a sequence of arbitrary bytes, using various hashing algorithms
16// like MD5, SHA-1 and SHA-256. Checksums are commonly used in various
17// environments and specifications.
18//
19// To create a new `GChecksum`, use [ctor@GLib.Checksum.new]. To free
20// a `GChecksum`, use [method@GLib.Checksum.free].
21//
22// GLib supports incremental checksums using the `GChecksum` data
23// structure, by calling [method@GLib.Checksum.update] as long as there’s data
24// available and then using [method@GLib.Checksum.get_string] or
25// [method@GLib.Checksum.get_digest] to compute the checksum and return it
26// either as a string in hexadecimal form, or as a raw sequence of bytes. To
27// compute the checksum for binary blobs and nul-terminated strings in
28// one go, use the convenience functions [func@GLib.compute_checksum_for_data]
29// and [func@GLib.compute_checksum_for_string], respectively.
30type Checksum struct {
31 _ structs.HostLayout
32}
33
34var xChecksumGLibType func() types.GType
35
36func ChecksumGLibType() types.GType {
37 return xChecksumGLibType()
38}
39
40func (x *Checksum) GoPointer() uintptr {
41 return uintptr(unsafe.Pointer(x))
42}
43
44var xNewChecksum func(ChecksumType) *Checksum
45
46// Creates a new #GChecksum, using the checksum algorithm @checksum_type.
47// If the @checksum_type is not known, %NULL is returned.
48// A #GChecksum can be used to compute the checksum, or digest, of an
49// arbitrary binary blob, using different hashing algorithms.
50//
51// A #GChecksum works by feeding a binary blob through g_checksum_update()
52// until there is data to be checked; the digest can then be extracted
53// using g_checksum_get_string(), which will return the checksum as a
54// hexadecimal string; or g_checksum_get_digest(), which will return a
55// vector of raw bytes. Once either g_checksum_get_string() or
56// g_checksum_get_digest() have been called on a #GChecksum, the checksum
57// will be closed and it won't be possible to call g_checksum_update()
58// on it anymore.
59func NewChecksum(ChecksumTypeVar ChecksumType) *Checksum {
60
61 cret := xNewChecksum(ChecksumTypeVar)
62 return cret
63}
64
65var xChecksumCopy func(uintptr) *Checksum
66
67// Copies a #GChecksum. If @checksum has been closed, by calling
68// g_checksum_get_string() or g_checksum_get_digest(), the copied
69// checksum will be closed as well.
70func (x *Checksum) Copy() *Checksum {
71
72 cret := xChecksumCopy(x.GoPointer())
73 return cret
74}
75
76var xChecksumFree func(uintptr)
77
78// Frees the memory allocated for @checksum.
79func (x *Checksum) Free() {
80
81 xChecksumFree(x.GoPointer())
82
83}
84
85var xChecksumGetDigest func(uintptr, []byte, uint)
86
87// Gets the digest from @checksum as a raw binary vector and places it
88// into @buffer. The size of the digest depends on the type of checksum.
89//
90// Once this function has been called, the #GChecksum is closed and can
91// no longer be updated with g_checksum_update().
92func (x *Checksum) GetDigest(BufferVar []byte, DigestLenVar uint) {
93
94 xChecksumGetDigest(x.GoPointer(), BufferVar, DigestLenVar)
95
96}
97
98var xChecksumGetString func(uintptr) string
99
100// Gets the digest as a hexadecimal string.
101//
102// Once this function has been called the #GChecksum can no longer be
103// updated with g_checksum_update().
104//
105// The hexadecimal characters will be lower case.
106func (x *Checksum) GetString() string {
107
108 cret := xChecksumGetString(x.GoPointer())
109 return cret
110}
111
112var xChecksumReset func(uintptr)
113
114// Resets the state of the @checksum back to its initial state.
115func (x *Checksum) Reset() {
116
117 xChecksumReset(x.GoPointer())
118
119}
120
121var xChecksumUpdate func(uintptr, []byte, int)
122
123// Feeds @data into an existing #GChecksum. The checksum must still be
124// open, that is g_checksum_get_string() or g_checksum_get_digest() must
125// not have been called on @checksum.
126func (x *Checksum) Update(DataVar []byte, LengthVar int) {
127
128 xChecksumUpdate(x.GoPointer(), DataVar, LengthVar)
129
130}
131
132// The hashing algorithm to be used by #GChecksum when performing the
133// digest of some data.
134//
135// Note that the #GChecksumType enumeration may be extended at a later
136// date to include new hashing algorithm types.
137type ChecksumType int
138
139const (
140
141 // Use the MD5 hashing algorithm
142 GChecksumMd5Value ChecksumType = 0
143 // Use the SHA-1 hashing algorithm
144 GChecksumSha1Value ChecksumType = 1
145 // Use the SHA-256 hashing algorithm
146 GChecksumSha256Value ChecksumType = 2
147 // Use the SHA-512 hashing algorithm (Since: 2.36)
148 GChecksumSha512Value ChecksumType = 3
149 // Use the SHA-384 hashing algorithm (Since: 2.51)
150 GChecksumSha384Value ChecksumType = 4
151)
152
153var xChecksumTypeGetLength func(ChecksumType) int
154
155// Gets the length in bytes of digests of type @checksum_type
156func ChecksumTypeGetLength(ChecksumTypeVar ChecksumType) int {
157
158 cret := xChecksumTypeGetLength(ChecksumTypeVar)
159
160 return cret
161}
162
163var xComputeChecksumForBytes func(ChecksumType, *Bytes) string
164
165// Computes the checksum for a binary @data. This is a
166// convenience wrapper for g_checksum_new(), g_checksum_get_string()
167// and g_checksum_free().
168//
169// The hexadecimal string returned will be in lower case.
170func ComputeChecksumForBytes(ChecksumTypeVar ChecksumType, DataVar *Bytes) string {
171
172 cret := xComputeChecksumForBytes(ChecksumTypeVar, DataVar)
173
174 return cret
175}
176
177var xComputeChecksumForData func(ChecksumType, []byte, uint) string
178
179// Computes the checksum for a binary @data of @length. This is a
180// convenience wrapper for g_checksum_new(), g_checksum_get_string()
181// and g_checksum_free().
182//
183// The hexadecimal string returned will be in lower case.
184func ComputeChecksumForData(ChecksumTypeVar ChecksumType, DataVar []byte, LengthVar uint) string {
185
186 cret := xComputeChecksumForData(ChecksumTypeVar, DataVar, LengthVar)
187
188 return cret
189}
190
191var xComputeChecksumForString func(ChecksumType, string, int) string
192
193// Computes the checksum of a string.
194//
195// The hexadecimal string returned will be in lower case.
196func ComputeChecksumForString(ChecksumTypeVar ChecksumType, StrVar string, LengthVar int) string {
197
198 cret := xComputeChecksumForString(ChecksumTypeVar, StrVar, LengthVar)
199
200 return cret
201}
202
203func init() {
204 core.SetPackageName("GLIB", "glib-2.0")
205 core.SetSharedLibraries("GLIB", []string{"libgobject-2.0.so.0", "libglib-2.0.so.0"})
206 var libs []uintptr
207 for _, libPath := range core.GetPaths("GLIB") {
208 lib, err := purego.Dlopen(libPath, purego.RTLD_NOW|purego.RTLD_GLOBAL)
209 if err != nil {
210 panic(err)
211 }
212 libs = append(libs, lib)
213 }
214
215 core.PuregoSafeRegister(&xChecksumTypeGetLength, libs, "g_checksum_type_get_length")
216 core.PuregoSafeRegister(&xComputeChecksumForBytes, libs, "g_compute_checksum_for_bytes")
217 core.PuregoSafeRegister(&xComputeChecksumForData, libs, "g_compute_checksum_for_data")
218 core.PuregoSafeRegister(&xComputeChecksumForString, libs, "g_compute_checksum_for_string")
219
220 core.PuregoSafeRegister(&xChecksumGLibType, libs, "g_checksum_get_type")
221
222 core.PuregoSafeRegister(&xNewChecksum, libs, "g_checksum_new")
223
224 core.PuregoSafeRegister(&xChecksumCopy, libs, "g_checksum_copy")
225 core.PuregoSafeRegister(&xChecksumFree, libs, "g_checksum_free")
226 core.PuregoSafeRegister(&xChecksumGetDigest, libs, "g_checksum_get_digest")
227 core.PuregoSafeRegister(&xChecksumGetString, libs, "g_checksum_get_string")
228 core.PuregoSafeRegister(&xChecksumReset, libs, "g_checksum_reset")
229 core.PuregoSafeRegister(&xChecksumUpdate, libs, "g_checksum_update")
230
231}