Documentation
¶
Overview ¶
Package certs provides helpful methods for generating test certificates.
Index ¶
- func New(cfg ...Config) (*x509.Certificate, crypto.Signer, error)
- func NewDER(cfg ...Config) (certificate []byte, key []byte, err error)
- func NewPEM(cfg ...Config) (certificate []byte, key []byte, err error)
- func TNew(t *testing.T, cfg ...Config) (*x509.Certificate, crypto.Signer)
- func TNewDER(t *testing.T, cfg ...Config) (certificate []byte, key []byte)
- func TNewPEM(t *testing.T, cfg ...Config) (certificate []byte, key []byte)
- type Config
- type KeyType
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func New ¶
New generates a certificate and private key. To override default values, pass a Config value.
func NewDER ¶
NewDER generates a certificate and private key in DER format. To override default values, pass a Config value.
func NewPEM ¶
NewPEM generates a certificate and private key in PEM format. To override default values, pass a Config value.
func TNew ¶
TNew generates a certificate and private key. To override default values, pass a Config value. If an error occurs, t.Error is called.
Types ¶
type Config ¶
type Config struct {
// CertPath specifies where to store the certificate. An empty string
// disables output. Files are PEM-encoded for New and NewPEM and DER-encoded
// for NewDER.
CertPath string
// CertPath specifies where to store the key. An empty string disables
// output. Files are PEM-encoded for New and NewPEM and DER-encoded for
// NewDER. Key files are unencrypted.
KeyPath string
// CACert specifies the CA certificate that signs the generated cert. Pass
// nil to create a self-signed certificate.
CACert *x509.Certificate
// CAKey specifies the CA key that signs the generated cert. Pass nil to
// create a self-signed certificate.
CAKey crypto.Signer
// DN is the distinguished name of the certificate. If nil, a DN is
// generated of the form 'CN=<random number>'.
DN *pkix.Name
// Expiry is the expiry time of the certificate. If zero, the expiry is set
// one year in the future.
Expiry time.Time
// SerialNumber specifies the certificate serial. If nil, a random
// SerialNumber is generated.
SerialNumber *big.Int
// KeyType indicates the type of key to generate.
KeyType KeyType
// KeySize indicates the size of the key to generate for RSA keys. If zero,
// RSA keys will be 2048 bits long.
RSAKeySize int
// Curve indicates the type of ECDSA key to generate. If nil, a P256 curve
// is used.
Curve elliptic.Curve
// IsCA indicates whether to set CA flags on the certificate.
IsCA bool
// Algorithm specifies the signature algorithm to use. If zero,
// SHA256WithRSA or ECDSAWithSHA256 is used (according to the issuing key
// type).
Algorithm x509.SignatureAlgorithm
// contains filtered or unexported fields
}
Config can be provided to override the default values. The default values used are equivalent to a zero Config value (e.g. Config{}).