kms

package
v0.2.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 27, 2020 License: MIT Imports: 8 Imported by: 0

README

aws-sdk-go-v2-wrapper | KMS

Quick Usage

import (
	"context"

	"github.com/evalphobia/aws-sdk-go-v2-wrapper/config"
	"github.com/evalphobia/aws-sdk-go-v2-wrapper/kms"
)

func main() {
	svc, err := kms.New(config.Config{
		AccessKey: "<...>",
		SecretKey: "<...>",
	})
	if err != nil {
		panic(err)
	}

	ctx := context.Background()
	base64Text, err := svc.XEncryptString(ctx, "alias/my-key", "I love you!")
	if err != nil {
		panic(err)
	}

	plainText, err := svc.XDecryptString(ctx, base64Text)
	if err != nil {
		panic(err)
	}

	if plainText != "I love you!" {
		panic("'plainText' should be 'I love you!'")
	}
	// ...
}

X API

Name Description
XDeleteKey deletes the key using 'ScheduleKeyDeletion'.
XEncryptBytes encrypts the 'plainData' using the 'key' and returns 'encryptedData'.
XEncryptString encrypts the 'plainText' using the 'key' and returns encrypted 'base64Text'.
XDecryptBytes decrypts the 'encryptedData'.
XDecryptString decrypts the 'base64Text'.
XReEncryptBytes re-encrypts the 'encryptedData' using 'destinationKey'.
XReEncryptString re-encrypts the 'base64Text' using 'destinationKey'.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type CreateAliasRequest

type CreateAliasRequest struct {
	AliasName   string
	TargetKeyID string
}

CreateAliasRequest has parameters for `CreateAlias` operation.

func (CreateAliasRequest) ToInput

type CreateKeyRequest

type CreateKeyRequest struct {
	BypassPolicyLockoutSafetyCheck bool
	CustomKeyStoreID               string
	CustomerMasterKeySpec          CustomerMasterKeySpec
	Description                    string
	KeyUsage                       KeyUsageType
	Origin                         OriginType
	Policy                         string
	Tags                           []Tag
}

CreateKeyRequest has parameters for `CreateKey` operation.

func (CreateKeyRequest) ToInput

func (r CreateKeyRequest) ToInput() *SDK.CreateKeyInput

type CreateKeyResult

type CreateKeyResult struct {
	KeyMetadata KeyMetadata
}

func NewCreateKeyResult

func NewCreateKeyResult(output *SDK.CreateKeyResponse) *CreateKeyResult

type DecryptRequest

type DecryptRequest struct {
	CiphertextBlob []byte

	// optional
	EncryptionAlgorithm EncryptionAlgorithmSpec
	EncryptionContext   map[string]string
	GrantTokens         []string
	KeyID               string
}

DecryptRequest has parameters for `Decrypt` operation.

func (DecryptRequest) ToInput

func (r DecryptRequest) ToInput() *SDK.DecryptInput

type DecryptResult

type DecryptResult struct {
	EncryptionAlgorithm EncryptionAlgorithmSpec
	KeyID               string
	Plaintext           []byte
}

func NewDecryptResult

func NewDecryptResult(output *SDK.DecryptResponse) *DecryptResult

type DescribeKeyRequest

type DescribeKeyRequest struct {
	KeyID string

	// optional
	GrantTokens []string
}

DescribeKeyRequest has parameters for `DescribeKey` operation.

func (DescribeKeyRequest) ToInput

type DescribeKeyResult

type DescribeKeyResult struct {
	KeyMetadata KeyMetadata
}

func NewDescribeKeyResult

func NewDescribeKeyResult(output *SDK.DescribeKeyResponse) *DescribeKeyResult

type EncryptRequest

type EncryptRequest struct {
	KeyID     string
	Plaintext []byte

	// optional
	EncryptionAlgorithm EncryptionAlgorithmSpec
	EncryptionContext   map[string]string
	GrantTokens         []string
}

EncryptRequest has parameters for `Encrypt` operation.

func (EncryptRequest) ToInput

func (r EncryptRequest) ToInput() *SDK.EncryptInput

type EncryptResult

type EncryptResult struct {
	CiphertextBlob      []byte
	EncryptionAlgorithm EncryptionAlgorithmSpec
	KeyID               string
}

