common

package
v0.0.0-...-1c4572a Latest Latest
Warning

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

Go to latest
Published: Nov 19, 2018 License: BSD-2-Clause Imports: 15 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrNetWorkDealy = errors.New("ErrNetWorkDealy")

Functions

func Bytes2Hex

func Bytes2Hex(d []byte) string

func CopyBytes

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

Copy bytes

Returns an exact copy of the provided bytes

func DoubleHashB

func DoubleHashB(b []byte) []byte

DoubleHashB calculates hash(hash(b)) and returns the resulting bytes.

func EmptyHash

func EmptyHash(h Hash) bool

func FromHex

func FromHex(s string) ([]byte, error)

func GetNtpTime

func GetNtpTime(host string) (time.Time, error)
    t2      t3                 t6          t7
---------------------------------------------------------
         /\         \                 /\            \
         /           \                /              \
        /             \              /                \
       /               \/           /                 \/
---------------------------------------------------------
     t1                t4         t5                  t8

利用服务器返回的 t2, t3, 和本地的 t1, t4 校准时间 delt = ((t2-t1)+(t3-t4))/2 current = t4 + delt

func GetRandBytes

func GetRandBytes(min, max int) []byte

func GetRandPrintString

func GetRandPrintString(min, max int) string

func GetRandString

func GetRandString(length int) string

func GetRealTime

func GetRealTime(hosts []string) time.Time

func GetRealTimeRetry

func GetRealTimeRetry(hosts []string, retry int) time.Time

func HasHexPrefix

func HasHexPrefix(str string) bool

func HashB

func HashB(b []byte) []byte

HashB calculates hash(b) and returns the resulting bytes.

func HashHex

func HashHex(d []byte) string

func Hex2Bytes

func Hex2Bytes(str string) ([]byte, error)

func IsHex

func IsHex(str string) bool

func MaxInt32

func MaxInt32(left, right int32) int32

func MinInt32

func MinInt32(left, right int32) int32

func RandKey

func RandKey() (ret [32]byte)

func Rimp160AfterSha256

func Rimp160AfterSha256(b []byte) (out [20]byte)

Returns hash: RIMP160( SHA256( data ) ) Where possible, using RimpHash() should be a bit faster

func Sha256

func Sha256(b []byte) []byte

func Sha2Sum

func Sha2Sum(b []byte) (out [32]byte)

Returns hash: SHA256( SHA256( data ) ) Where possible, using ShaHash() should be a bit faster

func ShaKeccak256

func ShaKeccak256(b []byte) []byte

func ToHex

func ToHex(b []byte) string

Types

type Hash

type Hash [hashLength]byte

func BigToHash

func BigToHash(b *big.Int) Hash

func BytesToHash

func BytesToHash(b []byte) Hash

func DoubleHashH

func DoubleHashH(b []byte) Hash

DoubleHashH calculates hash(hash(b)) and returns the resulting bytes as a Hash.

func HashH

func HashH(b []byte) Hash

HashH calculates hash(b) and returns the resulting bytes as a Hash.

func HexToHash

func HexToHash(s string) Hash

func StringToHash

func StringToHash(s string) Hash

func (Hash) Bytes

func (h Hash) Bytes() []byte

func (Hash) Format

func (h Hash) Format(s fmt.State, c rune)

Format implements fmt.Formatter, forcing the byte slice to be formatted as is, without going through the stringer interface used for logging.

func (Hash) Hex

func (h Hash) Hex() string

func (Hash) Revers

func (h Hash) Revers() Hash

String returns the Hash as the hexadecimal string of the byte-reversed hash.

func (Hash) ReversString

func (h Hash) ReversString() string

String returns the Hash as the hexadecimal string of the byte-reversed hash.

func (*Hash) Set

func (h *Hash) Set(other Hash)

Sets h to other

func (*Hash) SetBytes

func (h *Hash) SetBytes(b []byte)

Sets the hash to the value of b. If b is larger than len(h), 'b' will be cropped (from the left).

func (*Hash) SetString

func (h *Hash) SetString(s string)

Set string `s` to h. If s is larger than len(h) s will be cropped (from left) to fit.

func (Hash) Str

func (h Hash) Str() string

Get the string representation of the underlying hash

func (Hash) String

func (h Hash) String() string

String implements the stringer interface and is used also by the logger when doing full logging into a file.

func (Hash) TerminalString

func (h Hash) TerminalString() string

TerminalString implements log.TerminalStringer, formatting a string for console output during logging.

Directories

Path Synopsis
sha3
Package sha3 implements the SHA-3 fixed-output-length hash functions and the SHAKE variable-output-length hash functions defined by FIPS-202.
Package sha3 implements the SHA-3 fixed-output-length hash functions and the SHAKE variable-output-length hash functions defined by FIPS-202.
db
Package ed25519 implements the Ed25519 signature algorithm.
Package ed25519 implements the Ed25519 signature algorithm.
edwards25519
Package edwards25519 implements operations in GF(2**255-19) and on an Edwards curve that is isomorphic to curve25519.
Package edwards25519 implements operations in GF(2**255-19) and on an Edwards curve that is isomorphic to curve25519.
log
log15
Package log15 provides an opinionated, simple toolkit for best-practice logging that is both human and machine readable.
Package log15 provides an opinionated, simple toolkit for best-practice logging that is both human and machine readable.
Package pubsub implements a simple multi-topic pub-sub library.
Package pubsub implements a simple multi-topic pub-sub library.

Jump to

Keyboard shortcuts

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