utils

package
v0.0.0-...-982e07a Latest Latest
Warning

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

Go to latest
Published: Dec 19, 2023 License: Apache-2.0 Imports: 20 Imported by: 17

Documentation

Overview

Package utils contains various bits and pieces useful as helping functions all over the code.

Index

Constants

View Source
const (
	CommunityEdition = iota
	EnterpriseEdition
)

Set of types of product edition

View Source
const DefaultWaitGroupTimeoutDuration = time.Second

DefaultWaitGroupTimeoutDuration specifies how long should we wait for background goroutines finishing while ReaderServer shutdown

View Source
const (
	// NotFound indicated not found symbol
	NotFound = -1
)

Variables

View Source
var ErrDecodeOctalString = errors.New("can't decode escaped string")

ErrDecodeOctalString on incorrect decoding with DecodeOctal

View Source
var ErrInvalidVersionFormat = errors.New("value has incorrect format (semver 2.0.0 format expected, https://semver.org/)")

ErrInvalidVersionFormat error for incorrectly formatted version value

View Source
var VERSION = "0.95.0"

VERSION is current Acra suite version store it as string instead initialized struct value to easy change/grep/sed/replace value via scripts or with -ldflags "-X github.com/cossacklabs/acra/utils.VERSION=X.X.X"

Functions

func BytesToString

func BytesToString(data []byte) string

BytesToString converts data to string with re-using same allocated memory Warning: data shouldn't be changed after that because it will cause runtime error due to strings are immutable Only for read/iterate operations See https://groups.google.com/forum/#!msg/Golang-Nuts/ENgbUzYvCuU/90yGx7GUAgAJ .

Note it may break if string and/or slice header will change in the future go versions.

func DecodeEscaped

func DecodeEscaped(data []byte) ([]byte, error)

DecodeEscaped with hex or octal encodings

func DecodeOctal

func DecodeOctal(data []byte) ([]byte, error)

DecodeOctal escaped string See https://www.postgresql.org/docs/current/static/datatype-binary.html#AEN5667

func EncodeToOctal

func EncodeToOctal(data []byte) []byte

EncodeToOctal escape string See https://www.postgresql.org/docs/current/static/datatype-binary.html#AEN5667

func FileExists

func FileExists(path string) (bool, error)

FileExists returns true if file exists from path, path can be relative

func GetConfigPathByName

func GetConfigPathByName(name string) string

GetConfigPathByName returns filepath to config file named "name" from default configs folder

func IsPrintableEscapeChar

func IsPrintableEscapeChar(c byte) bool

IsPrintableEscapeChar returns true if character is ASCII printable (code between 32 and 126)

func IsPrintablePostgresqlString

func IsPrintablePostgresqlString(data []byte) bool

IsPrintablePostgresqlString returns true if it's valid utf8 string

func LoadPrivateKey

func LoadPrivateKey(path string) (*keys.PrivateKey, error)

LoadPrivateKey returns contents as PrivateKey from keyfile

func LoadPublicKey

func LoadPublicKey(path string) (*keys.PublicKey, error)

LoadPublicKey returns contents as PublicKey from keyfile

func Min

func Min(x, y int) int

Min returns minimum integer out of two

func PgEncodeToHex

func PgEncodeToHex(data []byte) []byte

PgEncodeToHex encode binary data to hex SQL literal

func QuoteValue

func QuoteValue(name string) string

QuoteValue returns name in quotes, if name contains quotes, doubles them

func ReadData

func ReadData(reader io.Reader) ([]byte, error)

ReadData reads length of data block, then reads data content returns data content

func ReadDataLength

func ReadDataLength(reader io.Reader) ([]byte, int, error)

ReadDataLength return read data from reader, parsed data length or err

func ReadFile

func ReadFile(path string) ([]byte, error)

ReadFile returns contents of file

func SendData

func SendData(data []byte, conn io.Writer) error

SendData writes length of data block to connection, then writes data itself

func WaitWithTimeout

func WaitWithTimeout(wg *sync.WaitGroup, timeout time.Duration) bool

WaitWithTimeout waits for the waitgroup for the specified max timeout. Returns true if waiting timed out.

func WriteFull

func WriteFull(data []byte, wr io.Writer) (int, error)

WriteFull writes data to io.Writer. if wr.Write will return n <= len(data) will

sent the rest of data until error or total sent byte count == len(data)

func ZeroizeBytes

func ZeroizeBytes(data []byte)

ZeroizeBytes wipes a byte slice from memory, filling it with zeros.

func ZeroizeKeyPair

func ZeroizeKeyPair(keypair *keys.Keypair)