func NewEncryptResult

func NewEncryptResult(output *SDK.EncryptResponse) *EncryptResult

type ExpirationModelType

type ExpirationModelType string

type KMS

type KMS struct {
	// contains filtered or unexported fields
}

KMS has KMS client.

func New

func New(conf config.Config) (*KMS, error)

New returns initialized *KMS.

func (*KMS) CreateAlias

func (svc *KMS) CreateAlias(ctx context.Context, r CreateAliasRequest) error

CreateAlias executes `CreateAlias` operation.

func (*KMS) CreateKey

func (svc *KMS) CreateKey(ctx context.Context, r CreateKeyRequest) (*CreateKeyResult, error)

CreateKey executes `CreateKey` operation.

func (*KMS) Decrypt

func (svc *KMS) Decrypt(ctx context.Context, r DecryptRequest) (*DecryptResult, error)

Decrypt executes `Decrypt` operation.

func (*KMS) DescribeKey

func (svc *KMS) DescribeKey(ctx context.Context, r DescribeKeyRequest) (*DescribeKeyResult, error)

DescribeKey executes `DescribeKey` operation.

func (*KMS) Encrypt

func (svc *KMS) Encrypt(ctx context.Context, r EncryptRequest) (*EncryptResult, error)

Encrypt executes `Encrypt` operation.

func (*KMS) Errorf

func (svc *KMS) Errorf(format string, v ...interface{})

Errorf logging error information.

func (*KMS) GetClient

func (svc *KMS) GetClient() *SDK.Client

GetClient gets original SDK client.

func (*KMS) Infof

func (svc *KMS) Infof(format string, v ...interface{})

Infof logging information.

func (*KMS) RawCancelKeyDeletion

func (svc *KMS) RawCancelKeyDeletion(ctx context.Context, in *SDK.CancelKeyDeletionInput) (*SDK.CancelKeyDeletionResponse, error)

RawCancelKeyDeletion executes `CancelKeyDeletion` raw operation.

func (*KMS) RawConnectCustomKeyStore

func (svc *KMS) RawConnectCustomKeyStore(ctx context.Context, in *SDK.ConnectCustomKeyStoreInput) (*SDK.ConnectCustomKeyStoreResponse, error)

RawConnectCustomKeyStore executes `ConnectCustomKeyStore` raw operation.

func (*KMS) RawCreateAlias

func (svc *KMS) RawCreateAlias(ctx context.Context, in *SDK.CreateAliasInput) (*SDK.CreateAliasResponse, error)

RawCreateAlias executes `CreateAlias` raw operation.

func (*KMS) RawCreateCustomKeyStore

func (svc *KMS) RawCreateCustomKeyStore(ctx context.Context, in *SDK.CreateCustomKeyStoreInput) (*SDK.CreateCustomKeyStoreResponse, error)

RawCreateCustomKeyStore executes `CreateCustomKeyStore` raw operation.

func (*KMS) RawCreateGrant

func (svc *KMS) RawCreateGrant(ctx context.Context, in *SDK.CreateGrantInput) (*SDK.CreateGrantResponse, error)

RawCreateGrant executes `CreateGrant` raw operation.

func (*KMS) RawCreateKey

func (svc *KMS) RawCreateKey(ctx context.Context, in *SDK.CreateKeyInput) (*SDK.CreateKeyResponse, error)

RawCreateKey executes `CreateKey` raw operation.

func (*KMS) RawDecrypt

func (svc *KMS) RawDecrypt(ctx context.Context, in *SDK.DecryptInput) (*SDK.DecryptResponse, error)

RawDecrypt executes `Decrypt` raw operation.

func (*KMS) RawDeleteAlias

func (svc *KMS) RawDeleteAlias(ctx context.Context, in *SDK.DeleteAliasInput) (*SDK.DeleteAliasResponse, error)

RawDeleteAlias executes `DeleteAlias` raw operation.

func (*KMS) RawDeleteCustomKeyStore

func (svc *KMS) RawDeleteCustomKeyStore(ctx context.Context, in *SDK.DeleteCustomKeyStoreInput) (*SDK.DeleteCustomKeyStoreResponse, error)

