serializing

package
v0.0.0-...-93fbde9 Latest Latest
Warning

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

Go to latest
Published: May 15, 2022 License: MIT Imports: 3 Imported by: 0

Documentation

Overview

Package serializing defines the various serializing Algorithms supported by the gormcrypto package

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func RegisterAlgo

func RegisterAlgo(name string, creator func(map[string]interface{}) Algorithm)

RegisterAlgo adds an Algorithm to the internal algos map so it can be used in YAML configs

func SupportedAlgos

func SupportedAlgos() []string

SupportedAlgos returns a list of registered Algorithms that can be used in YAML configs

Types

type Algorithm

type Algorithm interface {
	// Name identifies the Algorithm as a string for exporting configurations
	Name() string
	// Config converts an Algorthim's internal configuration into a map for export
	Config() map[string]interface{}
	// Serialize transforms an arbitrary Go typed value into a byte slice that can be easily encrypted/signed.
	Serialize(interface{}) ([]byte, error)
	// Unserialize transforms a byte slice representation of a value into the Go type it represents.
	Unserialize([]byte, interface{}) error
}

Algorithm is a bad name for the core interface all gormcrypto serializers implement. The name was chosen for consistency more than anything. A type implementing serializing.Algorithm will convert a value between its Go type and a serialized text form, in a manner consistent with its type. The types implemented here wrap the Go standard library's various encoding packages.

func FromYaml

func FromYaml(name string, config map[string]interface{}) Algorithm

FromYaml configures an Algorithm automatically based on a name and a configuration map

type GOB

type GOB struct {
	Algorithm
}

GOB supports GOB serialization of arbitrary data structures

func (GOB) Config

func (GOB) Config() map[string]interface{}

Config converts an Algorthim's internal configuration into a map for export

func (GOB) Name

func (GOB) Name() string

Name identifies the Algorithm as a string for exporting configurations

func (GOB) Serialize

func (g GOB) Serialize(value interface{}) ([]byte, error)

Serialize ::: GOB

func (GOB) Unserialize

func (g GOB) Unserialize(source []byte, dest interface{}) error

Unserialize ::: GOB

type JSON

type JSON struct {
	Algorithm
}

JSON supports JSON serialization of arbitrary data structures

func (JSON) Config

func (JSON) Config() map[string]interface{}

Config converts an Algorthim's internal configuration into a map for export

func (JSON) Name

func (JSON) Name() string

Name identifies the Algorithm as a string for exporting configurations

func (JSON) Serialize

func (j JSON) Serialize(value interface{}) ([]byte, error)

Serialize ::: JSON

func (JSON) Unserialize

func (j JSON) Unserialize(source []byte, dest interface{}) error

Unserialize ::: JSON

Jump to

Keyboard shortcuts

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