format

package
v0.2.15 Latest Latest
Warning

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

Go to latest
Published: Apr 10, 2024 License: GPL-3.0 Imports: 16 Imported by: 31

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrAesCreate             = errors.New("AES cipher creation error")
	ErrGcmCreate             = errors.New("GCM cipher mode creation error")
	ErrAesGcmEncrypt         = errors.New("AES GCM encrypt error")
	ErrAesGcmDecrypt         = errors.New("AES GCM decrypt error")
	ErrAesGcmDecryptTooShort = errors.New("AES GCM bytes to decrypt too short")
)
View Source
var (
	ErrFormatConversionMarshal   = errors.New("format conversion marshal error")
	ErrFormatConversionUnmarshal = errors.New("format conversion unmarshal error")
)
View Source
var (
	ErrGhastly = errors.New("ghastly")
	ErrHaunter = errors.New("haunter")
	ErrGengar  = errors.New("gengar")
	ErrBasic   = errors.New("error")
)
View Source
var (
	ErrMaskActualMarshal   = errors.New("masking error while converting type to bytes")
	ErrMaskMarshal         = errors.New("masking error while masking bytes")
	ErrMaskActualUnmarshal = errors.New("masking error while converting bytes to type")
	ErrMaskUnmarshal       = errors.New("masking error while unmasking bytes")
)
View Source
var (
	ErrWellspringMask  = errors.New("wellspring")
	ErrHearthflameMask = errors.New("hearthflame")
)

Functions

func Convert

func Convert[V1 any, V2 any](
	v V1,
	v1 Format[V1],
	v2 Format[V2],
) (V2, error)

assuming byte compatibility, i.e. bytes <-> proto, string <-> json

func RegisterFormat added in v0.0.29

func RegisterFormat[T any](c inverse.Container, f Format[T])

func RegisterMask added in v0.0.29

func RegisterMask(c inverse.Container, name string, m Mask)

Types

type AesGcmFormat added in v0.0.29

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

func (AesGcmFormat) Mask added in v0.0.29

func (helper AesGcmFormat) Mask(value []byte) ([]byte, error)

Encrypt

func (AesGcmFormat) Unmask added in v0.0.29

func (helper AesGcmFormat) Unmask(value []byte) ([]byte, error)

Decrypt

type Base64Format

type Base64Format struct {
}

format for interpereting bytes as base64

func (Base64Format) Default

func (helper Base64Format) Default() string

func (Base64Format) Marshal

func (helper Base64Format) Marshal(value string) ([]byte, error)

func (Base64Format) Mask added in v0.0.29

func (helper Base64Format) Mask(value []byte) ([]byte, error)

func (Base64Format) Unmarshal

func (helper Base64Format) Unmarshal(value []byte) (string, error)

func (Base64Format) Unmask added in v0.0.29

func (helper Base64Format) Unmask(value []byte) ([]byte, error)

type BytesFormat

type BytesFormat struct {
}

func (BytesFormat) Default

func (helper BytesFormat) Default() []byte

func (BytesFormat) Marshal

func (helper BytesFormat) Marshal(value []byte) ([]byte, error)

func (BytesFormat) Mask added in v0.0.29

func (helper BytesFormat) Mask(value []byte) ([]byte, error)

func (BytesFormat) Unmarshal

func (helper BytesFormat) Unmarshal(value []byte) ([]byte, error)

func (BytesFormat) Unmask added in v0.0.29

func (helper BytesFormat) Unmask(value []byte) ([]byte, error)

type Format

type Format[T any] interface {
	Default() T
	Marshal(T) ([]byte, error)
	Unmarshal([]byte) (T, error)
}

bytes format

func Base64

func Base64() Format[string]

func Bytes

func Bytes() Format[[]byte]

func Gengar added in v0.0.12

func Gengar() Format[string]

func Json

func Json[T any]() Format[T]

func Masked added in v0.0.29

func Masked[T any](mask Mask, actual Format[T]) Format[T]

func Protobuf

func Protobuf[T proto.Message]() Format[T]

func Protojson added in v0.0.12

func Protojson[T proto.Message]() Format[T]

func RetrieveFormat added in v0.2.4

func RetrieveFormat[T any](c inverse.Container, ctx context.Context) (Format[T], error)

func String

func String() Format[string]

func Yaml

