Documentation ¶
Overview ¶
Package utils contains various bits and pieces useful as helping functions all over the code.
Index ¶
- Constants
- Variables
- func BytesToString(data []byte) string
- func DecodeEscaped(data []byte) ([]byte, error)
- func DecodeOctal(data []byte) ([]byte, error)
- func EncodeToOctal(data []byte) []byte
- func FileExists(path string) (bool, error)
- func GetConfigPathByName(name string) string
- func IsPrintableEscapeChar(c byte) bool
- func IsPrintablePostgresqlString(data []byte) bool
- func LoadPrivateKey(path string) (*keys.PrivateKey, error)
- func LoadPublicKey(path string) (*keys.PublicKey, error)
- func Min(x, y int) int
- func PgEncodeToHex(data []byte) []byte
- func QuoteValue(name string) string
- func ReadData(reader io.Reader) ([]byte, error)
- func ReadDataLength(reader io.Reader) ([]byte, int, error)
- func ReadFile(path string) ([]byte, error)
- func SendData(data []byte, conn io.Writer) error
- func WaitWithTimeout(wg *sync.WaitGroup, timeout time.Duration) bool
- func WriteFull(data []byte, wr io.Writer) (int, error)
- func ZeroizeBytes(data []byte)
- func ZeroizeKeyPair(keypair *keys.Keypair)
- func ZeroizePrivateKey(privateKey *keys.PrivateKey)
- func ZeroizePrivateKeys(privateKeys []*keys.PrivateKey)
- func ZeroizeSymmetricKey(key []byte)
- func ZeroizeSymmetricKeys(keys [][]byte)
- type BinaryEncoder
- type CompareFlag
- type ComparisonStatus
- type EscapeEncoder
- type HexEncoder
- type MysqlEncoder
- type PqEncoder
- type ProductEdition
- type Version
- func (v *Version) Compare(v2 *Version) ComparisonStatus
- func (v *Version) CompareOnly(flags CompareFlag, v2 *Version) ComparisonStatus
- func (v *Version) MajorAsFloat64() (float64, error)
- func (v *Version) MinorAsFloat64() (float64, error)
- func (v *Version) PatchAsFloat64() (float64, error)
- func (v *Version) String() string
Constants ¶
const ( CommunityEdition = iota EnterpriseEdition )
Set of types of product edition
const DefaultWaitGroupTimeoutDuration = time.Second
DefaultWaitGroupTimeoutDuration specifies how long should we wait for background goroutines finishing while ReaderServer shutdown
const (
// NotFound indicated not found symbol
NotFound = -1
)
Variables ¶
var ErrDecodeOctalString = errors.New("can't decode escaped string")
ErrDecodeOctalString on incorrect decoding with DecodeOctal
var ErrInvalidVersionFormat = errors.New("value has incorrect format (semver 2.0.0 format expected, https://semver.org/)")
ErrInvalidVersionFormat error for incorrectly formatted version value
var VERSION = "0.96.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 ¶
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 ¶
DecodeEscaped with hex or octal encodings
func DecodeOctal ¶
DecodeOctal escaped string See https://www.postgresql.org/docs/current/static/datatype-binary.html#AEN5667
func EncodeToOctal ¶
EncodeToOctal escape string See https://www.postgresql.org/docs/current/static/datatype-binary.html#AEN5667
func FileExists ¶
FileExists returns true if file exists from path, path can be relative
func GetConfigPathByName ¶
GetConfigPathByName returns filepath to config file named "name" from default configs folder
func IsPrintableEscapeChar ¶
IsPrintableEscapeChar returns true if character is ASCII printable (code between 32 and 126)
func IsPrintablePostgresqlString ¶
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 ¶
LoadPublicKey returns contents as PublicKey from keyfile
func PgEncodeToHex ¶
PgEncodeToHex encode binary data to hex SQL literal
func QuoteValue ¶
QuoteValue returns name in quotes, if name contains quotes, doubles them
func ReadDataLength ¶
ReadDataLength return read data from reader, parsed data length or err
func WaitWithTimeout ¶
WaitWithTimeout waits for the waitgroup for the specified max timeout. Returns true if waiting timed out.
func WriteFull ¶
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 ¶
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 ¶
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) EncodeToString ¶
EncodeToString use HexEncoder.EncodeToString
type ProductEdition ¶
type ProductEdition int
ProductEdition type for edition values
var Edition ProductEdition = CommunityEdition
Edition type of product
type Version ¶
Version store version info
func GetParsedVersion ¶
GetParsedVersion return version as Version struct
func ParseVersion ¶
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 ¶
MajorAsFloat64 return major number as float64
func (*Version) MinorAsFloat64 ¶
MinorAsFloat64 return minor number as float64
func (*Version) PatchAsFloat64 ¶
PatchAsFloat64 return patch number as float64