-
Notifications
You must be signed in to change notification settings - Fork 5
/
seed_entropy_source.go
115 lines (93 loc) · 2.65 KB
/
seed_entropy_source.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
package foundation
// #include <virgil/crypto/foundation/vscf_foundation_public.h>
import "C"
import "runtime"
import unsafe "unsafe"
/*
* Deterministic entropy source that is based only on the given seed.
*/
type SeedEntropySource struct {
cCtx *C.vscf_seed_entropy_source_t /*ct10*/
}
/*
* Set a new seed as an entropy source.
*/
func (obj *SeedEntropySource) ResetSeed(seed []byte) {
seedData := helperWrapData (seed)
C.vscf_seed_entropy_source_reset_seed(obj.cCtx, seedData)
runtime.KeepAlive(obj)
return
}
/* Handle underlying C context. */
func (obj *SeedEntropySource) Ctx() uintptr {
return uintptr(unsafe.Pointer(obj.cCtx))
}
func NewSeedEntropySource() *SeedEntropySource {
ctx := C.vscf_seed_entropy_source_new()
obj := &SeedEntropySource {
cCtx: ctx,
}
runtime.SetFinalizer(obj, (*SeedEntropySource).Delete)
return obj
}
/* Acquire C context.
* Note. This method is used in generated code only, and SHOULD NOT be used in another way.
*/
func newSeedEntropySourceWithCtx(ctx *C.vscf_seed_entropy_source_t /*ct10*/) *SeedEntropySource {
obj := &SeedEntropySource {
cCtx: ctx,
}
runtime.SetFinalizer(obj, (*SeedEntropySource).Delete)
return obj
}
/* Acquire retained C context.
* Note. This method is used in generated code only, and SHOULD NOT be used in another way.
*/
func newSeedEntropySourceCopy(ctx *C.vscf_seed_entropy_source_t /*ct10*/) *SeedEntropySource {
obj := &SeedEntropySource {
cCtx: C.vscf_seed_entropy_source_shallow_copy(ctx),
}
runtime.SetFinalizer(obj, (*SeedEntropySource).Delete)
return obj
}
/*
* Release underlying C context.
*/
func (obj *SeedEntropySource) Delete() {
if obj == nil {
return
}
runtime.SetFinalizer(obj, nil)
obj.delete()
}
/*
* Release underlying C context.
*/
func (obj *SeedEntropySource) delete() {
C.vscf_seed_entropy_source_delete(obj.cCtx)
}
/*
* Defines that implemented source is strong.
*/
func (obj *SeedEntropySource) IsStrong() bool {
proxyResult := /*pr4*/C.vscf_seed_entropy_source_is_strong(obj.cCtx)
runtime.KeepAlive(obj)
return bool(proxyResult) /* r9 */
}
/*
* Gather entropy of the requested length.
*/
func (obj *SeedEntropySource) Gather(len uint) ([]byte, error) {
outBuf, outBufErr := newBuffer(int(len))
if outBufErr != nil {
return nil, outBufErr
}
defer outBuf.delete()
proxyResult := /*pr4*/C.vscf_seed_entropy_source_gather(obj.cCtx, (C.size_t)(len)/*pa10*/, outBuf.ctx)
err := FoundationErrorHandleStatus(proxyResult)
if err != nil {
return nil, err
}
runtime.KeepAlive(obj)
return outBuf.getData() /* r7 */, nil
}