Skip to content

Commit 8cdb31a

Browse files
committed
feat(kmip): Import/Export suppport
1 parent c4fa4ae commit 8cdb31a

File tree

2 files changed

+162
-0
lines changed

2 files changed

+162
-0
lines changed

kmipclient/import_export.go

Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
package kmipclient
2+
3+
import (
4+
"github.com/ovh/kmip-go"
5+
"github.com/ovh/kmip-go/payloads"
6+
)
7+
8+
// ExecImport represents the execution of an import operation with the KMIP client.
9+
type ExecImport struct {
10+
Executor[*payloads.ImportRequestPayload, *payloads.ImportResponsePayload]
11+
}
12+
13+
// ExecExport represents the execution of an export operation with the KMIP client.
14+
type ExecExport struct {
15+
Executor[*payloads.ExportRequestPayload, *payloads.ExportResponsePayload]
16+
}
17+
18+
// ExecImportWantsAAD is a helper type that allows for fluent-style configuration of an import operation.
19+
type ExecImportWantsAAD struct {
20+
req *payloads.ImportRequestPayload
21+
client *Client
22+
}
23+
24+
// Import initializes an import operation with the client.
25+
func (c *Client) Import() ExecImportWantsAAD {
26+
return ExecImportWantsAAD{
27+
client: c,
28+
req: &payloads.ImportRequestPayload{},
29+
}
30+
}
31+
32+
// Export initializes an export operation with the client for a given key ID.
33+
func (c *Client) Export(id string) ExecExport {
34+
return ExecExport{
35+
Executor[*payloads.ExportRequestPayload, *payloads.ExportResponsePayload]{
36+
client: c,
37+
req: &payloads.ExportRequestPayload{UniqueIdentifier: id},
38+
},
39+
}
40+
}
41+
42+
// WithReplaceExisting sets the ReplaceExisting flag in the import request.
43+
func (ex ExecImportWantsAAD) WithReplaceExisting(replaceExisting bool) ExecImportWantsAAD {
44+
ex.req.ReplaceExisting = replaceExisting
45+
return ex
46+
}
47+
48+
// WithKeyWrapType sets the KeyWrapType in the import request.
49+
func (ex ExecImportWantsAAD) WithKeyWrapType(keyWrapType kmip.KeyWrapType) ExecImportWantsAAD {
50+
ex.req.KeyWrapType = keyWrapType
51+
return ex
52+
}
53+
54+
// AAD sets the AuthenticatedEncryptionAdditionalData in the import request and finalizes the import operation.
55+
func (ex ExecImportWantsAAD) AAD(aad []byte) ExecImport {
56+
ex.req.AuthenticatedEncryptionAdditionalData = aad
57+
return ExecImport{
58+
Executor[*payloads.ImportRequestPayload, *payloads.ImportResponsePayload]{
59+
client: ex.client,
60+
req: ex.req,
61+
},
62+
}
63+
}
64+
65+
// WithKeyFormatType sets the KeyFormatType in the export request.
66+
func (ex ExecExport) WithKeyFormatType(keyFormatType kmip.KeyFormatType) ExecExport {
67+
ex.req.KeyFormatType = keyFormatType
68+
return ex
69+
}
70+
71+
// WithKeyWrapType sets the KeyWrapType in the export request.
72+
func (ex ExecExport) WithKeyWrapType(keyWrapType kmip.KeyWrapType) ExecExport {
73+
ex.req.KeyWrapType = keyWrapType
74+
return ex
75+
}
76+
77+
// WithKeyCompressionType sets the KeyCompressionType in the export request.
78+
func (ex ExecExport) WithKeyCompressionType(keyCompressionType kmip.KeyCompressionType) ExecExport {
79+
ex.req.KeyCompressionType = keyCompressionType
80+
return ex
81+
}
82+
83+
// WithKeyWrappingSpecification sets the KeyWrappingSpecification in the export request.
84+
func (ex ExecExport) WithKeyWrappingSpecification(keyWrappingSpecification kmip.KeyWrappingSpecification) ExecExport {
85+
ex.req.KeyWrappingSpecification = keyWrappingSpecification
86+
return ex
87+
}

