Documentation ¶
Overview ¶
Package common contains various helper functions.
Index ¶
- Constants
- Variables
- func AllZero(b []byte) bool
- func BE_Bytes2Int(buf []byte) int64
- func BE_BytesToUint32(buf []byte) uint32
- func BE_BytesToUint64(buf []byte) uint64
- func BE_Int2Bytes(i int64) []byte
- func BE_Uint32ToBytes(i uint32) []byte
- func BE_Uint64ToBytes(i uint64) []byte
- func BigMax(x, y *big.Int) *big.Int
- func BigMin(x, y *big.Int) *big.Int
- func BigPow(a, b int64) *big.Int
- func BigUint64(v *big.Int) (uint64, bool)
- func Bool2Bytes(b bool) []byte
- func Byte(bigint *big.Int, padlength, n int) byte
- func Bytes2Hex(d []byte) string
- func BytesEqual(a, b []byte) bool
- func BytesToString(data []byte) string
- func CopyBytes(b []byte) (copiedBytes []byte)
- func CreateDirIfNotExist(dir string) error
- func Decrypt(cryptoGraph, passphrase string) (string, error)
- func DecryptBytes(encryptedJSON, passphrase []byte) ([]byte, error)
- func Encrypt(raw, passphrase string) (string, error)
- func EncryptBytes(raw, passphrase []byte) ([]byte, error)
- func Exp(base, exponent *big.Int) *big.Int
- func FromHex(s string) []byte
- func Hash(size int, data ...[]byte) []byte
- func Hash256(data ...[]byte) []byte
- func Hex2Bytes(str string) []byte
- func Hex2BytesFixed(str string, flen int) []byte
- func Hex32ToBytes(s string) [32]byte
- func Hex64ToBytes(s string) [64]byte
- func HexToBytes(s string) []byte
- func JoinBytes(data ...[]byte) []byte
- func LE_BytesToInt64(buf []byte) int64
- func LE_BytesToUint32(buf []byte) uint32
- func LE_BytesToUint64(buf []byte) uint64
- func LE_EncodeVarInt(val uint64) []byte
- func LE_Int64ToBytes(i int64) []byte
- func LE_Uint32ToBytes(i uint32) []byte
- func LE_Uint64ToBytes(i uint64) []byte
- func LeftPadBytes(slice []byte, l int) []byte
- func Max(x, y uint64) uint64
- func Min(x, y uint64) uint64
- func PaddedBigBytes(bigint *big.Int, n int) []byte
- func RandomFixedString(length int) string
- func ReadBits(bigint *big.Int, buf []byte)
- func ReverseBytes(str []byte) (result []byte)
- func RightPadBytes(slice []byte, l int) []byte
- func S256(x *big.Int) *big.Int
- func SafeAdd(x, y uint64) (uint64, bool)
- func SafeMul(x, y uint64) (uint64, bool)
- func SafeSub(x, y uint64) (uint64, bool)
- func String2Bytes(s string) []byte
- func StringToBigInt(str *string) (*big.Int, error)
- func ToHex(b []byte) stringdeprecated
- func ToIndentString(v interface{}) string
- func ToString(v interface{}) string
- func ToWordSize(size uint64) uint64
- func TrimBuffToString(bytes []byte) string
- func TrimQuotes(s string) string
- func U256(x *big.Int) *big.Int
Constants ¶
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 )
Variables ¶
Functions ¶
func BE_Bytes2Int ¶ added in v1.2.3
func BE_BytesToUint32 ¶ added in v1.2.3
func BE_BytesToUint64 ¶ added in v1.2.3
func BE_Int2Bytes ¶ added in v1.2.3
func BE_Uint32ToBytes ¶ added in v1.2.3
func BE_Uint64ToBytes ¶ added in v1.2.3
func BigUint64 ¶ added in v0.0.9
BigUint64 returns the integer casted to a uint64 and returns whether it overflowed in the process.
func Bool2Bytes ¶ added in v0.0.9
func Byte ¶ added in v0.0.9
Byte returns the byte at position n, with the supplied padlength in Little-Endian encoding. n==0 returns the MSB Example: bigint '5', padlength 32, n=31 => 5
func BytesEqual ¶ added in v0.0.9
func BytesToString ¶ added in v0.0.9
func CreateDirIfNotExist ¶
CreateDirIfNotExist create given folder
func DecryptBytes ¶ added in v0.0.5
DecryptBytes decrypt raw json to raw
func EncryptBytes ¶ added in v0.0.5
EncryptBytes encrypts raw by passphrase to json binary
func Exp ¶ added in v0.0.9
Exp implements exponentiation by squaring. Exp returns a newly-allocated big integer and does not change base or exponent. The result is truncated to 256 bits.
func FromHex ¶
FromHex returns the bytes represented by the hexadecimal string s. s may be prefixed with "0x".
func Hex2BytesFixed ¶
Hex2BytesFixed returns bytes of a specified fixed length flen.
func Hex32ToBytes ¶
func Hex64ToBytes ¶
func HexToBytes ¶
func LE_BytesToInt64 ¶ added in v1.2.3
func LE_BytesToUint32 ¶ added in v1.3.0
func LE_BytesToUint64 ¶ added in v1.2.3
func LE_EncodeVarInt ¶ added in v1.3.0
func LE_Int64ToBytes ¶ added in v1.2.3
func LE_Uint32ToBytes ¶ added in v1.3.0
func LE_Uint64ToBytes ¶ added in v1.2.3
func LeftPadBytes ¶
LeftPadBytes zero-pads slice to the left up to length l.
func PaddedBigBytes ¶ added in v0.0.9
PaddedBigBytes encodes a big integer as a big-endian byte slice. The length of the slice is at least n bytes.
func RandomFixedString ¶ added in v1.1.0
func ReadBits ¶ added in v0.0.9
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 RightPadBytes ¶
RightPadBytes zero-pads slice to the right up to length l.
func S256 ¶ added in v0.0.9
S256 interprets x as a two's complement number. x must not exceed 256 bits (the result is undefined if it does) and is not modified.
S256(0) = 0 S256(1) = 1 S256(2**255) = -2**255 S256(2**256-1) = -1
func String2Bytes ¶ added in v0.0.9
func ToIndentString ¶ added in v1.0.1
func ToIndentString(v interface{}) string
func ToWordSize ¶ added in v0.0.9
ToWordSize returns the ceiled word size required for memory expansion.
func TrimBuffToString ¶ added in v0.0.9
trim the '\00' byte
Types ¶
This section is empty.