tlstest

package
v0.2.1 Latest Latest
Warning

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

Go to latest
Published: Oct 30, 2026 License: MIT Imports: 14 Imported by: 0

Documentation

Overview

Package tlstest issues throwaway certificates for tests: an in-memory CA and the leaves it signs, written as PEM files the way an operator deploys them. Nothing here is meant for production use.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func WriteFile

func WriteFile(t testing.TB, path string, data []byte)

WriteFile replaces path atomically: it writes a sibling file and renames it over path, the way certificate tooling rotates files in place.

Types

type CA

type CA struct {
	Cert *x509.Certificate
	// Pool trusts only this CA.
	Pool *x509.CertPool
	// PEM is the CA certificate, PEM encoded.
	PEM []byte
	// contains filtered or unexported fields
}

CA is a private certificate authority held in memory.

func NewCA

func NewCA(t testing.TB, name string) *CA

NewCA creates a CA named name.

func (*CA) Issue

func (ca *CA) Issue(t testing.TB, commonName string, usages ...x509.ExtKeyUsage) Leaf

Issue signs a leaf named commonName for localhost, 127.0.0.1 and ::1. With no usages it is valid for both server and client authentication.

type Leaf

type Leaf struct {
	Cert    *x509.Certificate
	CertPEM []byte
	KeyPEM  []byte
}

Leaf is a certificate the CA signed, with its private key.

func (Leaf) Write

func (l Leaf) Write(t testing.TB, dir string) (certFile, keyFile string)

Write stores the leaf as dir/tls.crt and dir/tls.key and returns both paths.

Jump to

Keyboard shortcuts

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