compress

package
v0.0.0-...-7662171 Latest Latest
Warning

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

Go to latest
Published: Aug 1, 2021 License: MIT Imports: 10 Imported by: 0

Documentation

Index

Constants

View Source
const (
	NoCompression = ""
	Zip           = "gzip"
	Zip1          = "gzip1"
	Zip9          = "gzip9"

	// Aes - AES 256 alg
	Aes = "aes"
)

Algs

Variables

View Source
var Errors map[int]string = map[int]string{
	10200000: "Generator.Compress: algorithm %v is not exists and encrypt key is not null",
	10200001: "Generator.Restore: algorithm %v is not exists",

	10201000: "GZipRestore: gzip reader not created with error",
	10201001: "GZipRestore: read gzip error",
	10201002: "GZipRestore: readresult is large",
	10201003: "GZipRestore: close gzip error",

	10201100: "GZipCompress: gzip writer fail on create",
	10201101: "GZipCompress: gzip writer fail on write",
	10201102: "GZipCompress: gzip writer fail on close",

	10202000: "AesEncrypt: input key len %v != 32",
	10202001: "AesEncrypt: NewCipher fail",
	10202002: "AesEncrypt: NewGCM fail",
	10202003: "AesEncrypt: nonce fill fail",

	10202100: "AesDecrypt: input key len %v != 32",
	10202101: "AesDecrypt: NewCipher fail",
	10202102: "AesDecrypt: NewGCM fail",
	10202103: "AesDecrypt: decrypt fail",
}

Errors codes and description

View Source
var LimitZipRestore int64 = 1e8

Functions

func AesDecrypt

func AesDecrypt(ctx context.Context, algorithm string, body []byte, decryptKey []byte,
) (algorithmUsed string, result []byte, err *mft.Error)

func AesEncrypt

func AesEncrypt(ctx context.Context, algorithm string, body []byte, encryptKey []byte,
) (algorithmUsed string, result []byte, err *mft.Error)

func AesKeyGenerate

func AesKeyGenerate() []byte

AesKeyGenerate generates a random 32 byte (256 bit) key for AES-256

func GZipCompress

func GZipCompress(ctx context.Context, level int, algorithm string, body []byte, encryptKey []byte) (algorithmUsed string, result []byte, err *mft.Error)

func GZipRestore

func GZipRestore(ctx context.Context, algorithm string, body []byte, decryptKey []byte) (algorithmUsed string, result []byte, err *mft.Error)

func GenerateError

func GenerateError(key int, a ...interface{}) *mft.Error

GenerateError -

func GenerateErrorE

func GenerateErrorE(key int, err error, a ...interface{}) *mft.Error

GenerateErrorE -

Types

type CompressFunc

type CompressFunc func(ctx context.Context, algorithm string, body []byte, encryptKey []byte) (algorithmUsed string, result []byte, err *mft.Error)

func GZipCompressGenerator

func GZipCompressGenerator(level int) CompressFunc

type Generator

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

Generator - compressor

func GeneratorCreate

func GeneratorCreate(gzipDefaultLevel int) *Generator

GeneratorCreate - generate with default algs

func (*Generator) Add

func (g *Generator) Add(name string, compressor CompressFunc, restore RestoreFunc)

func (*Generator) Compress

func (g *Generator) Compress(ctx context.Context, must bool, algorithm string, body []byte, encryptKey []byte) (algorithmUsed string, result []byte, err *mft.Error)

func (*Generator) Init

func (g *Generator) Init()

func (*Generator) Restore

func (g *Generator) Restore(ctx context.Context, algorithm string, body []byte, decryptKey []byte) (algorithmUsed string, result []byte, err *mft.Error)

type RestoreFunc

type RestoreFunc func(ctx context.Context, algorithm string, body []byte, decryptKey []byte) (algorithmUsed string, result []byte, err *mft.Error)

Jump to

Keyboard shortcuts

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