util

package
v0.0.0-...-3a21ec0 Latest Latest
Warning

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

Go to latest
Published: Oct 7, 2020 License: Apache-2.0 Imports: 39 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// TagDefault is the tag name for a default value of a field as recognized
	// by RegisterFlags.
	TagDefault = "def"
	// TagHelp is the tag name for a help message of a field as recognized
	// by RegisterFlags.
	TagHelp = "help"
	// TagOpt is the tag name for a one character option of a field as recognized
	// by RegisterFlags.  For example, a value of "d" reserves "-d" for the
	// command line argument.
	TagOpt = "opt"
	// TagSkip is the tag name which causes the field to be skipped by
	// RegisterFlags.
	TagSkip = "skip"
	// TagHide is the tag name which causes the field to be hidden
	TagHide = "hide"
)
View Source
const SecretTag = "mask"

SecretTag to tag a field as secret as in password, token

Variables

View Source
var (

	// ErrNotImplemented used to return errors for functions not implemented
	ErrNotImplemented = errors.New("NOT YET IMPLEMENTED")
)
View Source
var RevocationReasonCodes = map[string]int{
	"unspecified":          ocsp.Unspecified,
	"keycompromise":        ocsp.KeyCompromise,
	"cacompromise":         ocsp.CACompromise,
	"affiliationchanged":   ocsp.AffiliationChanged,
	"superseded":           ocsp.Superseded,
	"cessationofoperation": ocsp.CessationOfOperation,
	"certificatehold":      ocsp.CertificateHold,
	"removefromcrl":        ocsp.RemoveFromCRL,
	"privilegewithdrawn":   ocsp.PrivilegeWithdrawn,
	"aacompromise":         ocsp.AACompromise,
}

RevocationReasonCodes is a map between string reason codes to integers as defined in RFC 5280

View Source
var URLRegex = regexp.MustCompile("(ldap|http)s*://(\\S+):(\\S+)@")

URLRegex is the regular expression to check if a value is an URL

Functions

func B64Decode

func B64Decode(str string) (buf []byte, err error)

B64Decode base64 decodes a string

func B64Encode

func B64Encode(buf []byte) string

B64Encode base64 encodes bytes

func CalcGasCost

func CalcGasCost(gasLimit uint64, gasPrice *big.Int) *big.Int

CalcGasCost calculate gas cost given gas limit (units) and gas price (wei)

func CmdRunBegin

func CmdRunBegin(v *viper.Viper)

CmdRunBegin is called at the beginning of each cobra run function

func CopyMissingValues

func CopyMissingValues(src, dst interface{})

CopyMissingValues checks the dst interface for missing values and replaces them with value from src config struct. This does a deep copy of pointers.

func CreateKeyStore

func CreateKeyStore(path string, password string) (*ks.KeyStore, string, error)

CreateKeyStore in host directory

func EqualBytes

func EqualBytes(a [32]byte, b [32]byte) bool

EqualBytes ...

func ErrorContains

func ErrorContains(t *testing.T, err error, contains, msg string, args ...interface{})

ErrorContains will check to see if an error occurred, if so it will check that it contains the appropriate error message

func Fatal

func Fatal(format string, v ...interface{})

Fatal logs a fatal message and exits

func FatalError

func FatalError(t *testing.T, err error, msg string, args ...interface{})

FatalError will check to see if an error occured if so it will cause the test cases exit

func FileExists

func FileExists(name string) bool

FileExists checks to see if a file exists

func FlagString

func FlagString(v *viper.Viper, flags *pflag.FlagSet, name, short string, def string, desc string)

FlagString sets up a flag for a string, binding it to its name

func FromECDSA

func FromECDSA(privateKey *ecdsa.PrivateKey) string

FromECDSA get PrivateKey

func GetDefaultConfigFile

func GetDefaultConfigFile(cmdName string) string

GetDefaultConfigFile gets the default path for the config file to display in usage message

func GetECPrivateKey

func GetECPrivateKey(raw []byte) (*ecdsa.PrivateKey, error)

GetECPrivateKey get *ecdsa.PrivateKey from key pem

func GetKey

func GetKey(file string, password string) (*ks.Key, error)

GetKey get a key from KeyStore

func GetMaskedURL

func GetMaskedURL(url string) string

GetMaskedURL returns masked URL. It masks username and password from the URL if present

func GetRSAPrivateKey

func GetRSAPrivateKey(raw []byte) (*rsa.PrivateKey, error)

GetRSAPrivateKey get *rsa.PrivateKey from key pem

func GetSerialAsHex

func GetSerialAsHex(serial *big.Int) string

GetSerialAsHex returns the serial number from certificate as hex format

func GetSliceFromList

func GetSliceFromList(split string, delim string) []string

GetSliceFromList will return a slice from a list

func HTTPRequestToString

func HTTPRequestToString(req *http.Request) string

HTTPRequestToString returns a string for an HTTP request for debuggging

func HTTPResponseToString

