util

package
v0.0.0-...-a91455d Latest Latest
Warning

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

Go to latest
Published: Apr 3, 2019 License: Apache-2.0 Imports: 36 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"
)

Variables

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

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

Functions

func CCCSPBackedSigner

func CCCSPBackedSigner(caFile, keyFile string, policy *config.Signing, csp cccsp.CCCSP) (signer.Signer, error)

CCCSPBackedSigner attempts to create a signer using csp cccsp.CCCSP.

func CCCSPKeyRequestGenerate

func CCCSPKeyRequestGenerate(req *csr.CertificateRequest, csp cccsp.CCCSP) (cccsp.Key, crypto.Signer, error)

CCCSPKeyRequestGenerate generates keys through CCCSP somewhat mirroring to cfssl/req.KeyRequest.Generate()

func CreateToken

func CreateToken(csp cccsp.CCCSP, cert []byte, key cccsp.Key, method, uri string, body []byte) (string, error)

CreateToken creates a JWT-like token.

func Fatal

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

Fatal logs fatal message and exists

func FileExists

func FileExists(name string) bool

FileExists checks to see if a file exists.

func GenECDSAToken

func GenECDSAToken(csp cccsp.CCCSP, cert []byte, key cccsp.Key, method, uri string, body []byte) (string, error)

GenECDSAToken signs the http body and cert with ECDSA using EC private key

func GetECPrivateKey

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

GetECPrivateKey get *ecdsa.PrivateKey from key pem

func GetEnrollmentIDFromPEM

func GetEnrollmentIDFromPEM(cert []byte) (string, error)

GetEnrollmentIDFromPEM returns the EnrollmentID from a PEM buffer

func GetEnrollmentIDFromX509Certificate

func GetEnrollmentIDFromX509Certificate(cert *x509.Certificate) string

GetEnrollmentIDFromX509Certificate returns the EnrollmentID from the x509 certificate

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 GetSignerFromCert

func GetSignerFromCert(cert *x509.Certificate, csp cccsp.CCCSP) (cccsp.Key, crypto.Signer, error)

GetSignerFromCert load private key represented by ski and return cccsp signer that conforms to crypto.Signer

func GetSignerFromCertFile

func GetSignerFromCertFile(certFile string, csp cccsp.CCCSP) (cccsp.Key, crypto.Signer, *x509.Certificate, error)

GetSignerFromCertFile load skifile and load private key represented by ski and return cccsp signer that conforms to crypto.Signer

func GetX509CertificateFromPEM

func GetX509CertificateFromPEM(cert []byte) (*x509.Certificate, error)

GetX509CertificateFromPEM get on x509 certificate from bytes in PEM format

func ImportCCCSPKeyFromPEM

func ImportCCCSPKeyFromPEM(keyFile string, csp cccsp.CCCSP, temporary bool) (cccsp.Key, error)

ImportCCCSPKeyFromPEM attempts to create a private CCCSP key from a pem file keyFile

func InitCCCSP

func InitCCCSP(path string) (cccsp.CCCSP, error)

InitCCCSP initializes CCCSP

func LoadX509KeyPair

func LoadX509KeyPair(certFile, keyFile string, csp cccsp.CCCSP) (*tls.Certificate, error)

LoadX509KeyPair reads and parses a public/private key pair from a pair of files.

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 NormalizeStringSlice

func NormalizeStringSlice(slice []string) []string

NormalizeStringSlice checks for seperators

func ParseObject

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

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

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 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 Unmarshal

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

Unmarshal from bytes

func WriteFile

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

WriteFile writes a file

Types

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