util

package
v1.5.1 Latest Latest
Warning

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

Go to latest
Published: Apr 25, 2021 License: MIT Imports: 16 Imported by: 0

Documentation

Overview

Package common contains various helper functions.

Index

Constants

View Source
const (
	// StandardScryptN is the N parameter of Scrypt encryption algorithm, using 256MB
	// memory and taking approximately 1s CPU time on a modern processor.
	StandardScryptN = 1 << 18

	// StandardScryptP is the P parameter of Scrypt encryption algorithm, using 256MB
	// memory and taking approximately 1s CPU time on a modern processor.
	StandardScryptP = 1
)
View Source
const (
	MaxUint64 = uint64(1<<64 - 1)

	// number of bits in a big.Word
	WordBits = 32 << (uint64(^big.Word(0)) >> 63)
	// number of bytes in a big.Word
	WordBytes = WordBits / 8
	// number of bytes in a vm word
	WordSize = 32
)

Variables

View Source
var (
	Big0   = big.NewInt(0)
	Big1   = big.NewInt(1)
	Big2   = big.NewInt(2)
	Big10  = big.NewInt(10)
	Big31  = big.NewInt(31)
	Big32  = big.NewInt(32)
	Big256 = big.NewInt(256)
	Big257 = big.NewInt(257)

	Tt255   = BigPow(2, 255)
	Tt256   = BigPow(2, 256)
	Tt256m1 = new(big.Int).Sub(Tt256, big.NewInt(1))
)

Functions

func BE_Bytes2Int added in v1.2.3

func BE_Bytes2Int(buf []byte) int64

func BE_BytesToUint16 added in v1.4.0

func BE_BytesToUint16(buf []byte) uint16

func BE_BytesToUint32 added in v1.2.3

func BE_BytesToUint32(buf []byte) uint32

func BE_BytesToUint64 added in v1.2.3

func BE_BytesToUint64(buf []byte) uint64

func BE_Int2Bytes added in v1.2.3

func BE_Int2Bytes(i int64) []byte

func BE_Uint16ToBytes added in v1.4.0

func BE_Uint16ToBytes(i uint16) []byte

func BE_Uint32ToBytes added in v1.2.3

func BE_Uint32ToBytes(i uint32) []byte

func BE_Uint64ToBytes added in v1.2.3

func BE_Uint64ToBytes(i uint64) []byte

func BigPow added in v0.0.9

func BigPow(a, b int64) *big.Int

BigPow returns a ** b as a big integer.

func Bool2Bytes added in v0.0.9

func Bool2Bytes(b bool) []byte

func CopyBytes

func CopyBytes(b []byte) (copiedBytes []byte)

CopyBytes returns an exact copy of the provided bytes.

func CreateDirIfNotExist

func CreateDirIfNotExist(dir string) error

CreateDirIfNotExist create given folder

func Decrypt added in v0.0.5

func Decrypt(cryptoGraph, passphrase string) (string, error)

func DecryptBytes added in v0.0.5

func DecryptBytes(encryptedJSON, passphrase []byte) ([]byte, error)

DecryptBytes decrypt raw json to raw

func Encrypt added in v0.0.5

func Encrypt(raw, passphrase string) (string, error)

func EncryptBytes added in v0.0.5

func EncryptBytes(raw, passphrase []byte) ([]byte, error)

EncryptBytes encrypts raw by passphrase to json binary

func FromHex

func FromHex(s string) []byte

FromHex returns the bytes represented by the hexadecimal string s. s may be prefixed with "0x".

func Hex2Bytes

func Hex2Bytes(str string) []byte

Hex2Bytes returns the bytes represented by the hexadecimal string str.

func HexToBytes

func HexToBytes(s string) []byte

func LE_BytesToInt64 added in v1.2.3

func LE_BytesToInt64(buf []byte) int64

func LE_BytesToUint16 added in v1.4.0

func LE_BytesToUint16(buf []byte) uint16

func LE_BytesToUint32 added in v1.3.0

func LE_BytesToUint32(buf []byte) uint32

func LE_BytesToUint64 added in v1.2.3

func LE_BytesToUint64(buf []byte) uint64

func LE_EncodeVarInt added in v1.3.0

func LE_EncodeVarInt(val uint64) []byte

func LE_Int64ToBytes added in v1.2.3

func LE_Int64ToBytes(i int64) []byte

func LE_Uint16ToBytes added in v1.4.0

func LE_Uint16ToBytes(i uint16) []byte

func LE_Uint32ToBytes added in v1.3.0

func LE_Uint32ToBytes(i uint32) []byte

func LE_Uint64ToBytes added in v1.2.3

func LE_Uint64ToBytes(i uint64) []byte

func LeftPadBytes

func LeftPadBytes(slice []byte, l int) []byte

LeftPadBytes zero-pads slice to the left up to length l.

func Max added in v0.0.9

func Max(x, y uint64) uint64

func Min added in v0.0.9

func Min(x, y uint64) uint64

func PaddedBigBytes added in v0.0.9

func PaddedBigBytes(bigint *big.Int, n int) []byte

PaddedBigBytes encodes a big integer as a big-endian byte slice. The length of the slice is at least n bytes.

func RandomFixedBytes added in v1.4.0

func RandomFixedBytes(length int) []byte

func RandomFixedString added in v1.1.0

func RandomFixedString(length int) string

func RandomFixedStringWithSeed added in v1.4.0

func RandomFixedStringWithSeed(length int, seed int64) string

func ReadBits added in v0.0.9

func ReadBits(bigint *big.Int, buf []byte)

ReadBits encodes the absolute amount of bigint as big-endian bytes. Callers must ensure that buf has enough space. If buf is too short the result will be incomplete.

func ReverseBytes

func ReverseBytes(str []byte) (result []byte)

func RightPadBytes

func RightPadBytes(slice []byte, l int) []byte

RightPadBytes zero-pads slice to the right up to length l.

func SafeAdd added in v0.0.9

func SafeAdd(x, y uint64) (uint64, bool)

SafeAdd returns the result and whether overflow occurred.

func SafeMul added in v0.0.9

func SafeMul(x, y uint64) (uint64, bool)

SafeMul returns multiplication result and whether overflow occurred.

func SafeSub added in v0.0.9

func SafeSub(x, y uint64) (uint64, bool)

SafeSub returns subtraction result and whether overflow occurred.

func String2Bytes added in v0.0.9

func String2Bytes(s string) []byte

func StringToBigInt added in v0.0.9

func StringToBigInt(str *string) (*big.Int, error)

func ToIndentString added in v1.0.1

func ToIndentString(v interface{}) string

func ToString added in v0.0.5

func ToString(v interface{}) string

func TrimBuffToString added in v0.0.9

func TrimBuffToString(bytes []byte) string

trim the '\00' byte

func TrimQuotes

func TrimQuotes(s string) string

TrimQuotes trim quotes of string if quotes exist

func U256 added in v0.0.9

func U256(x *big.Int) *big.Int

U256 encodes as a 256 bit two's complement number. This operation is destructive.

func UInt32Max added in v1.4.0

func UInt32Max(x, y uint32) uint32

UInt32Max returns the larger of x or y.

func UInt32Min added in v1.4.0

func UInt32Min(a, b uint32) uint32

UInt32Max returns the smaller of x or y.

func VerifyEmailFormat added in v1.4.0

func VerifyEmailFormat(email string) bool

Types

This section is empty.

Directories

Path Synopsis
Package hexutil implements hex encoding with 0x prefix.
Package hexutil implements hex encoding with 0x prefix.

Jump to

Keyboard shortcuts

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