-
Notifications
You must be signed in to change notification settings - Fork 18
/
response.go
92 lines (80 loc) · 3.01 KB
/
response.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
package kmip
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
import (
"time"
"github.com/pkg/errors"
)
// Response is a Response Message Structure
type Response struct {
Tag `kmip:"RESPONSE_MESSAGE"`
Header ResponseHeader `kmip:"RESPONSE_HEADER,required"`
BatchItems []ResponseBatchItem `kmip:"RESPONSE_BATCH_ITEM,required"`
}
// ResponseHeader is a Response Header Structure
type ResponseHeader struct {
Tag `kmip:"RESPONSE_HEADER"`
Version ProtocolVersion `kmip:"PROTOCOL_VERSION,required"`
TimeStamp time.Time `kmip:"TIME_STAMP,required"`
Nonce Nonce `kmip:"NONCE"`
AttestationType []Enum `kmip:"ATTESTATION_TYPE"`
ClientCorrelationValue string `kmip:"CLIENT_CORRELATION_VALUE"`
ServerCorrelationValue string `kmip:"SERVER_CORRELATION_VALUE"`
BatchCount int32 `kmip:"BATCH_COUNT,required"`
}
// ResponseBatchItem is a Response Batch Item Structure
type ResponseBatchItem struct {
Operation Enum `kmip:"OPERATION,required"`
UniqueID []byte `kmip:"UNIQUE_BATCH_ITEM_ID"`
ResultStatus Enum `kmip:"RESULT_STATUS,required"`
ResultReason Enum `kmip:"RESULT_REASON"`
ResultMessage string `kmip:"RESULT_MESSAGE"`
AsyncronousCorrelationValue []byte `kmip:"ASYNCHRONOUS_CORRELATION_VALUE"`
ResponsePayload interface{} `kmip:"RESPONSE_PAYLOAD"`
MessageExtension MessageExtension `kmip:"MESSAGE_EXTENSION"`
}
// BuildFieldValue builds value for ResponsePayload based on Operation
func (bi *ResponseBatchItem) BuildFieldValue(name string) (v interface{}, err error) {
switch bi.Operation {
case OPERATION_CREATE:
v = &CreateResponse{}
case OPERATION_CREATE_KEY_PAIR:
v = &CreateKeyPairResponse{}
case OPERATION_GET:
v = &GetResponse{}
case OPERATION_GET_ATTRIBUTES:
v = &GetAttributesResponse{}
case OPERATION_GET_ATTRIBUTE_LIST:
v = &GetAttributeListResponse{}
case OPERATION_ACTIVATE:
v = &ActivateResponse{}
case OPERATION_REVOKE:
v = &RevokeResponse{}
case OPERATION_DESTROY:
v = &DestroyResponse{}
case OPERATION_DISCOVER_VERSIONS:
v = &DiscoverVersionsResponse{}
case OPERATION_ENCRYPT:
v = &EncryptResponse{}
case OPERATION_DECRYPT:
v = &DecryptResponse{}
case OPERATION_SIGN:
v = &SignResponse{}
case OPERATION_REGISTER:
v = &RegisterResponse{}
case OPERATION_LOCATE:
v = &LocateResponse{}
case OPERATION_REKEY:
v = &ReKeyResponse{}
default:
err = errors.Errorf("unsupported operation: %v", bi.Operation)
}
return
}
// Nonce object is a structure used by the server to send a random value to the client
type Nonce struct {
Tag `kmip:"NONCE"`
NonceID []byte `kmip:"NONCE_ID,required"`
NonceValue []byte `kmip:"NONCE_VALUE,required"`
}