utils

package
v0.0.0-...-00d340d Latest Latest
Warning

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

Go to latest
Published: Jul 22, 2019 License: Apache-2.0 Imports: 26 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AppendAll

func AppendAll(content ...[]byte) []byte

func ArraytoString

func ArraytoString(data []string) string

func AssertContains

func AssertContains(t testing.TB, slice interface{}, value interface{})

func AssertContainsAll

func AssertContainsAll(t testing.TB, sliceActual interface{}, sliceExpected interface{})

func AssertEquals

func AssertEquals(t testing.TB, actual interface{}, expected interface{})

func AssertError

func AssertError(t testing.TB, err error, message string)

func AssertNil

func AssertNil(t testing.TB, value interface{})

func AssertNoError

func AssertNoError(t testing.TB, err error, message string)

func AssertNotEquals

func AssertNotEquals(t testing.TB, actual interface{}, expected interface{})

func AssertNotNil

func AssertNotNil(t testing.TB, value interface{})

func AssertPanic

func AssertPanic(t testing.TB, msg string)

func AssertSame

func AssertSame(t testing.TB, actual interface{}, expected interface{})

func BoolToPtr

func BoolToPtr(b bool) *bool

boolToPtr returns the pointer to a boolean

func CalculateBCHash

func CalculateBCHash(txData []byte) [32]byte

CalculateBCHash returns the Bitcoin hash (double sha256) of the given transaction

func CleanEnvVar

func CleanEnvVar(s string, r byte) string

CleanEnvVar replaces all occurrences of illegal characters in an environment variable with the specified byte.

func ComputeBitcoinAddress

func ComputeBitcoinAddress(pk []byte) string

ComputeBitcoinAddress compute address from public key Key hash = RIPEMD-160(SHA-256(public key)) Checksum = SHA-256(SHA-256(Key hash)) first 4 bytes Bitcoin Address = Base58Encode(Key hash + Checksum)

func ComputeCryptoHash

func ComputeCryptoHash(data []byte) (hash []byte)

ComputeCryptoHash should be used in openchain code so that we can change the actual algo used for crypto-hash at one place

func ComputeSha256

func ComputeSha256(data string) string

func ConstructRandomBytes

func ConstructRandomBytes(t testing.TB, size int) []byte

func CopyFile

func CopyFile(src, dst string) (err error)

CopyFile copies a file from src to dst. If src and dst files exist, and are the same, then return success. Otherise, attempt to create a hard link between the two files. If that fail, copy the file contents from src to dst.

func CopyMapStringFloat64

func CopyMapStringFloat64(m map[string]float64) map[string]float64

func CopyMapStringInt

func CopyMapStringInt(m map[string]int) map[string]int

func CopyMapStringString

func CopyMapStringString(m map[string]string) map[string]string

Helpers for copying generic structures.

func CopySliceInt

func CopySliceInt(s []int) []int

func CopySliceString

func CopySliceString(s []string) []string

func CreateUtcTimestamp

func CreateUtcTimestamp() *gp.Timestamp

CreateUtcTimestamp returns a google/protobuf/Timestamp in UTC

func CreateUtcToday

func CreateUtcToday() string

CreateUtcToday return current utc date, format is: "%d-%02d-%02d"

func DecodeBase58

func DecodeBase58(in string) []byte

DecodeBase58 decodes from Base58

func DecodeBase64

func DecodeBase64(in string) ([]byte, error)

DecodeBase64 decodes from Base64

func Decrypt

func Decrypt(key []byte, cryptoText string) string

Decrypt from base64 to decrypted string

func EncodeBase58

func EncodeBase58(in []byte) string

EncodeBase58 encodes to Base58

func EncodeBase64

func EncodeBase64(in []byte) string

EncodeBase64 encodes to Base64

func Encrypt

func Encrypt(key []byte, text string) string

Encrypt string to base64 crypto using AES

func EncryptPassword

func EncryptPassword(pass string) string

EncryptPassword encrypt password and return hash result you can not decrypt this password any more

func FindMissingElements

func FindMissingElements(all []string, some []string) (delta []string)

FindMissingElements identifies the elements of the first slice that are not present in the second The second slice is expected to be a subset of the first slice

func GenerateBytesUUID

func GenerateBytesUUID() []byte

GenerateBytesUUID returns a UUID based on RFC 4122 returning the generated bytes

func GenerateHashFromSignature

func GenerateHashFromSignature(path string, ctor string, args []string) []byte

