kms

package module
v1.1.0 Latest Latest
Warning

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

Go to latest
Published: Oct 10, 2026 License: MIT Imports: 17 Imported by: 0

Documentation

Overview

Package kms supplies an AWS Encryption SDK provider for Data Masking.

New constructs a Provider from key identifiers in Config. The first key is the generator; additional keys wrap the same data key. Provider.Encrypt and Provider.Decrypt exchange Base64-encoded authenticated Encryption SDK messages, rather than raw KMS Encrypt ciphertext.

Key and context policy

The provider requires key commitment. Encryption context is authenticated; decryption checks the caller's expected context. ClientProvider lets applications supply regional AWS SDK clients while retaining invocation cancellation. Actual cryptographic operations require KMS access and permissions.

Each encryption obtains fresh materials. TypeScript data-key caching and its age, capacity, message and byte limits are not implemented. This optional module keeps Encryption SDK dependencies out of the core erasure package.

For usage and compatibility details, see the user guide.

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type ClientProvider

type ClientProvider func(context.Context, string) (*awskms.Client, error)

ClientProvider supplies a regional AWS SDK client template. The provider clones its options to bind each operation's context without mutating it. Implementations must support concurrent calls.

type Config

type Config struct {
	// Keys contains the generator identifier first, followed by additional keys.
	Keys []string
	// A nil ClientProvider uses the default AWS configuration and regional clients.
	ClientProvider ClientProvider
}

type Provider

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

Provider uses authenticated AWS Encryption SDK messages and strict key commitment. It is safe for concurrent calls. Each encryption obtains fresh materials; cache age/capacity/message/byte limits are not implemented yet.

func New

func New(ctx context.Context, options Config) (*Provider, error)
Example

This example requires configured AWS credentials and a usable KMS key. It is compiled as documentation but is not executed by go test.

package main

import (
	"context"

	"github.com/rambow-cloud/powertools-lambda-go/datamasking"
	"github.com/rambow-cloud/powertools-lambda-go/datamasking/kms"
)

func main() {
	ctx := context.Background()
	provider, err := kms.New(ctx, kms.Config{Keys: []string{"alias/example"}})
	if err != nil {
		panic(err)
	}
	masker := datamasking.New(datamasking.Config{Provider: provider})
	value, err := masker.Encrypt(ctx, map[string]any{"email": "user@example.com"},
		datamasking.TransformOptions{Fields: []string{"email"},
			Context: map[string]string{"purpose": "example"}})
	if err != nil {
		panic(err)
	}
	_ = value // Persist ciphertext; supply the same expected context on decryption.
}

func (*Provider) Decrypt

func (p *Provider) Decrypt(ctx context.Context, data string, encryptionContext map[string]string) (string, error)

func (*Provider) Encrypt

func (p *Provider) Encrypt(ctx context.Context, data string, encryptionContext map[string]string) (string, error)

Jump to

Keyboard shortcuts

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