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

kms.NewDecryptResult   A

Complexity

Conditions 3

Size

Total Lines 12
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 3
eloc 9
nop 1
dl 0
loc 12
rs 9.95
c 0
b 0
f 0
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
// Decrypt executes `Decrypt` operation.
13
func (svc *KMS) Decrypt(ctx context.Context, r DecryptRequest) (*DecryptResult, error) {
14
	out, err := svc.RawDecrypt(ctx, r.ToInput())
15
	if err != nil {
16
		err = svc.errWrap(errors.ErrorData{
17
			Err:          err,
18
			AWSOperation: "Decrypt",
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 NewDecryptResult(out), nil
24
}
25
26
// DecryptRequest has parameters for `Decrypt` operation.
27
type DecryptRequest struct {
28
	CiphertextBlob []byte
29
30
	// optional
31
	EncryptionAlgorithm EncryptionAlgorithmSpec
32
	EncryptionContext   map[string]string
33
	GrantTokens         []string
34
	KeyID               string
35
}
36
37
func (r DecryptRequest) ToInput() *SDK.DecryptInput {
0 ignored issues
show
introduced by
exported method DecryptRequest.ToInput should have comment or be unexported
Loading history...
38
	in := &SDK.DecryptInput{}
39
40
	in.CiphertextBlob = r.CiphertextBlob
41
	in.EncryptionAlgorithm = SDK.EncryptionAlgorithmSpec(r.EncryptionAlgorithm)
42
	in.EncryptionContext = r.EncryptionContext
43
	in.GrantTokens = r.GrantTokens
44
45
	if r.KeyID != "" {
46
		in.KeyId = pointers.String(r.KeyID)
47
	}
48
	return in
49
}
50
51
type DecryptResult struct {
0 ignored issues
show
introduced by
exported type DecryptResult should have comment or be unexported
Loading history...
52
	EncryptionAlgorithm EncryptionAlgorithmSpec
53
	KeyID               string
54
	Plaintext           []byte
55
}
56
57
func NewDecryptResult(output *SDK.DecryptResponse) *DecryptResult {
0 ignored issues
show
introduced by
exported function NewDecryptResult should have comment or be unexported
Loading history...
58
	r := &DecryptResult{}
59
	if output == nil {
60
		return r
61
	}
62
63
	r.EncryptionAlgorithm = EncryptionAlgorithmSpec(output.EncryptionAlgorithm)
64
	if output.KeyId != nil {
65
		r.KeyID = *output.KeyId
66
	}
67
	r.Plaintext = output.Plaintext
68
	return r
69
}
70