marshal

package
v1.0.21 Latest Latest
Warning

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

Go to latest
Published: Jun 30, 2025 License: Apache-2.0 Imports: 11 Imported by: 0

Documentation

Overview

Package marshal provides optimized marshaling for DynamoDB

Package marshal provides safe marshaling for DynamoDB without unsafe operations

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func SetGlobalConfig added in v1.0.18

func SetGlobalConfig(config Config)

SetGlobalConfig sets the global marshaler configuration

func ValidateConfig added in v1.0.18

func ValidateConfig(config Config) error

ValidateConfig validates marshaler configuration for security compliance

Types

type Config added in v1.0.18

type Config struct {
	// MarshalerType specifies which marshaler to use (default: safe)
	MarshalerType MarshalerType `json:"marshaler_type" yaml:"marshaler_type"`

	// AllowUnsafeMarshaler must be explicitly set to true to enable unsafe operations
	// This flag is not serialized to prevent accidental persistence
	AllowUnsafeMarshaler bool `json:"-" yaml:"-"`

	// RequireExplicitUnsafeAck requires explicit acknowledgment of security risks
	RequireExplicitUnsafeAck bool `json:"require_explicit_unsafe_ack" yaml:"require_explicit_unsafe_ack"`

	// WarnOnUnsafeUsage logs warnings when unsafe marshaler is used
	WarnOnUnsafeUsage bool `json:"warn_on_unsafe_usage" yaml:"warn_on_unsafe_usage"`
}

Config holds marshaler configuration with security defaults

func DefaultConfig added in v1.0.18

func DefaultConfig() Config

DefaultConfig returns a secure default configuration

func GetGlobalConfig added in v1.0.18

func GetGlobalConfig() Config

GetGlobalConfig returns the current global configuration

type Marshaler

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

Marshaler provides high-performance marshaling to DynamoDB AttributeValues

func New

func New() *Marshaler

New creates a new optimized marshaler

func (*Marshaler) MarshalItem

func (m *Marshaler) MarshalItem(model any, metadata *model.Metadata) (map[string]types.AttributeValue, error)

MarshalItem marshals a model to DynamoDB AttributeValues using cached reflection

type MarshalerFactory added in v1.0.18

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

MarshalerFactory creates marshalers with security controls

func NewMarshalerFactory added in v1.0.18

func NewMarshalerFactory(config Config) *MarshalerFactory

NewMarshalerFactory creates a new factory with the given configuration

func (*MarshalerFactory) NewMarshaler added in v1.0.18

func (f *MarshalerFactory) NewMarshaler() (MarshalerInterface, error)

NewMarshaler creates a marshaler based on configuration

func (*MarshalerFactory) NewMarshalerWithAcknowledgment added in v1.0.18

func (f *MarshalerFactory) NewMarshalerWithAcknowledgment(ack *SecurityAcknowledgment) (MarshalerInterface, error)

NewMarshalerWithAcknowledgment creates a marshaler with explicit security acknowledgment

type MarshalerInterface added in v1.0.18

type MarshalerInterface interface {
	MarshalItem(model any, metadata *model.Metadata) (map[string]types.AttributeValue, error)
}

MarshalerInterface defines the common interface for all marshalers

type MarshalerType added in v1.0.18

type MarshalerType string

MarshalerType defines the type of marshaler to use

const (
	// SafeMarshalerType uses reflection-based marshaling (RECOMMENDED)
	SafeMarshalerType MarshalerType = "safe"

	// UnsafeMarshalerType uses unsafe pointer operations (DEPRECATED)
	// Will be removed in v2.0
	UnsafeMarshalerType MarshalerType = "unsafe"
)

type SafeMarshaler added in v1.0.18

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

SafeMarshaler provides memory-safe marshaling implementation without unsafe operations This is the default marshaler and should be used in production environments

func NewSafeMarshaler added in v1.0.18

func NewSafeMarshaler() *SafeMarshaler

NewSafeMarshaler creates a new safe marshaler (recommended for production)

func (*SafeMarshaler) MarshalItem added in v1.0.18

func (m *SafeMarshaler) MarshalItem(model any, metadata *model.Metadata) (map[string]types.AttributeValue, error)

MarshalItem safely marshals a model to DynamoDB AttributeValues using only reflection This implementation prioritizes security over performance but is still highly optimized

type SecurityAcknowledgment added in v1.0.18

type SecurityAcknowledgment struct {
	AcknowledgeMemoryCorruptionRisk bool
	AcknowledgeSecurityVulnerable   bool
	AcknowledgeDeprecationWarning   bool
	DeveloperSignature              string
	Timestamp                       int64
}

SecurityAcknowledgment represents explicit acknowledgment of unsafe marshaler risks

func CreateSecurityAcknowledgment added in v1.0.18

func CreateSecurityAcknowledgment(developerSignature string) *SecurityAcknowledgment

CreateSecurityAcknowledgment creates a security acknowledgment for unsafe marshaler usage

type SecurityStats added in v1.0.18

type SecurityStats struct {
	UnsafeUsageCount int64
	SecurityWarnings int64
	CurrentConfig    Config
}

SecurityStats contains security monitoring information

func GetSecurityStats added in v1.0.18

func GetSecurityStats() SecurityStats

GetSecurityStats returns security-related statistics

Jump to

Keyboard shortcuts

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