v0.2.1 c0399be

ghmac.go RawHistoryFolder

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// HMACs should be used when producing a cookie or hash based on data
15// and a key. Simple mechanisms for using SHA1 and other algorithms to
16// digest a key and data together are vulnerable to various security
17// issues.
18// [HMAC](http://en.wikipedia.org/wiki/HMAC)
19// uses algorithms like SHA1 in a secure way to produce a digest of a
20// key and data.
21//
22// Both the key and data are arbitrary byte arrays of bytes or characters.
23//
24// Support for HMAC Digests has been added in GLib 2.30, and support for SHA-512
25// in GLib 2.42. Support for SHA-384 was added in GLib 2.52.
26//
27// To create a new `GHmac`, use [ctor@GLib.Hmac.new]. To free a `GHmac`, use
28// [method@GLib.Hmac.unref].
29type Hmac struct {
30	_ structs.HostLayout
31}
32
33var xHmacGLibType func() types.GType
34
35func HmacGLibType() types.GType {
36	return xHmacGLibType()
37}
38
39func (x *Hmac) GoPointer() uintptr {
40	return uintptr(unsafe.Pointer(x))
41}
42
43var xNewHmac func(ChecksumType, []byte, uint) *Hmac
44
45// Creates a new #GHmac, using the digest algorithm @digest_type.
46// If the @digest_type is not known, %NULL is returned.
47// A #GHmac can be used to compute the HMAC of a key and an
48// arbitrary binary blob, using different hashing algorithms.
49//
50// A #GHmac works by feeding a binary blob through g_hmac_update()
51// until the data is complete; the digest can then be extracted
52// using g_hmac_get_string(), which will return the checksum as a
53// hexadecimal string; or g_hmac_get_digest(), which will return a
54// array of raw bytes. Once either g_hmac_get_string() or
55// g_hmac_get_digest() have been called on a #GHmac, the HMAC
56// will be closed and it won't be possible to call g_hmac_update()
57// on it anymore.
58//
59// Support for digests of type %G_CHECKSUM_SHA512 has been added in GLib 2.42.
60// Support for %G_CHECKSUM_SHA384 was added in GLib 2.52.
61func NewHmac(DigestTypeVar ChecksumType, KeyVar []byte, KeyLenVar uint) *Hmac {
62
63	cret := xNewHmac(DigestTypeVar, KeyVar, KeyLenVar)
64	return cret
65}
66
67var xHmacCopy func(uintptr) *Hmac
68
69// Copies a #GHmac. If @hmac has been closed, by calling
70// g_hmac_get_string() or g_hmac_get_digest(), the copied
71// HMAC will be closed as well.
72func (x *Hmac) Copy() *Hmac {
73
74	cret := xHmacCopy(x.GoPointer())
75	return cret
76}
77
78var xHmacGetDigest func(uintptr, []byte, uint)
79
80// Gets the digest from @checksum as a raw binary array and places it
81// into @buffer. The size of the digest depends on the type of checksum.
82//
83// Once this function has been called, the #GHmac is closed and can
84// no longer be updated with g_checksum_update().
85func (x *Hmac) GetDigest(BufferVar []byte, DigestLenVar uint) {
86
87	xHmacGetDigest(x.GoPointer(), BufferVar, DigestLenVar)
88
89}
90
91var xHmacGetString func(uintptr) string
92
93// Gets the HMAC as a hexadecimal string.
94//
95// Once this function has been called the #GHmac can no longer be
96// updated with g_hmac_update().
97//
98// The hexadecimal characters will be lower case.
99func (x *Hmac) GetString() string {
100
101	cret := xHmacGetString(x.GoPointer())
102	return cret
103}
104
105var xHmacRef func(uintptr) *Hmac
106
107// Atomically increments the reference count of @hmac by one.
108//
109// This function is MT-safe and may be called from any thread.
110func (x *Hmac) Ref() *Hmac {
111
112	cret := xHmacRef(x.GoPointer())
113	return cret
114}
115
116var xHmacUnref func(uintptr)
117
118// Atomically decrements the reference count of @hmac by one.
119//
120// If the reference count drops to 0, all keys and values will be
121// destroyed, and all memory allocated by the hash table is released.
122// This function is MT-safe and may be called from any thread.
123// Frees the memory allocated for @hmac.
124func (x *Hmac) Unref() {
125
126	xHmacUnref(x.GoPointer())
127
128}
129
130var xHmacUpdate func(uintptr, []byte, int)
131
132// Feeds @data into an existing #GHmac.
133//
134// The HMAC must still be open, that is g_hmac_get_string() or
135// g_hmac_get_digest() must not have been called on @hmac.
136func (x *Hmac) Update(DataVar []byte, LengthVar int) {
137
138	xHmacUpdate(x.GoPointer(), DataVar, LengthVar)
139
140}
141
142var xComputeHmacForBytes func(ChecksumType, *Bytes, *Bytes) string
143
144// Computes the HMAC for a binary @data. This is a
145// convenience wrapper for g_hmac_new(), g_hmac_get_string()
146// and g_hmac_unref().
147//
148// The hexadecimal string returned will be in lower case.
149func ComputeHmacForBytes(DigestTypeVar ChecksumType, KeyVar *Bytes, DataVar *Bytes) string {
150
151	cret := xComputeHmacForBytes(DigestTypeVar, KeyVar, DataVar)
152
153	return cret
154}
155
156var xComputeHmacForData func(ChecksumType, []byte, uint, []byte, uint) string
157
158// Computes the HMAC for a binary @data of @length. This is a
159// convenience wrapper for g_hmac_new(), g_hmac_get_string()
160// and g_hmac_unref().
161//
162// The hexadecimal string returned will be in lower case.
163func ComputeHmacForData(DigestTypeVar ChecksumType, KeyVar []byte, KeyLenVar uint, DataVar []byte, LengthVar uint) string {
164
165	cret := xComputeHmacForData(DigestTypeVar, KeyVar, KeyLenVar, DataVar, LengthVar)
166
167	return cret
168}
169
170var xComputeHmacForString func(ChecksumType, []byte, uint, string, int) string
171
172// Computes the HMAC for a string.
173//
174// The hexadecimal string returned will be in lower case.
175func ComputeHmacForString(DigestTypeVar ChecksumType, KeyVar []byte, KeyLenVar uint, StrVar string, LengthVar int) string {
176
177	cret := xComputeHmacForString(DigestTypeVar, KeyVar, KeyLenVar, StrVar, LengthVar)
178
179	return cret
180}
181
182func init() {
183	core.SetPackageName("GLIB", "glib-2.0")
184	core.SetSharedLibraries("GLIB", []string{"libgobject-2.0.so.0", "libglib-2.0.so.0"})
185	var libs []uintptr
186	for _, libPath := range core.GetPaths("GLIB") {
187		lib, err := purego.Dlopen(libPath, purego.RTLD_NOW|purego.RTLD_GLOBAL)
188		if err != nil {
189			panic(err)
190		}
191		libs = append(libs, lib)
192	}
193
194	core.PuregoSafeRegister(&xComputeHmacForBytes, libs, "g_compute_hmac_for_bytes")
195	core.PuregoSafeRegister(&xComputeHmacForData, libs, "g_compute_hmac_for_data")
196	core.PuregoSafeRegister(&xComputeHmacForString, libs, "g_compute_hmac_for_string")
197
198	core.PuregoSafeRegister(&xHmacGLibType, libs, "g_hmac_get_type")
199
200	core.PuregoSafeRegister(&xNewHmac, libs, "g_hmac_new")
201
202	core.PuregoSafeRegister(&xHmacCopy, libs, "g_hmac_copy")
203	core.PuregoSafeRegister(&xHmacGetDigest, libs, "g_hmac_get_digest")
204	core.PuregoSafeRegister(&xHmacGetString, libs, "g_hmac_get_string")
205	core.PuregoSafeRegister(&xHmacRef, libs, "g_hmac_ref")
206	core.PuregoSafeRegister(&xHmacUnref, libs, "g_hmac_unref")
207	core.PuregoSafeRegister(&xHmacUpdate, libs, "g_hmac_update")
208
209}

Keyboard shortcuts

Single-key shortcuts are on. ctrl k and esc work whatever this says.

ctrl k :
go to a section, branch, tag, file or repository
?
this list
j k
move the row cursor down / up
enter
open the row under the cursor; on Files, a directory opens or closes in place
↑ ↓ ← → home end
in the file tree (focus on a row): previous / next row, close / open a directory or go to its parent / first entry, first / last row. They never open a file
l h
on Files: open a directory or a file / close a directory or go up to its parent, then to the parent page. Elsewhere: into the side panel (on a merge request, its files) / back to the content; there j k move between its controls
g g G
first / last row
/
filter the list; on Files, find a file anywhere in the repository (esc clears, enter opens the best match)
b
switch branch or tag
g s g f g c g b g m g i g r g a
tabs: summary, files, commits, branches & tags, merge requests, issues, releases, actions (when available)
g h
home
w
wide mode: use the whole width of the screen, or not (remembered)
y
copy a permalink pinned to the commit
d u x
diff: split / unified / collapse or expand all
e E
diff: the whole file in view / every file, with the lines the hunks hide
n
merge request: next note in the diff
esc
close a dialog, leave a field

Branches 1

Tags 102

↑↓ moveenter openesc close