RawDeleteCustomKeyStore executes `DeleteCustomKeyStore` raw operation.

func (*KMS) RawDeleteImportedKeyMaterial

func (svc *KMS) RawDeleteImportedKeyMaterial(ctx context.Context, in *SDK.DeleteImportedKeyMaterialInput) (*SDK.DeleteImportedKeyMaterialResponse, error)

RawDeleteImportedKeyMaterial executes `DeleteImportedKeyMaterial` raw operation.

func (*KMS) RawDescribeCustomKeyStores

func (svc *KMS) RawDescribeCustomKeyStores(ctx context.Context, in *SDK.DescribeCustomKeyStoresInput) (*SDK.DescribeCustomKeyStoresResponse, error)

RawDescribeCustomKeyStores executes `DescribeCustomKeyStores` raw operation.

func (*KMS) RawDescribeKey

func (svc *KMS) RawDescribeKey(ctx context.Context, in *SDK.DescribeKeyInput) (*SDK.DescribeKeyResponse, error)

RawDescribeKey executes `DescribeKey` raw operation.

func (*KMS) RawDisableKey

func (svc *KMS) RawDisableKey(ctx context.Context, in *SDK.DisableKeyInput) (*SDK.DisableKeyResponse, error)

RawDisableKey executes `DisableKey` raw operation.

func (*KMS) RawDisableKeyRotation

func (svc *KMS) RawDisableKeyRotation(ctx context.Context, in *SDK.DisableKeyRotationInput) (*SDK.DisableKeyRotationResponse, error)

RawDisableKeyRotation executes `DisableKeyRotation` raw operation.

func (*KMS) RawDisconnectCustomKeyStore

func (svc *KMS) RawDisconnectCustomKeyStore(ctx context.Context, in *SDK.DisconnectCustomKeyStoreInput) (*SDK.DisconnectCustomKeyStoreResponse, error)

RawDisconnectCustomKeyStore executes `DisconnectCustomKeyStore` raw operation.

func (*KMS) RawEnableKey

func (svc *KMS) RawEnableKey(ctx context.Context, in *SDK.EnableKeyInput) (*SDK.EnableKeyResponse, error)

RawEnableKey executes `EnableKey` raw operation.

func (*KMS) RawEnableKeyRotation

func (svc *KMS) RawEnableKeyRotation(ctx context.Context, in *SDK.EnableKeyRotationInput) (*SDK.EnableKeyRotationResponse, error)

RawEnableKeyRotation executes `EnableKeyRotation` raw operation.

func (*KMS) RawEncrypt

func (svc *KMS) RawEncrypt(ctx context.Context, in *SDK.EncryptInput) (*SDK.EncryptResponse, error)

RawEncrypt executes `Encrypt` raw operation.

func (*KMS) RawGenerateDataKey

func (svc *KMS) RawGenerateDataKey(ctx context.Context, in *SDK.GenerateDataKeyInput) (*SDK.GenerateDataKeyResponse, error)

RawGenerateDataKey executes `GenerateDataKey` raw operation.

func (*KMS) RawGenerateDataKeyPair

func (svc *KMS) RawGenerateDataKeyPair(ctx context.Context, in *SDK.GenerateDataKeyPairInput) (*SDK.GenerateDataKeyPairResponse, error)

RawGenerateDataKeyPair executes `GenerateDataKeyPair` raw operation.

func (*KMS) RawGenerateDataKeyPairWithoutPlaintext

func (svc *KMS) RawGenerateDataKeyPairWithoutPlaintext(ctx context.Context, in *SDK.GenerateDataKeyPairWithoutPlaintextInput) (*SDK.GenerateDataKeyPairWithoutPlaintextResponse, error)

RawGenerateDataKeyPairWithoutPlaintext executes `GenerateDataKeyPairWithoutPlaintext` raw operation.

func (*KMS) RawGenerateDataKeyWithoutPlaintext

func (svc *KMS) RawGenerateDataKeyWithoutPlaintext(ctx context.Context, in *SDK.GenerateDataKeyWithoutPlaintextInput) (*SDK.GenerateDataKeyWithoutPlaintextResponse, error)

RawGenerateDataKeyWithoutPlaintext executes `GenerateDataKeyWithoutPlaintext` raw operation.

