cipher

package
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Apr 1, 2024 License: MIT Imports: 14 Imported by: 1

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func LoadAllCertPool

func LoadAllCertPool(additionalCAFiles []string) (*x509.CertPool, error)

LoadAllCertPool loads system default pool and appends the additional ca certs provided in additionalCAFiles to the pool. The additional ca cert files are expected to be PEM-encoded. Returns the system pool plus the additional.

func LoadCertPoolFromFile

func LoadCertPoolFromFile(file string) (*x509.CertPool, error)

LoadCertPoolFromFile loads certs from the ca file and returns as a new cert pool. The system cert pool is not loaded and caBytes should be PEM-encoded.

func LoadCertPoolFromPEM

func LoadCertPoolFromPEM(caBytes []byte) (*x509.CertPool, error)

LoadCertPoolFromPEM loads certs from the ca certificate and returns as a new cert pool. The system cert pool is not loaded and caBytes should be PEM-encoded.

func LoadCertificateFromFile

func LoadCertificateFromFile(file string) (*tls.Certificate, error)

LoadCertificateFromFile loads a single PEM-encoded cert from the file.

func LoadKeyAndCertificate

func LoadKeyAndCertificate(keyBytes []byte, certBytes []byte) (*tls.Certificate, error)

LoadKeyAndCertificate combines a tls.Certificate using the given cert and key binary data.

func LoadKeyAndCertificateFromFile

func LoadKeyAndCertificateFromFile(keyPath, certPath string) (*tls.Certificate, error)

LoadKeyAndCertificateFromFile loads key and cert for a single pair.

func LoadKeyFromFile

func LoadKeyFromFile(file string) (crypto.PrivateKey, error)

LoadKeyFromFile loads a single PMM-encoded private key from the file.

func UnmarshalCert

func UnmarshalCert(certBytes []byte) (*tls.Certificate, error)

UnmarshalCert unmarshal binary data to a tls.Certificate.

func UnmarshalPemKey

func UnmarshalPemKey(keyBytes []byte) (crypto.PrivateKey, error)

UnmarshalPemKey unmarshal binary data to a crypto.PrivateKey

Types

type Descriptor

type Descriptor struct {
	Name string            //file name
	Info *x509.Certificate //basic input info

	EncodeType  EncodeType
	CertEncoded []byte
	KeyEncoded  []byte
}

Descriptor defines

type EncodeType

type EncodeType = int
const (
	EncodeDER EncodeType = iota
	EncodePEM
)

type SelfSigner

type SelfSigner struct {
	// contains filtered or unexported fields
}

func NewSelfSigner

func NewSelfSigner() *SelfSigner

func (*SelfSigner) CACert

func (g *SelfSigner) CACert() []byte

CACert returns the PEM-encoded ca certificate data.

func (*SelfSigner) CAPrivateKey

func (g *SelfSigner) CAPrivateKey() []byte

CAPrivateKey returns the PEM-encoded ca private key data.

func (*SelfSigner) CreateSelfSigned

func (g *SelfSigner) CreateSelfSigned(info *x509.Certificate) (cert, key []byte, err error)

CreateSelfSigned creates a certificate based on the given input. The following fields input are extracted:

	NotBefore - mandatory
	NotAfter  - mandatory
	Subject   - mandatory
	IPAddresses - optional
	EmailAddresses - optional
 DNSNames - optional

func (*SelfSigner) CreateSelfSignedCertificates

func (g *SelfSigner) CreateSelfSignedCertificates(descriptors []*Descriptor) (error, int)

CreateSelfSignedCertificates creates and signs certificates according to the given descriptors and returns number of certificates successfully generated.

func (*SelfSigner) GenerateCA

func (g *SelfSigner) GenerateCA(info *x509.Certificate) error

GenerateCA creates a deterministic certificate authority. The following fields input are extracted:

NotBefore - mandatory
NotAfter  - mandatory
Subject   - mandatory
IPAddresses - optional
EmailAddresses - optional

func (*SelfSigner) LoadCAFromBuf

func (g *SelfSigner) LoadCAFromBuf(certPEM, keyPEM []byte) error

LoadCAFromBuf loads certificate and private key data from the given slices. Note that both are required to be PEM-encoded.

func (*SelfSigner) LoadCAFromFiles

func (g *SelfSigner) LoadCAFromFiles(certFile, keyFile string) error

LoadCAFromFiles loads certificate and private key data from the given file path. Note that both are required to be PEM-encoded.

func (*SelfSigner) UseAlgorithm

func (g *SelfSigner) UseAlgorithm(alg elliptic.Curve)

func (*SelfSigner) UseRandProvider

func (g *SelfSigner) UseRandProvider(rand io.Reader)

func (*SelfSigner) UseSerialNumberGenerator

func (g *SelfSigner) UseSerialNumberGenerator(gen SerialNumberGenerator)

func (*SelfSigner) WriteCACertFiles

func (g *SelfSigner) WriteCACertFiles(file string) error

func (*SelfSigner) WriteFiles

func (g *SelfSigner) WriteFiles(descriptors []*Descriptor) error

type SerialNumberGenerator

type SerialNumberGenerator interface {
	Generate() (*big.Int, error)
}

Jump to

Keyboard shortcuts

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