util

package
v0.0.0-...-b80afe7 Latest Latest
Warning

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

Go to latest
Published: Mar 1, 2022 License: Apache-2.0 Imports: 19 Imported by: 0

Documentation

Overview

Package util provides generic utility functions.

Index

Constants

This section is empty.

Variables

View Source
var ErrInvalidPublicKey = goerrors.New("invalid public key")

ErrInvalidPublicKey is raised when the public key type is unknown/unsupported.

View Source
var ErrInvalidSubjectAltName = goerrors.New("invalid subject alt name")

ErrInvalidSubjectAltName is raised when an unsupported SAN is specified.

View Source
var ErrTimeout = errors.New("process timed out")

ErrTimeout is raised when a wait doesn't terminate in time.

Functions

func DecodeCertificate

func DecodeCertificate(certPEM []byte) (*x509.Certificate, error)

DecodeCertificate accepts an parses a PEM formatted certificate.

func DecodePrivateKey

func DecodePrivateKey(keyPEM []byte) (crypto.PrivateKey, error)

DecodePrivateKey accepts a PEM formatted private key and parses it.

func GenerateCertificate

func GenerateCertificate(keyPEM []byte, cn string, lifetime time.Duration, usage CertificateUsage, sans []string, caKeyPEM, caCertPEM []byte) ([]byte, error)

GenerateCertificate generates and signs an X.509 certificate.

func GenerateKey

func GenerateKey(keyType KeyType, encoding KeyEncodingType, bits *int) ([]byte, error)

GenerateKey creates a PEM encoded private key. The bits parameter is required for RSA keys.

func MustWaitFor

func MustWaitFor(t *testing.T, f WaitFunc, timeout time.Duration)

MustWaitFor waits until a condition is nil.

func WaitFor

func WaitFor(f WaitFunc, timeout time.Duration) error

WaitFor waits until a condition is nil.

Types

type CertificateUsage

type CertificateUsage string

CertificateUsage defines the certificate use.

const (
	// CA is used for signing certificates and providing a trust anchor.
	CA CertificateUsage = "CA"

	// Server is used for server certificates.
	Server CertificateUsage = "Server"

	// Client is used for client certificates.
	Client CertificateUsage = "Client"
)

type KeyEncodingType

type KeyEncodingType string

KeyEncodingType is a private key encoding type.

const (
	// KeyEncodingPKCS1 may only be used with the RSA key type.
	KeyEncodingPKCS1 KeyEncodingType = "PKCS#1"

	// KeyEncodingPKCS8 may be used for any key type.
	KeyEncodingPKCS8 KeyEncodingType = "PKCS#8"

	// KeyEncodingSEC1 may only be used with EC key types.
	KeyEncodingSEC1 KeyEncodingType = "SEC 1"
)

type KeyType

type KeyType string

KeyType is a private key type.

const (
	// RSA is widely supported, but the key sizes are large.
	KeyTypeRSA KeyType = "RSA"

	// KeyTypeEllipticP224 generates small keys relative to encryption strength.
	KeyTypeEllipticP224 KeyType = "EllipticP224"

	// KeyTypeEllipticP256 generates small keys relative to encryption strength.
	KeyTypeEllipticP256 KeyType = "EllipticP256"

	// KeyTypeEllipticP384 generates small keys relative to encryption strength.
	KeyTypeEllipticP384 KeyType = "EllipticP384"

	// KeyTypeEllipticP521 generates small keys relative to encryption strength.
	KeyTypeEllipticP521 KeyType = "EllipticP521"

	// KeyTypeED25519 generates small keys relative to encrption strength.
	KeyTypeED25519 KeyType = "ED25519"
)

type WaitFunc

type WaitFunc func() error

WaitFunc is a callback that stops a wait when nil.

Jump to

Keyboard shortcuts

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