func (*KMS) RawGenerateRandom

func (svc *KMS) RawGenerateRandom(ctx context.Context, in *SDK.GenerateRandomInput) (*SDK.GenerateRandomResponse, error)

RawGenerateRandom executes `GenerateRandom` raw operation.

func (*KMS) RawGetKeyPolicy

func (svc *KMS) RawGetKeyPolicy(ctx context.Context, in *SDK.GetKeyPolicyInput) (*SDK.GetKeyPolicyResponse, error)

RawGetKeyPolicy executes `GetKeyPolicy` raw operation.

func (*KMS) RawGetKeyRotationStatus

func (svc *KMS) RawGetKeyRotationStatus(ctx context.Context, in *SDK.GetKeyRotationStatusInput) (*SDK.GetKeyRotationStatusResponse, error)

RawGetKeyRotationStatus executes `GetKeyRotationStatus` raw operation.

func (*KMS) RawGetParametersForImport

func (svc *KMS) RawGetParametersForImport(ctx context.Context, in *SDK.GetParametersForImportInput) (*SDK.GetParametersForImportResponse, error)

RawGetParametersForImport executes `GetParametersForImport` raw operation.

func (*KMS) RawGetPublicKey

func (svc *KMS) RawGetPublicKey(ctx context.Context, in *SDK.GetPublicKeyInput) (*SDK.GetPublicKeyResponse, error)

RawGetPublicKey executes `GetPublicKey` raw operation.

func (*KMS) RawImportKeyMaterial

func (svc *KMS) RawImportKeyMaterial(ctx context.Context, in *SDK.ImportKeyMaterialInput) (*SDK.ImportKeyMaterialResponse, error)

RawImportKeyMaterial executes `ImportKeyMaterial` raw operation.

func (*KMS) RawListAliases

func (svc *KMS) RawListAliases(ctx context.Context, in *SDK.ListAliasesInput) (*SDK.ListAliasesResponse, error)

RawListAliases executes `ListAliases` raw operation.

func (*KMS) RawListGrants

func (svc *KMS) RawListGrants(ctx context.Context, in *SDK.ListGrantsInput) (*SDK.ListGrantsResponse, error)

RawListGrants executes `ListGrants` raw operation.

func (*KMS) RawListKeyPolicies

func (svc *KMS) RawListKeyPolicies(ctx context.Context, in *SDK.ListKeyPoliciesInput) (*SDK.ListKeyPoliciesResponse, error)

RawListKeyPolicies executes `ListKeyPolicies` raw operation.

func (*KMS) RawListKeys

func (svc *KMS) RawListKeys(ctx context.Context, in *SDK.ListKeysInput) (*SDK.ListKeysResponse, error)

RawListKeys executes `ListKeys` raw operation.

func (*KMS) RawListResourceTags

func (svc *KMS) RawListResourceTags(ctx context.Context, in *SDK.ListResourceTagsInput) (*SDK.ListResourceTagsResponse, error)

RawListResourceTags executes `ListResourceTags` raw operation.

func (*KMS) RawListRetirableGrants

func (svc *KMS) RawListRetirableGrants(ctx context.Context, in *SDK.ListRetirableGrantsInput) (*SDK.ListRetirableGrantsResponse, error)

RawListRetirableGrants executes `ListRetirableGrants` raw operation.

func (*KMS) RawPutKeyPolicy

func (svc *KMS) RawPutKeyPolicy(ctx context.Context, in *SDK.PutKeyPolicyInput) (*SDK.PutKeyPolicyResponse, error)

RawPutKeyPolicy executes `PutKeyPolicy` raw operation.

func (*KMS) RawReEncrypt

func (svc *KMS) RawReEncrypt(ctx context.Context, in *SDK.ReEncryptInput) (*SDK.ReEncryptResponse, error)

RawReEncrypt executes `ReEncrypt` raw operation.

func (*KMS) RawRetireGrant

func (svc *KMS) RawRetireGrant(ctx context.Context, in *SDK.RetireGrantInput) (*SDK.RetireGrantResponse, error)

RawRetireGrant executes `RetireGrant` raw operation.

func (*KMS) RawRevokeGrant