GenerateHashFromSignature returns a hash of the combined parameters

func GenerateIDWithAlg

func GenerateIDWithAlg(customIDgenAlg string, encodedPayload string) (string, error)

GenerateIDWithAlg generates an ID using a custom algorithm

func GenerateIntUUID

func GenerateIntUUID() *big.Int

GenerateIntUUID returns a UUID based on RFC 4122 returning a big.Int

func GenerateShortID

func GenerateShortID() string

GenerateShortID generates a short id (length = 9)

func GenerateUUID

func GenerateUUID() string

GenerateUUID returns a UUID based on RFC 4122

func GenerateUUIDfromTxSHAHash

func GenerateUUIDfromTxSHAHash(txData []byte) string

GenerateUUIDfromTxSHAHash generates SHA256 hash using Tx payload, and uses its first 128 bits as a UUID

func GetFQDN

func GetFQDN() string

GetFQDN Fully Qualified Domain Name returns "unknown" or hostanme in case of error

func Int2Str

func Int2Str(i, length int) (result string)

i=1, lenght=2 -> result=01 i=10, lenght=2 -> result=10 i=1, lenght=3 -> result=001

func IntArrayEquals

func IntArrayEquals(a []int, b []int) bool

IntArrayEquals checks if the arrays of ints are the same

func IntToPtr

func IntToPtr(i int) *int

IntToPtr returns the pointer to an int

func IsHexdigest

func IsHexdigest(data, digestType string) (valid bool, err error)

Check if the data is valid SHA1, MD5 or SHA256 string.

func IsUUID

func IsUUID(str string) bool

IsUUID returns true if the given string is a valid UUID.

func MapStringStringSliceValueSet

func MapStringStringSliceValueSet(m map[string][]string) []string

MapStringStringSliceValueSet returns the set of values in a map[string][]string

func ParseTestParams

func ParseTestParams() []string

func RandNewStr

func RandNewStr(len int) string

func RawDecrypt

func RawDecrypt(key []byte, cryptoText string) string

Decrypt from base64 RawURLEncoding to decrypted string

func RawEncrypt

func RawEncrypt(key []byte, text string) string

Encrypt string to base64 RawURLEncoding crypto using AES

func RemoveStringSliceDuplicate

func RemoveStringSliceDuplicate(haystack []string, isSensitive bool) []string

RemoveDuplicate remove duplicates for haystack(isSensitive true for case-sensitive, false for case-insensitive)

func SliceSetDisjoint

func SliceSetDisjoint(first, second []string) (bool, []string)

func SliceStringIsSubset

func SliceStringIsSubset(larger, smaller []string) (bool, []string)

SliceStringIsSubset returns whether the smaller set of strings is a subset of the larger. If the smaller slice is not a subset, the offending elements are returned.

func SliceStringToSet

func SliceStringToSet(s []string) map[string]struct{}

func StringInSlice

func StringInSlice(a string, list []string) bool

func StringSliceHas

func StringSliceHas(haystack []string, needle string) bool

Has returns true if the needle is in the haystack (case-sensitive)

func StringSliceHasI

func StringSliceHasI(haystack []string, needle string) bool

HasI returns true if the needle is in the haystack (case-insensitive)

func StringToPtr

func StringToPtr(str string) *string

StringToPtr returns the pointer to a string

func TimeToPtr

func TimeToPtr(t time.Duration) *time.Duration

TimeToPtr returns the pointer to a time stamp

func Uint64ToPtr

func Uint64ToPtr(u uint64) *uint64

UintToPtr returns the pointer to an uint

func ValidateBase64EncodingString

func ValidateBase64EncodingString(encodingString string) bool

validate base64 encoding string

func ValidateTXID

func ValidateTXID(txid string) bool

validate txid from blockchain return

func ValidateUUID

func ValidateUUID(uuid string) bool

validate UUID base on RFC 4122(uuid v4)

func VerifyPassword

func VerifyPassword(pass, hash string) bool

VerifyPassword verify the pass is match with the given hash

Types

type TestRandomNumberGenerator

type TestRandomNumberGenerator struct {
	// contains filtered or unexported fields
}

func NewTestRandomNumberGenerator

func NewTestRandomNumberGenerator(maxNumber int) *TestRandomNumberGenerator

func (*TestRandomNumberGenerator) Next

func (randNumGenerator *TestRandomNumberGenerator) Next() int

Jump to

Keyboard shortcuts

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