payloads/import_export.go

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
package payloads
2+
3+
import "github.com/ovh/kmip-go"
4+
5+
// init registers the Import and Export operation payloads with the KMIP package.
6+
func init() {
7+
kmip.RegisterOperationPayload[ImportRequestPayload, ImportResponsePayload](kmip.OperationImport)
8+
kmip.RegisterOperationPayload[ExportRequestPayload, ExportResponsePayload](kmip.OperationExport)
9+
}
10+
11+
// ImportRequestPayload represents the payload for the Import operation request.
12+
type ImportRequestPayload struct {
13+
// UniqueIdentifier is an optional field that specifies the unique identifier of the object to be imported.
14+
UniqueIdentifier string
15+
// ReplaceExisting is an optional field that specifies whether to replace an existing object with the imported one.
16+
ReplaceExisting bool `ttlv:",omitempty,version=v1.4.."`
17+
// KeyWrapType is an optional field that specifies the key wrapping type used for the imported key material.
18+
KeyWrapType kmip.KeyWrapType `ttlv:",omitempty,version=v1.4.."`
19+
// Attribute is an optional field that specifies additional attributes for the imported object.
20+
Attribute kmip.Attribute `ttlv:",omitempty,version=v1.4.."`
21+
// AuthenticatedEncryptionAdditionalData is a required field that specifies additional data for authenticated encryption.
22+
AuthenticatedEncryptionAdditionalData []byte `ttlv:",version=v1.4.."`
23+
}
24+
25+
// Operation returns the operation type for the ImportRequestPayload.
26+
func (a *ImportRequestPayload) Operation() kmip.Operation {
27+
return kmip.OperationImport
28+
}
29+
30+
// ImportResponsePayload represents the payload for the Import operation response.
31+
type ImportResponsePayload struct {
32+
// UniqueIdentifier is a required field that specifies the unique identifier of the imported object.
33+
UniqueIdentifier string `ttlv:",version=v1.4.."`
34+
}
35+
36+
// Operation returns the operation type for the ImportResponsePayload.
37+
func (a *ImportResponsePayload) Operation() kmip.Operation {
38+
return kmip.OperationImport
39+
}
40+
41+
// ExportRequestPayload represents the payload for the Export operation request.
42+
type ExportRequestPayload struct {
43+
// UniqueIdentifier is an optional field that specifies the unique identifier of the object to be exported.
44+
UniqueIdentifier string `ttlv:",omitempty,version=v1.4.."`
45+
// KeyFormatType is an optional field that specifies the format type of the exported key material.
46+
KeyFormatType kmip.KeyFormatType `ttlv:",omitempty,version=v1.4.."`
47+
// KeyWrapType is an optional field that specifies the key wrapping type used for the exported key material.
48+
KeyWrapType kmip.KeyWrapType `ttlv:",omitempty,version=v1.4.."`
49+
// KeyCompressionType is an optional field that specifies the compression type used for the exported key material.
50+
KeyCompressionType kmip.KeyCompressionType `ttlv:",omitempty,version=v1.4.."`
51+
// KeyWrappingSpecification is an optional field that specifies the key wrapping specification for the exported key material.
52+
KeyWrappingSpecification kmip.KeyWrappingSpecification `ttlv:",omitempty,version=v1.4.."`
53+
}
54+
55+
// Operation returns the operation type for the ExportRequestPayload.
56+
func (a *ExportRequestPayload) Operation() kmip.Operation {
57+
return kmip.OperationExport
58+
}
59+
60+
// ExportResponsePayload represents the payload for the Export operation response.
61+
type ExportResponsePayload struct {
62+
// ObjectType is a required field that specifies the type of the exported object.
63+
ObjectType kmip.ObjectType `ttlv:",version=v1.4.."`
64+
// UniqueIdentifier is a required field that specifies the unique identifier of the exported object.
65+
UniqueIdentifier string `ttlv:",version=v1.4.."`
66+
// Attribute is a required field that specifies additional attributes for the exported object.
67+
Attribute kmip.Attribute `ttlv:",version=v1.4.."`
68+
// AuthenticatedEncryptionAdditionalData is a required field that specifies additional data for authenticated encryption.
69+
AuthenticatedEncryptionAdditionalData []byte `ttlv:",version=v1.4.."`
70+
}
71+
72+
// Operation returns the operation type for the ExportResponsePayload.
73+
func (a *ExportResponsePayload) Operation() kmip.Operation {
74+
return kmip.OperationExport
75+
}

0 commit comments

Comments
 (0)