func (svc *KMS) RawRevokeGrant(ctx context.Context, in *SDK.RevokeGrantInput) (*SDK.RevokeGrantResponse, error)

RawRevokeGrant executes `RevokeGrant` raw operation.

func (*KMS) RawScheduleKeyDeletion

func (svc *KMS) RawScheduleKeyDeletion(ctx context.Context, in *SDK.ScheduleKeyDeletionInput) (*SDK.ScheduleKeyDeletionResponse, error)

RawScheduleKeyDeletion executes `ScheduleKeyDeletion` raw operation.

func (*KMS) RawSign

func (svc *KMS) RawSign(ctx context.Context, in *SDK.SignInput) (*SDK.SignResponse, error)

RawSign executes `Sign` raw operation.

func (*KMS) RawTagResource

func (svc *KMS) RawTagResource(ctx context.Context, in *SDK.TagResourceInput) (*SDK.TagResourceResponse, error)

RawTagResource executes `TagResource` raw operation.

func (*KMS) RawUntagResource

func (svc *KMS) RawUntagResource(ctx context.Context, in *SDK.UntagResourceInput) (*SDK.UntagResourceResponse, error)

RawUntagResource executes `UntagResource` raw operation.

func (*KMS) RawUpdateAlias

func (svc *KMS) RawUpdateAlias(ctx context.Context, in *SDK.UpdateAliasInput) (*SDK.UpdateAliasResponse, error)

RawUpdateAlias executes `UpdateAlias` raw operation.

func (*KMS) RawUpdateCustomKeyStore

func (svc *KMS) RawUpdateCustomKeyStore(ctx context.Context, in *SDK.UpdateCustomKeyStoreInput) (*SDK.UpdateCustomKeyStoreResponse, error)

RawUpdateCustomKeyStore executes `UpdateCustomKeyStore` raw operation.

func (*KMS) RawUpdateKeyDescription

func (svc *KMS) RawUpdateKeyDescription(ctx context.Context, in *SDK.UpdateKeyDescriptionInput) (*SDK.UpdateKeyDescriptionResponse, error)

RawUpdateKeyDescription executes `UpdateKeyDescription` raw operation.

func (*KMS) RawVerify

func (svc *KMS) RawVerify(ctx context.Context, in *SDK.VerifyInput) (*SDK.VerifyResponse, error)

RawVerify executes `Verify` raw operation.

func (*KMS) ReEncrypt

func (svc *KMS) ReEncrypt(ctx context.Context, r ReEncryptRequest) (*ReEncryptResult, error)

ReEncrypt executes `ReEncrypt` operation.

func (*KMS) ScheduleKeyDeletion

func (svc *KMS) ScheduleKeyDeletion(ctx context.Context, r ScheduleKeyDeletionRequest) (*ScheduleKeyDeletionResult, error)

ScheduleKeyDeletion executes `ScheduleKeyDeletion` operation.

func (*KMS) SetLogger

func (svc *KMS) SetLogger(logger log.Logger)

SetLogger sets logger.

func (*KMS) XDecryptBytes added in v0.1.0

func (svc *KMS) XDecryptBytes(ctx context.Context, encryptedData []byte) (plainData []byte, err error)

XDecryptBytes decrypts the 'encryptedData'.

func (*KMS) XDecryptString added in v0.1.0

func (svc *KMS) XDecryptString(ctx context.Context, base64Text string) (plainText string, err error)

XDecryptString decrypts the 'base64Text'.

func (*KMS) XDeleteKey added in v0.1.0

func (svc *KMS) XDeleteKey(ctx context.Context, key string, day ...int64) error

XDeleteKey deletes the key using 'ScheduleKeyDeletion'.

func (*KMS) XEncryptBytes added in v0.1.0

func (svc *KMS) XEncryptBytes(ctx context.Context, key string, plainData []byte) (encryptedData []byte, err error)

XEncryptBytes encrypts the 'plainData' using the 'key' and returns 'encryptedData'.

func (*KMS) XEncryptString added in v0.1.0

func (svc *KMS) XEncryptString(ctx context.Context, key string, plainText string) (base64Text string, err error)

XEncryptString encrypts the 'plainText' using the 'key' and returns encrypted 'base64Text'.

func (*KMS) XReEncryptBytes added in v0.1.0