func HTTPResponseToString(resp *http.Response) string

HTTPResponseToString returns a string for an HTTP response for debuggging

func Hostname

func Hostname() string

Hostname name returns the hostname of the machine

func ImportKeyStore

func ImportKeyStore(file string, password string) (*ks.KeyStore, *accounts.Account, error)

ImportKeyStore from keystore in host directory

func IsSubsetOf

func IsSubsetOf(small, big string) error

IsSubsetOf returns an error if there is something in 'small' that is not in 'big'. Both small and big are assumed to be comma-separated strings. All string comparisons are case-insensitive. Examples: 1) IsSubsetOf('a,B', 'A,B,C') returns nil 2) IsSubsetOf('A,B,C', 'B,C') returns an error because A is not in the 2nd set.

func IsValidAddress

func IsValidAddress(iaddress interface{}) bool

IsValidAddress validate hex address

func IsZeroAddress

func IsZeroAddress(iaddress interface{}) bool

IsZeroAddress validate if it's a 0 address

func ListContains

func ListContains(list, find string) bool

ListContains looks through a comma separated list to see if a string exists

func MakeFileAbs

func MakeFileAbs(file, dir string) (string, error)

MakeFileAbs makes 'file' absolute relative to 'dir' if not already absolute

func MakeFileNamesAbsolute

func MakeFileNamesAbsolute(files []*string, home string) error

MakeFileNamesAbsolute makes all file names in the list absolute, relative to home

func Marshal

func Marshal(from interface{}, what string) ([]byte, error)

Marshal to bytes

func NormalizeFileList

func NormalizeFileList(files []string, homeDir string) ([]string, error)

NormalizeFileList provides absolute pathing for the list of files

func NormalizeStringSlice

func NormalizeStringSlice(slice []string) []string

NormalizeStringSlice checks for seperators

func ParseObj

func ParseObj(obj interface{}, cb func(*Field) error, tags map[string]string) error

ParseObj parses an object structure, calling back with field info for each field

func PublicKeyBytesToAddress

func PublicKeyBytesToAddress(publicKey []byte) common.Address

PublicKeyBytesToAddress ...

func RandomString

func RandomString(n int) string

RandomString returns a random string

func Read

func Read(r io.Reader, data []byte) ([]byte, error)

Read reads from Reader into a byte array

func ReadFile

func ReadFile(file string) ([]byte, error)

ReadFile reads a file

func RegisterFlags

func RegisterFlags(v *viper.Viper, flags *pflag.FlagSet, config interface{},
	tags map[string]string) error

RegisterFlags registers flags for all fields in an arbitrary 'config' object. This method recognizes the following field tags: "def" - the default value of the field; "opt" - the optional one character short name to use on the command line; "help" - the help message to display on the command line; "skip" - to skip the field.

func RemoveQuotes

func RemoveQuotes(str string) string

RemoveQuotes removes outer quotes from a string if necessary

func ReplaceTextFile

func ReplaceTextFile(path, old, new string) error

ReplaceTextFile replace a text in a file

func SigRSV

func SigRSV(isig interface{}) ([32]byte, [32]byte, uint8)

SigRSV signatures R S V returned as arrays

func StrContained

func StrContained(str string, strs []string) bool

StrContained returns true if 'str' is in 'strs'; otherwise return false

func StructToString

func StructToString(si interface{}) string

StructToString converts a struct to a string. If a field has a 'secret' tag, it is masked in the returned string

func ToDecimal

func ToDecimal(ivalue interface{}, decimals int) decimal.Decimal

ToDecimal wei to decimals

func ToWei

func ToWei(iamount interface{}, decimals int) *big.Int

ToWei decimals to wei

func Unmarshal

func Unmarshal(from []byte, to interface{}, what string) error

Unmarshal from bytes

func ValidateAndReturnAbsConf

func ValidateAndReturnAbsConf(configFilePath, homeDir, cmdName string) (string, string, error)

ValidateAndReturnAbsConf checks to see that there are no conflicts between the configuration file path and home directory. If no conflicts, returns back the absolute path for the configuration file and home directory.

func ViperUnmarshal

func ViperUnmarshal(cfg interface{}, stringSliceFields []string, vp *viper.Viper) error

ViperUnmarshal is a work around for a bug in viper.Unmarshal This can be removed once https://github.com/spf13/viper/issues/327 is fixed and vendored.

func WriteFile

func WriteFile(file string, buf []byte, perm os.FileMode) error

WriteFile writes a file

Types

type ECDSASignature

type ECDSASignature struct {
	R, S *big.Int
}

ECDSASignature forms the structure for R and S value for ECDSA

type Field

type Field struct {
	Name  string
	Path  string
	Type  reflect.Type
	Kind  reflect.Kind
	Leaf  bool
	Depth int
	Tag   reflect.StructTag
	Value interface{}
	Addr  interface{}
	Hide  string
}

Field is a field of an arbitrary struct

Jump to

Keyboard shortcuts

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