1
|
|
|
package kms |
2
|
|
|
|
3
|
|
|
import ( |
4
|
|
|
"context" |
5
|
|
|
|
6
|
|
|
SDK "github.com/aws/aws-sdk-go-v2/service/kms" |
7
|
|
|
|
8
|
|
|
"github.com/evalphobia/aws-sdk-go-v2-wrapper/errors" |
9
|
|
|
"github.com/evalphobia/aws-sdk-go-v2-wrapper/private/pointers" |
10
|
|
|
) |
11
|
|
|
|
12
|
|
|
// ReEncrypt executes `ReEncrypt` operation. |
13
|
|
|
func (svc *KMS) ReEncrypt(ctx context.Context, r ReEncryptRequest) (*ReEncryptResult, error) { |
14
|
|
|
out, err := svc.RawReEncrypt(ctx, r.ToInput()) |
15
|
|
|
if err != nil { |
16
|
|
|
err = svc.errWrap(errors.ErrorData{ |
17
|
|
|
Err: err, |
18
|
|
|
AWSOperation: "ReEncrypt", |
19
|
|
|
}) |
20
|
|
|
svc.Errorf(err.Error()) |
|
|
|
|
21
|
|
|
return nil, err |
22
|
|
|
} |
23
|
|
|
return NewReEncryptResult(out), nil |
24
|
|
|
} |
25
|
|
|
|
26
|
|
|
// ReEncryptRequest has parameters for `ReEncrypt` operation. |
27
|
|
|
type ReEncryptRequest struct { |
28
|
|
|
CiphertextBlob []byte |
29
|
|
|
DestinationKeyID string |
30
|
|
|
|
31
|
|
|
// optional |
32
|
|
|
DestinationEncryptionAlgorithm EncryptionAlgorithmSpec |
33
|
|
|
DestinationEncryptionContext map[string]string |
34
|
|
|
GrantTokens []string |
35
|
|
|
SourceEncryptionAlgorithm EncryptionAlgorithmSpec |
36
|
|
|
SourceEncryptionContext map[string]string |
37
|
|
|
SourceKeyID string |
38
|
|
|
} |
39
|
|
|
|
40
|
|
|
func (r ReEncryptRequest) ToInput() *SDK.ReEncryptInput { |
|
|
|
|
41
|
|
|
in := &SDK.ReEncryptInput{} |
42
|
|
|
|
43
|
|
|
in.CiphertextBlob = r.CiphertextBlob |
44
|
|
|
if r.DestinationKeyID != "" { |
45
|
|
|
in.DestinationKeyId = pointers.String(r.DestinationKeyID) |
46
|
|
|
} |
47
|
|
|
|
48
|
|
|
in.DestinationEncryptionAlgorithm = SDK.EncryptionAlgorithmSpec(r.DestinationEncryptionAlgorithm) |
49
|
|
|
in.DestinationEncryptionContext = r.DestinationEncryptionContext |
50
|
|
|
in.GrantTokens = r.GrantTokens |
51
|
|
|
in.SourceEncryptionAlgorithm = SDK.EncryptionAlgorithmSpec(r.SourceEncryptionAlgorithm) |
52
|
|
|
in.SourceEncryptionContext = r.SourceEncryptionContext |
53
|
|
|
if r.SourceKeyID != "" { |
54
|
|
|
in.SourceKeyId = pointers.String(r.SourceKeyID) |
55
|
|
|
} |
56
|
|
|
return in |
57
|
|
|
} |
58
|
|
|
|
59
|
|
|
type ReEncryptResult struct { |
|
|
|
|
60
|
|
|
CiphertextBlob []byte |
61
|
|
|
DestinationEncryptionAlgorithm EncryptionAlgorithmSpec |
62
|
|
|
KeyID string |
63
|
|
|
SourceEncryptionAlgorithm EncryptionAlgorithmSpec |
64
|
|
|
SourceKeyID string |
65
|
|
|
} |
66
|
|
|
|
67
|
|
|
func NewReEncryptResult(output *SDK.ReEncryptResponse) *ReEncryptResult { |
|
|
|
|
68
|
|
|
r := &ReEncryptResult{} |
69
|
|
|
if output == nil { |
70
|
|
|
return r |
71
|
|
|
} |
72
|
|
|
|
73
|
|
|
r.CiphertextBlob = output.CiphertextBlob |
74
|
|
|
r.DestinationEncryptionAlgorithm = EncryptionAlgorithmSpec(output.DestinationEncryptionAlgorithm) |
75
|
|
|
|
76
|
|
|
if output.KeyId != nil { |
77
|
|
|
r.KeyID = *output.KeyId |
78
|
|
|
} |
79
|
|
|
|
80
|
|
|
r.SourceEncryptionAlgorithm = EncryptionAlgorithmSpec(output.SourceEncryptionAlgorithm) |
81
|
|
|
|
82
|
|
|
if output.SourceKeyId != nil { |
83
|
|
|
r.SourceKeyID = *output.SourceKeyId |
84
|
|
|
} |
85
|
|
|
return r |
86
|
|
|
} |
87
|
|
|
|