func (svc *KMS) XReEncryptBytes(ctx context.Context, destinationKey string, encryptedData []byte) (resultEncryptedData []byte, err error)

XReEncryptBytes re-encrypts the 'encryptedData' using 'destinationKey'.

func (*KMS) XReEncryptString added in v0.1.0

func (svc *KMS) XReEncryptString(ctx context.Context, destinationKey, base64Text string) (resultBase64Text string, err error)

XReEncryptString re-encrypts the 'base64Text' using 'destinationKey'.

type KeyManagerType

type KeyManagerType string

type KeyMetadata

type KeyMetadata struct {
	KeyID string

	// optional
	AWSAccountID          string
	ARN                   string
	CloudHsmClusterID     string
	CreationDate          time.Time
	CustomKeyStoreID      string
	CustomerMasterKeySpec CustomerMasterKeySpec
	DeletionDate          time.Time
	Description           string
	Enabled               bool
	EncryptionAlgorithms  []EncryptionAlgorithmSpec
	ExpirationModel       ExpirationModelType
	KeyManager            KeyManagerType
	KeyState              KeyState
	KeyUsage              KeyUsageType
	Origin                OriginType
	SigningAlgorithms     []SigningAlgorithmSpec
	ValidTo               time.Time
}

type KeyState

type KeyState string
const (
	KeyStateEnabled         KeyState = KeyState(SDK.KeyStateEnabled)
	KeyStateDisabled        KeyState = KeyState(SDK.KeyStateDisabled)
	KeyStatePendingDeletion KeyState = KeyState(SDK.KeyStatePendingDeletion)
	KeyStatePendingImport   KeyState = KeyState(SDK.KeyStatePendingImport)
	KeyStateUnavailable     KeyState = KeyState(SDK.KeyStateUnavailable)
)

type KeyUsageType

type KeyUsageType string
const (
	KeyUsageTypeSignVerify     KeyUsageType = KeyUsageType(SDK.KeyUsageTypeSignVerify)
	KeyUsageTypeEncryptDecrypt KeyUsageType = KeyUsageType(SDK.KeyUsageTypeEncryptDecrypt)
)

type OriginType

type OriginType string
const (
	OriginTypeAwsKms      OriginType = OriginType(SDK.OriginTypeAwsKms)
	OriginTypeExternal    OriginType = OriginType(SDK.OriginTypeExternal)
	OriginTypeAwsCloudhsm OriginType = OriginType(SDK.OriginTypeAwsCloudhsm)
)

type ReEncryptRequest

type ReEncryptRequest struct {
	CiphertextBlob   []byte
	DestinationKeyID string

	// optional
	DestinationEncryptionAlgorithm EncryptionAlgorithmSpec
	DestinationEncryptionContext   map[string]string
	GrantTokens                    []string
	SourceEncryptionAlgorithm      EncryptionAlgorithmSpec
	SourceEncryptionContext        map[string]string
	SourceKeyID                    string
}

ReEncryptRequest has parameters for `ReEncrypt` operation.

func (ReEncryptRequest) ToInput

func (r ReEncryptRequest) ToInput() *SDK.ReEncryptInput

type ReEncryptResult

type ReEncryptResult struct {
	CiphertextBlob                 []byte
	DestinationEncryptionAlgorithm EncryptionAlgorithmSpec
	KeyID                          string
	SourceEncryptionAlgorithm      EncryptionAlgorithmSpec
	SourceKeyID                    string
}

func NewReEncryptResult

func NewReEncryptResult(output *SDK.ReEncryptResponse) *ReEncryptResult

type ScheduleKeyDeletionRequest

type ScheduleKeyDeletionRequest struct {
	KeyID string

	// optional
	PendingWindowInDays int64 // must be [7 ~ 30] days
}

ScheduleKeyDeletionRequest has parameters for `ScheduleKeyDeletion` operation.

func (ScheduleKeyDeletionRequest) ToInput

type ScheduleKeyDeletionResult

type ScheduleKeyDeletionResult struct {
	DeletionDate time.Time
	KeyID        string
}

type Tag

type Tag struct {
	Key   string
	Value string
}

func (Tag) ToSDK

func (r Tag) ToSDK() SDK.Tag

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL