Passed
Pull Request — master (#11)
by eval
01:29
created

kms/client_op_re_encrypt.go   A

Size/Duplication

Total Lines 85
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
cc 9
eloc 55
dl 0
loc 85
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A kms.*KMS.ReEncrypt 0 11 2
A kms.NewReEncryptResult 0 19 4
A kms.ReEncryptRequest.ToInput 0 17 3
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())
0 ignored issues
show
introduced by
can't check non-constant format in call to Errorf
Loading history...
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 {
0 ignored issues
show
introduced by
exported method ReEncryptRequest.ToInput should have comment or be unexported
Loading history...
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 {
0 ignored issues
show
introduced by
exported type ReEncryptResult should have comment or be unexported
Loading history...
60
	CiphertextBlob                 []byte
61
	DestinationEncryptionAlgorithm EncryptionAlgorithmSpec
62
	KeyID                          string
63
	SourceEncryptionAlgorithm      EncryptionAlgorithmSpec
64
	SourceKeyID                    string
65
}
66
67
func NewReEncryptResult(output *SDK.ReEncryptResponse) *ReEncryptResult {
0 ignored issues
show
introduced by
exported function NewReEncryptResult should have comment or be unexported
Loading history...
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