...
1
2
3
4
5
6
7
8
9
10 package mongocrypt
11
12
13 import "C"
14
15
16 type KmsContext struct {
17 wrapped *C.mongocrypt_kms_ctx_t
18 }
19
20
21 func newKmsContext(wrapped *C.mongocrypt_kms_ctx_t) *KmsContext {
22 return &KmsContext{
23 wrapped: wrapped,
24 }
25 }
26
27
28 func (kc *KmsContext) HostName() (string, error) {
29 var hostname *C.char
30 if ok := C.mongocrypt_kms_ctx_endpoint(kc.wrapped, &hostname); !ok {
31 return "", kc.createErrorFromStatus()
32 }
33 return C.GoString(hostname), nil
34 }
35
36
37 func (kc *KmsContext) KMSProvider() string {
38 kmsProvider := C.mongocrypt_kms_ctx_get_kms_provider(kc.wrapped, nil)
39 return C.GoString(kmsProvider)
40 }
41
42
43 func (kc *KmsContext) Message() ([]byte, error) {
44 msgBinary := newBinary()
45 defer msgBinary.close()
46
47 if ok := C.mongocrypt_kms_ctx_message(kc.wrapped, msgBinary.wrapped); !ok {
48 return nil, kc.createErrorFromStatus()
49 }
50 return msgBinary.toBytes(), nil
51 }
52
53
54
55 func (kc *KmsContext) BytesNeeded() int32 {
56 return int32(C.mongocrypt_kms_ctx_bytes_needed(kc.wrapped))
57 }
58
59
60 func (kc *KmsContext) FeedResponse(response []byte) error {
61 responseBinary := newBinaryFromBytes(response)
62 defer responseBinary.close()
63
64 if ok := C.mongocrypt_kms_ctx_feed(kc.wrapped, responseBinary.wrapped); !ok {
65 return kc.createErrorFromStatus()
66 }
67 return nil
68 }
69
70
71 func (kc *KmsContext) createErrorFromStatus() error {
72 status := C.mongocrypt_status_new()
73 defer C.mongocrypt_status_destroy(status)
74 C.mongocrypt_kms_ctx_status(kc.wrapped, status)
75 return errorFromStatus(status)
76 }
77
View as plain text