func Yaml[T any]() Format[T]

type GengarFormat added in v0.0.12

type GengarFormat struct {
}

the pokemon gengar likes to play pranks. for unit testing broken format results

func (GengarFormat) Default added in v0.0.12

func (helper GengarFormat) Default() string

func (GengarFormat) Marshal added in v0.0.12

func (helper GengarFormat) Marshal(value string) ([]byte, error)

func (GengarFormat) Unmarshal added in v0.0.12

func (helper GengarFormat) Unmarshal(value []byte) (string, error)

type JsonFormat

type JsonFormat[T any] struct{}

func (JsonFormat[T]) Default

func (helper JsonFormat[T]) Default() T

func (JsonFormat[T]) Marshal

func (helper JsonFormat[T]) Marshal(value T) ([]byte, error)

func (JsonFormat[T]) Unmarshal

func (helper JsonFormat[T]) Unmarshal(value []byte) (T, error)

type Mask added in v0.0.29

type Mask interface {
	Mask([]byte) ([]byte, error)
	Unmask([]byte) ([]byte, error)
}

func AesGcm added in v0.0.29

func AesGcm(key string) (Mask, error)

func AesGcmByteKey added in v0.0.29

func AesGcmByteKey(key []byte) (Mask, error)

func Base64Mask added in v0.0.29

func Base64Mask() Mask

func Ogerpon added in v0.0.29

func Ogerpon() Mask

func Plain added in v0.0.29

func Plain() Mask

func RetrieveMask added in v0.2.4

func RetrieveMask(c inverse.Container, name string, ctx context.Context) (Mask, error)

type MaskedFormat added in v0.0.29

type MaskedFormat[T any] struct {
	// contains filtered or unexported fields
}

func (MaskedFormat[T]) Default added in v0.0.29

func (helper MaskedFormat[T]) Default() T

func (MaskedFormat[T]) Marshal added in v0.0.29

func (helper MaskedFormat[T]) Marshal(value T) ([]byte, error)

func (MaskedFormat[T]) Unmarshal added in v0.0.29

func (helper MaskedFormat[T]) Unmarshal(value []byte) (T, error)

type OgerponFormat added in v0.0.29

type OgerponFormat struct {
}

ogerpon the teal mask pokemon. for unit testing broken format masking

func (OgerponFormat) Mask added in v0.0.29

func (helper OgerponFormat) Mask(value []byte) ([]byte, error)

func (OgerponFormat) Unmask added in v0.0.29

func (helper OgerponFormat) Unmask(value []byte) ([]byte, error)

type ProtobufFormat

type ProtobufFormat[T proto.Message] struct{}

func (ProtobufFormat[T]) Default

func (helper ProtobufFormat[T]) Default() T

func (ProtobufFormat[T]) Marshal

func (helper ProtobufFormat[T]) Marshal(value T) ([]byte, error)

func (ProtobufFormat[T]) Unmarshal

func (helper ProtobufFormat[T]) Unmarshal(value []byte) (T, error)

type ProtojsonFormat added in v0.0.12

type ProtojsonFormat[T proto.Message] struct{}

func (ProtojsonFormat[T]) Default added in v0.0.12

func (helper ProtojsonFormat[T]) Default() T

func (ProtojsonFormat[T]) Marshal added in v0.0.12

func (helper ProtojsonFormat[T]) Marshal(value T) ([]byte, error)

func (ProtojsonFormat[T]) Unmarshal added in v0.0.12

func (helper ProtojsonFormat[T]) Unmarshal(value []byte) (T, error)

type StringFormat

type StringFormat struct {
}

func (StringFormat) Default

func (helper StringFormat) Default() string

func (StringFormat) Marshal

func (helper StringFormat) Marshal(value string) ([]byte, error)

func (StringFormat) Unmarshal

func (helper StringFormat) Unmarshal(value []byte) (string, error)

type YamlFormat

type YamlFormat[T any] struct{}

func (YamlFormat[T]) Default

func (helper YamlFormat[T]) Default() T

func (YamlFormat[T]) Marshal

func (helper YamlFormat[T]) Marshal(value T) ([]byte, error)

func (YamlFormat[T]) Unmarshal

func (helper YamlFormat[T]) Unmarshal(value []byte) (T, error)

Jump to

Keyboard shortcuts

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