forked from ThalesGroup/kmip-go
-
Notifications
You must be signed in to change notification settings - Fork 0
/
op_discover_versions.go
45 lines (37 loc) · 960 Bytes
/
op_discover_versions.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
package kmip
import (
"context"
)
// 4.26
type DiscoverVersionsRequestPayload struct {
ProtocolVersion []ProtocolVersion
}
type DiscoverVersionsResponsePayload struct {
ProtocolVersion []ProtocolVersion
}
type DiscoverVersionsHandler struct {
SupportedVersions []ProtocolVersion
}
func (h *DiscoverVersionsHandler) HandleItem(ctx context.Context, req *Request) (item *ResponseBatchItem, err error) {
var payload DiscoverVersionsRequestPayload
err = req.DecodePayload(&payload)
if err != nil {
return nil, err
}
var respPayload DiscoverVersionsResponsePayload
if len(payload.ProtocolVersion) == 0 {
respPayload.ProtocolVersion = h.SupportedVersions
} else {
for _, v := range h.SupportedVersions {
for _, cv := range payload.ProtocolVersion {
if cv == v {
respPayload.ProtocolVersion = append(respPayload.ProtocolVersion, v)
break
}
}
}
}
return &ResponseBatchItem{
ResponsePayload: respPayload,
}, nil
}