-
Notifications
You must be signed in to change notification settings - Fork 5
/
key_alg_factory.go
95 lines (69 loc) · 2.67 KB
/
key_alg_factory.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
package foundation
// #include <virgil/crypto/foundation/vscf_foundation_public.h>
import "C"
import "runtime"
import unsafe "unsafe"
/*
* Create a bridge between "raw keys" and algorithms that can import them.
*/
type KeyAlgFactory struct {
}
/*
* Create a key algorithm based on an identifier.
*/
func KeyAlgFactoryCreateFromAlgId(algId AlgId, random Random) (KeyAlg, error) {
var error C.vscf_error_t
C.vscf_error_reset(&error)
proxyResult := /*pr4*/C.vscf_key_alg_factory_create_from_alg_id(C.vscf_alg_id_t(algId) /*pa7*/, (*C.vscf_impl_t)(unsafe.Pointer(random.Ctx())), &error)
err := FoundationErrorHandleStatus(error.status)
if err != nil {
return nil, err
}
runtime.KeepAlive(random)
return FoundationImplementationWrapKeyAlg(proxyResult) /* r4 */
}
/*
* Create a key algorithm correspond to a specific key.
*/
func KeyAlgFactoryCreateFromKey(key Key, random Random) (KeyAlg, error) {
var error C.vscf_error_t
C.vscf_error_reset(&error)
proxyResult := /*pr4*/C.vscf_key_alg_factory_create_from_key((*C.vscf_impl_t)(unsafe.Pointer(key.Ctx())), (*C.vscf_impl_t)(unsafe.Pointer(random.Ctx())), &error)
err := FoundationErrorHandleStatus(error.status)
if err != nil {
return nil, err
}
runtime.KeepAlive(key)
runtime.KeepAlive(random)
return FoundationImplementationWrapKeyAlg(proxyResult) /* r4 */
}
/*
* Create a key algorithm that can import "raw public key".
*/
func KeyAlgFactoryCreateFromRawPublicKey(publicKey *RawPublicKey, random Random) (KeyAlg, error) {
var error C.vscf_error_t
C.vscf_error_reset(&error)
proxyResult := /*pr4*/C.vscf_key_alg_factory_create_from_raw_public_key((*C.vscf_raw_public_key_t)(unsafe.Pointer(publicKey.Ctx())), (*C.vscf_impl_t)(unsafe.Pointer(random.Ctx())), &error)
err := FoundationErrorHandleStatus(error.status)
if err != nil {
return nil, err
}
runtime.KeepAlive(publicKey)
runtime.KeepAlive(random)
return FoundationImplementationWrapKeyAlg(proxyResult) /* r4 */
}
/*
* Create a key algorithm that can import "raw private key".
*/
func KeyAlgFactoryCreateFromRawPrivateKey(privateKey *RawPrivateKey, random Random) (KeyAlg, error) {
var error C.vscf_error_t
C.vscf_error_reset(&error)
proxyResult := /*pr4*/C.vscf_key_alg_factory_create_from_raw_private_key((*C.vscf_raw_private_key_t)(unsafe.Pointer(privateKey.Ctx())), (*C.vscf_impl_t)(unsafe.Pointer(random.Ctx())), &error)
err := FoundationErrorHandleStatus(error.status)
if err != nil {
return nil, err
}
runtime.KeepAlive(privateKey)
runtime.KeepAlive(random)
return FoundationImplementationWrapKeyAlg(proxyResult) /* r4 */
}