encryption

package
v6.1.0-rc Latest Latest
Warning

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

Go to latest
Published: Oct 18, 2026 License: Apache-2.0 Imports: 17 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func EncryptUpdateExpressionValues

func EncryptUpdateExpressionValues(
	ctx context.Context,
	svc *Service,
	binding RecordBinding,
	metadata *model.Metadata,
	updateExpression string,
	exprAttrNames map[string]string,
	exprAttrValues map[string]types.AttributeValue,
) error

EncryptUpdateExpressionValues mutates exprAttrValues in-place by encrypting values assigned to encrypted fields. It currently supports direct SET assignments and if_not_exists() defaults for encrypted fields.

func FailClosedIfEncryptedWithoutKMSKeyARN

func FailClosedIfEncryptedWithoutKMSKeyARN(sess *session.Session, metadata *model.Metadata) error

func MetadataHasEncryptedFields

func MetadataHasEncryptedFields(metadata *model.Metadata) bool

Types

type RecordBinding added in v6.1.0

type RecordBinding struct {
	PartitionKey types.AttributeValue
	SortKey      types.AttributeValue
	Table        string
}

RecordBinding identifies the stored row an encrypted envelope belongs to. Envelope v2 authenticates this binding in the AES-GCM additional data, so a valid envelope copied onto another record or another table fails to decrypt.

func BindingFromItem added in v6.1.0

func BindingFromItem(table string, metadata *model.Metadata, item map[string]types.AttributeValue) (RecordBinding, bool)

BindingFromItem derives a record binding from a full or projected item. It reports false when the item does not carry the key attributes, which is the case for a projection that omits them.

func NewRecordBinding added in v6.1.0

func NewRecordBinding(table string, partitionKey, sortKey types.AttributeValue) (RecordBinding, error)

NewRecordBinding validates and returns a record binding.

func NewRecordBindingFromKey added in v6.1.0

func NewRecordBindingFromKey(table string, metadata *model.Metadata, key map[string]types.AttributeValue) (RecordBinding, error)

NewRecordBindingFromKey builds a binding from a model key map. metadata and the key map must describe the same row; a missing partition key is an error so a write cannot silently produce an unbound envelope.

func (RecordBinding) Valid added in v6.1.0

func (b RecordBinding) Valid() bool

Valid reports whether the binding carries the minimum identity needed to construct the v2 additional authenticated data.

type Service

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

Service implements envelope encryption for DynamoDB attribute values using AWS KMS.

func NewService

func NewService(keyARN string, kmsClient kmsAPI) *Service

func NewServiceFromAWSConfig

func NewServiceFromAWSConfig(keyARN string, cfg aws.Config) *Service

func NewServiceFromAWSConfigWithRand

func NewServiceFromAWSConfigWithRand(keyARN string, cfg aws.Config, rng io.Reader) *Service

func NewServiceWithRand

func NewServiceWithRand(keyARN string, kmsClient kmsAPI, rng io.Reader) *Service

func (*Service) DecryptAttributeValue

func (s *Service) DecryptAttributeValue(ctx context.Context, attributeName string, envelope types.AttributeValue) (types.AttributeValue, error)

DecryptAttributeValue decrypts a legacy v1 envelope. A v2 envelope requires the record binding and is rejected here rather than decrypted without it.

func (*Service) DecryptAttributeValueWithBinding added in v6.1.0

func (s *Service) DecryptAttributeValueWithBinding(ctx context.Context, binding RecordBinding, attributeName string, envelope types.AttributeValue) (types.AttributeValue, error)

DecryptAttributeValueWithBinding decrypts v2 envelopes with their record binding and still accepts legacy v1 envelopes for read compatibility.

func (*Service) EncryptAttributeValue

func (s *Service) EncryptAttributeValue(ctx context.Context, attributeName string, av types.AttributeValue) (types.AttributeValue, error)

EncryptAttributeValue writes a legacy v1 envelope that authenticates only the attribute name. New writes to stored records should use EncryptAttributeValueWithBinding so an envelope cannot be replayed onto another record or table.

func (*Service) EncryptAttributeValueWithBinding added in v6.1.0

func (s *Service) EncryptAttributeValueWithBinding(ctx context.Context, binding RecordBinding, attributeName string, av types.AttributeValue) (types.AttributeValue, error)

EncryptAttributeValueWithBinding writes a v2 envelope bound to the record identity (table, partition key, sort key) in addition to the attribute name. The same binding is also supplied to KMS as the data key's EncryptionContext.

Jump to

Keyboard shortcuts

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