aesgcm

package
v0.0.0-...-6116a66 Latest Latest
Warning

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

Go to latest
Published: Dec 5, 2023 License: MIT Imports: 15 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Serializer

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

Serializer provides a Gorm Serializer capable of encrypting and decrypting database fields using an AES+GCM cipher. The same encryption key can be used for multiple values in an attempt to optimize performance.

func New

func New(
	db *gorm.DB,
	hmac []byte,
	cacheSize int,
	cacheDuration time.Duration,
	rotationDuration time.Duration,
	marshaler func(any) ([]byte, error),
	unmarshaler func([]byte, any) error,
) (*Serializer, error)

func (*Serializer) Get

func (s *Serializer) Get(fingerprint string) (*database.Key, error)

Get implements loading logic that pulls encryption keys from the database and caches them in memory to improve performance of decrypting field values.

func (*Serializer) Scan

func (s *Serializer) Scan(ctx context.Context, field *schema.Field, dst reflect.Value, dbValue interface{}) error

Scan converts on-disk, ciphertext into a plaintext in-memory field value.

func (*Serializer) Value

func (s *Serializer) Value(ctx context.Context, field *schema.Field, dst reflect.Value, fieldValue interface{}) (interface{}, error)

Value converts a plaintext, in-memory field value into an encrypted field value intended for storage in SQL systems.

Jump to

Keyboard shortcuts

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