codec

package
v0.0.0-...-cdd27d5 Latest Latest
Warning

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

Go to latest
Published: Mar 7, 2019 License: GPL-3.0 Imports: 12 Imported by: 0

Documentation

Overview

codec library is responsible for transforming data + additionalData to different kind of data. This means in practise either encrypting/decrypting, or compressing/uncompressing on case-by-case basis.

CodecChain makes it possible to combine multiple Codecs that do the particular sub-EncodeBytes/DecodeBytes steps.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Codec

type Codec interface {
	DecodeBytes(data, additionalData []byte) (ret []byte, err error)
	EncodeBytes(data, additionalData []byte) (ret []byte, err error)
}

Codec

Single transformation of byte slices.

type CodecChain

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

func (*CodecChain) DecodeBytes

func (self *CodecChain) DecodeBytes(data, additionalData []byte) (ret []byte, err error)

func (*CodecChain) EncodeBytes

func (self *CodecChain) EncodeBytes(data, additionalData []byte) (ret []byte, err error)

func (CodecChain) Init

func (self CodecChain) Init(codecs ...Codec) *CodecChain

Init method initializes the codec chain.

codecs are given in decryption order, so e.g. encrypting one should be given before compressing one.

type CompressedData

type CompressedData struct {
	// CompressionType describes how the data has been compressed.
	CompressionType CompressionType `zid:"0"`

	// RawData is the raw data of the client (whatever it is)
	RawData []byte `zid:"1"`
}

func (*CompressedData) DecodeMsg

func (z *CompressedData) DecodeMsg(dc *msgp.Reader) (err error)

DecodeMsg implements msgp.Decodable We treat empty fields as if we read a Nil from the wire.

func (*CompressedData) EncodeMsg

func (z *CompressedData) EncodeMsg(en *msgp.Writer) (err error)

EncodeMsg implements msgp.Encodable

func (*CompressedData) MarshalMsg

func (z *CompressedData) MarshalMsg(b []byte) (o []byte, err error)

MarshalMsg implements msgp.Marshaler

func (*CompressedData) Msgsize

func (z *CompressedData) Msgsize() (s int)

Msgsize returns an upper bound estimate of the number of bytes occupied by the serialized message

func (*CompressedData) UnmarshalMsg

func (z *CompressedData) UnmarshalMsg(bts []byte) (o []byte, err error)

UnmarshalMsg implements msgp.Unmarshaler

func (*CompressedData) UnmarshalMsgWithCfg

func (z *CompressedData) UnmarshalMsgWithCfg(bts []byte, cfg *msgp.RuntimeConfig) (o []byte, err error)

type CompressingCodec

type CompressingCodec struct {
	CompressionType CompressionType
}

CompressingCodec

On-the-fly compressing Codec. If the result does not improve, the result is marked to be plaintext and passed as-is (at cost of 1 byte).

func (*CompressingCodec) DecodeBytes

func (self *CompressingCodec) DecodeBytes(data, additionalData []byte) (ret []byte, err error)

func (*CompressingCodec) EncodeBytes

func (self *CompressingCodec) EncodeBytes(data, additionalData []byte) (ret []byte, err error)

type CompressionType

type CompressionType byte
const (
	CompressionType_UNSET CompressionType = iota

	// The data has not been compressed.
	CompressionType_PLAIN

	// The data is compressed with Snappy.
	CompressionType_SNAPPY

	// Golang built-in zlib
	CompressionType_ZLIB
)

func (*CompressionType) DecodeMsg

func (z *CompressionType) DecodeMsg(dc *msgp.Reader) (err error)

DecodeMsg implements msgp.Decodable We treat empty fields as if we read a Nil from the wire.

func (CompressionType) EncodeMsg

func (z CompressionType) EncodeMsg(en *msgp.Writer) (err error)

EncodeMsg implements msgp.Encodable

func (CompressionType) MarshalMsg

func (z CompressionType) MarshalMsg(b []byte) (o []byte, err error)

MarshalMsg implements msgp.Marshaler

func (CompressionType) Msgsize

func (z CompressionType) Msgsize() (s int)

Msgsize returns an upper bound estimate of the number of bytes occupied by the serialized message

func (*CompressionType) UnmarshalMsg

func (z *CompressionType) UnmarshalMsg(bts []byte) (o []byte, err error)

UnmarshalMsg implements msgp.Unmarshaler

func (*CompressionType) UnmarshalMsgWithCfg

func (z *CompressionType) UnmarshalMsgWithCfg(bts []byte, cfg *msgp.RuntimeConfig) (o []byte, err error)

type EncryptedData

type EncryptedData struct {
	Nonce         []byte `zid:"0"`
	EncryptedData []byte `zid:"1"`
}

func (*EncryptedData) DecodeMsg

func (z *EncryptedData) DecodeMsg(dc *msgp.Reader) (err error)

DecodeMsg implements msgp.Decodable We treat empty fields as if we read a Nil from the wire.

func (*EncryptedData) EncodeMsg

func (z *EncryptedData) EncodeMsg(en *msgp.Writer) (err error)

EncodeMsg implements msgp.Encodable

func (*EncryptedData) MarshalMsg

func (z *EncryptedData) MarshalMsg(b []byte) (o []byte, err error)

MarshalMsg implements msgp.Marshaler

func (*EncryptedData) Msgsize

func (z *EncryptedData) Msgsize() (s int)

Msgsize returns an upper bound estimate of the number of bytes occupied by the serialized message

func (*EncryptedData) UnmarshalMsg

func (z *EncryptedData) UnmarshalMsg(bts []byte) (o []byte, err error)

UnmarshalMsg implements msgp.Unmarshaler

func (*EncryptedData) UnmarshalMsgWithCfg

func (z *EncryptedData) UnmarshalMsgWithCfg(bts []byte, cfg *msgp.RuntimeConfig) (o []byte, err error)

type EncryptingCodec

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

EncryptingCodec

AES GCM based encrypting/decrypting (+authenticating) Codec.

TBD: Should # of iterations be parametrizable?

func (*EncryptingCodec) DecodeBytes

func (self *EncryptingCodec) DecodeBytes(data, additionalData []byte) (ret []byte, err error)

func (*EncryptingCodec) EncodeBytes

func (self *EncryptingCodec) EncodeBytes(data, additionalData []byte) (ret []byte, err error)

func (EncryptingCodec) Init

func (self EncryptingCodec) Init(password, salt []byte, iter int) *EncryptingCodec

Jump to

Keyboard shortcuts

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