utils

package
v0.0.0-...-041bb98 Latest Latest
Warning

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

Go to latest
Published: May 14, 2017 License: MIT Imports: 23 Imported by: 0

Documentation

Index

Constants

View Source
const PemDefaultCipher = x509.PEMCipherAES256

Variables

View Source
var CurrentLogLevel = WARNING
View Source
var InvalidRsaBits = errors.New("Invalid RSA bits (must be in range 2048..4096)")
View Source
var UnknownCurve = errors.New("Unknown Curve")
View Source
var UnknownKeyType = errors.New("Unknown Key Type")
View Source
var UnknownPrivateKey = errors.New("Unknown Private Key")

Functions

func AddLogFlags

func AddLogFlags(flagset *flag.FlagSet)

func Base64UrlDecode

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

also adds missing padding

func Base64UrlEncode

func Base64UrlEncode(data []byte) string

also removes padding

func CertificateToPem

func CertificateToPem(cert *x509.Certificate) *pem.Block

func CreateEcdsaPrivateKey

func CreateEcdsaPrivateKey(curve elliptic.Curve) (*ecdsa.PrivateKey, error)

func CreatePrivateKey

func CreatePrivateKey(keyType KeyType, curve Curve, rsaBits *int) (interface{}, error)

func CreateRsaPrivateKey

func CreateRsaPrivateKey(bits int) (*rsa.PrivateKey, error)

func DebugLogHttpRequest

func DebugLogHttpRequest(req *HttpRequest, hReq *http.Request)

func DebugLogHttpResponse

func DebugLogHttpResponse(resp *HttpResponse)

fetch response data (if you're intrested in it) before calling this, and pass it along

func Debugf

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

func DecodePrivateKey

func DecodePrivateKey(block pem.Block) (interface{}, error)

func DecodePublicKey

func DecodePublicKey(block pem.Block) (interface{}, error)

func DecryptPemBlock

func DecryptPemBlock(block *pem.Block, prompt func() (string, error)) (err error)

func EncodePrivateKey

func EncodePrivateKey(privateKey interface{}) (*pem.Block, error)

func EncodePublicKey

func EncodePublicKey(publicKey interface{}) (*pem.Block, error)

func EncryptPemBlock

func EncryptPemBlock(block *pem.Block, password string, alg x509.PEMCipher) error

func EncryptPrivateKey

func EncryptPrivateKey(privateKey interface{}, password string, alg x509.PEMCipher) (*pem.Block, error)

func Errorf

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

func Fatalf

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

func FirstPemBlock

func FirstPemBlock(r io.Reader, types ...string) (*pem.Block, error)

func FormatDuration

func FormatDuration(duration time.Duration) string

func Infof

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

func IsValidHex

func IsValidHex(s string) bool

func LoadFirstPrivateKey

func LoadFirstPrivateKey(r io.Reader, prompt func() (string, error)) (interface{}, error)

func LoadFirstPublicKey

func LoadFirstPublicKey(r io.Reader, prompt func() (string, error)) (interface{}, error)

func LoadPemBlocks

func LoadPemBlocks(r io.Reader, prompt func() (string, error)) ([]*pem.Block, error)

func MakeCertificate

func MakeCertificate(parameters CertificateParameters) (*pem.Block, error)

func MakeCertificateRequest

func MakeCertificateRequest(parameters CertificateRequestParameters) (*pem.Block, error)

func MakeSerialNumber

func MakeSerialNumber() (*big.Int, error)

func MustBase64UrlDecode

func MustBase64UrlDecode(s string) []byte

also adds missing padding

func MustEncodeJson

func MustEncodeJson(v interface{}) []byte

func MustHexDecode

func MustHexDecode(s string) []byte

func MustPrettyEncodeJson

func MustPrettyEncodeJson(v interface{}) []byte

func MustPublicKey

func MustPublicKey(privateKey interface{}) interface{}

func PickSignatureAlgorithm

func PickSignatureAlgorithm(privateKey interface{}, defaultAlg x509.SignatureAlgorithm) x509.SignatureAlgorithm

func PublicKey

func PublicKey(privateKey interface{}) (pubKey interface{}, err error)

func Warningf

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

Types

type CertificateParameters

type CertificateParameters struct {
	SigningKey                interface{}
	ParentCertificate         *x509.Certificate
	PublicKey                 interface{}
	DefaultSignatureAlgorithm x509.SignatureAlgorithm
	Subject                   pkix.Name
	Duration                  time.Duration
	DNSNames                  []string
	SerialNumber              *big.Int
}

type CertificateRequestParameters

type CertificateRequestParameters struct {
	PrivateKey                interface{}
	DefaultSignatureAlgorithm x509.SignatureAlgorithm
	Subject                   pkix.Name
	DNSNames                  []string
}

type Curve

type Curve string
const (
	CurveP256 Curve = "P-256"
	CurveP384 Curve = "P-384"
	CurveP521 Curve = "P-521"
)

func (Curve) IsValid

func (curve Curve) IsValid() bool

func (*Curve) Set

func (curve *Curve) Set(v string) error

func (*Curve) String

func (curve *Curve) String() string
type HttpLink struct {
	URL        string
	Properties map[string]string
}

type HttpRequest

type HttpRequest struct {
	Method  string
	URL     string
	Body    []byte
	Headers HttpRequestHeader
}

func (*HttpRequest) Run

func (req *HttpRequest) Run() (*HttpResponse, error)

type HttpRequestHeader

type HttpRequestHeader struct {
	ContentType string
	Accept      string
}

type HttpResponse

type HttpResponse struct {
	RawResponse *http.Response
	Body        []byte
	StatusCode  int
	Status      string
	Location    string
	ContentType string
	Links       map[string]HttpLink
}

type KeyType

type KeyType string
const (
	KeyEcdsa KeyType = "ECDSA"
	KeyRSA   KeyType = "RSA"
)

func (KeyType) IsValid

func (keyType KeyType) IsValid() bool

func (*KeyType) Set

func (keyType *KeyType) Set(v string) error

func (*KeyType) String

func (keyType *KeyType) String() string

type LogLevel

type LogLevel int
const (
	DEBUG   LogLevel = iota
	INFO    LogLevel = iota
	WARNING LogLevel = iota
	ERROR   LogLevel = iota
)

Jump to

Keyboard shortcuts

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