ZeroizeKeyPair wipes a private key of a key pair from memory, filling it with zero bytes.

func ZeroizePrivateKey

func ZeroizePrivateKey(privateKey *keys.PrivateKey)

ZeroizePrivateKey wipes a private key from memory, filling it with zero bytes.

func ZeroizePrivateKeys

func ZeroizePrivateKeys(privateKeys []*keys.PrivateKey)

ZeroizePrivateKeys wipes a slice of private keys from memory, filling them with zero bytes.

func ZeroizeSymmetricKey

func ZeroizeSymmetricKey(key []byte)

ZeroizeSymmetricKey wipes a symmetric key from memory, filling it with zero bytes.

func ZeroizeSymmetricKeys

func ZeroizeSymmetricKeys(keys [][]byte)

ZeroizeSymmetricKeys wipes a symmetric keys from memory, filling it with zero bytes.

Types

type BinaryEncoder

type BinaryEncoder interface {
	EncodeToString([]byte) string
	Encode([]byte) interface{}
}

BinaryEncoder encodes binary to string

type CompareFlag

type CompareFlag uint8

CompareFlag flags what parts of version to compare

const (
	MajorFlag CompareFlag = 1 << iota
	MinorFlag
	PatchFlag
)

Flags used for CompareOnly to mark parts to check

func (CompareFlag) String

func (f CompareFlag) String() string

String return value as string in format major | major-minor | major-minor-patch | major-patch | minor-patch

type ComparisonStatus

type ComparisonStatus int

ComparisonStatus result of comparison versions

const (
	Less    ComparisonStatus = iota - 1 // -1
	Equal                               // 0
	Greater                             // 1
	InvalidFlags
)

Available constant values for ComparisonStatus

type EscapeEncoder

type EscapeEncoder struct{}

EscapeEncoder for Postgres

func (*EscapeEncoder) Encode

func (e *EscapeEncoder) Encode(data []byte) interface{}

Encode return data as is

func (*EscapeEncoder) EncodeToString

func (e *EscapeEncoder) EncodeToString(data []byte) string

EncodeToString bytes to Postgres Octal format

type HexEncoder

type HexEncoder struct{}

HexEncoder for hex

func (*HexEncoder) Encode

func (e *HexEncoder) Encode(data []byte) interface{}

Encode return data as is

func (*HexEncoder) EncodeToString

func (*HexEncoder) EncodeToString(data []byte) string

EncodeToString bytes to Hex

type MysqlEncoder

type MysqlEncoder struct{}

MysqlEncoder encodes MySQL packets

func (*MysqlEncoder) Encode

func (e *MysqlEncoder) Encode(data []byte) interface{}

Encode return data as is

func (*MysqlEncoder) EncodeToString

func (e *MysqlEncoder) EncodeToString(data []byte) string

EncodeToString bytes to Hex supported by MySQL

type PqEncoder

type PqEncoder struct{}

PqEncoder wrap array with pq.Array

func (*PqEncoder) Encode

func (*PqEncoder) Encode(data []byte) interface{}

Encode wrap data with pq.Array

func (*PqEncoder) EncodeToString

func (*PqEncoder) EncodeToString(data []byte) string

EncodeToString use HexEncoder.EncodeToString

type ProductEdition

type ProductEdition int

ProductEdition type for edition values

Edition type of product

type Version

type Version struct {
	Major string
	Minor string
	Patch string
}

Version store version info

func GetParsedVersion

func GetParsedVersion() (*Version, error)

GetParsedVersion return version as Version struct

func ParseVersion

func ParseVersion(version string) (*Version, error)

ParseVersion and return as struct

func (*Version) Compare

func (v *Version) Compare(v2 *Version) ComparisonStatus

Compare compare v with v2 and return ComparisonStatus [Less|Equal|Greater]

func (*Version) CompareOnly

func (v *Version) CompareOnly(flags CompareFlag, v2 *Version) ComparisonStatus

CompareOnly compares only parts in order major -> minor -> patch if the corresponding bit is set to 1 return InvalidFlags if flags == 0 or flags > (MajorFlag|MinorFlag|PatchFlag)

func (*Version) MajorAsFloat64

func (v *Version) MajorAsFloat64() (float64, error)

MajorAsFloat64 return major number as float64

func (*Version) MinorAsFloat64

func (v *Version) MinorAsFloat64() (float64, error)

MinorAsFloat64 return minor number as float64

func (*Version) PatchAsFloat64

func (v *Version) PatchAsFloat64() (float64, error)

PatchAsFloat64 return patch number as float64

func (*Version) String

func (v *Version) String() string

String format version as string

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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