pemfile

package module
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Apr 2, 2020 License: MIT Imports: 9 Imported by: 0

README

pemfile

GoDoc

Package pemfile contains functions for reading/writing common PKI objects from/to PEM-encoded files.

Install

go get -u github.com/paulgriffiths/pemfile

License

Copyright (c) 2020-present Paul Griffiths

Licensed under MIT License

Documentation

Overview

Package pemfile contains functions for reading/writing common PKI objects from/to PEM-encoded files.

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrNotFound indicates that no PEM block was found at the beginning of
	// a file.
	ErrNotFound = errors.New("no PEM block found in file")

	// ErrTrailingData indicates that a file contains trailing data after one
	// or more PEM blocks.
	ErrTrailingData = errors.New("trailing data in file")
)

Functions

func IsType

func IsType(block *pem.Block, want ...string) error

IsType returns an error if the type of a PEM block is not one of the provided values.

func ReadBlock

func ReadBlock(filename string) (*pem.Block, error)

ReadBlock reads a PEM block from a file. An error is returned if the file is empty, or if it contains any data other than a single PEM block.

func ReadBlocks

func ReadBlocks(filename string) ([]*pem.Block, error)

ReadBlocks reads a slice of PEM blocks from a file. An error is returned if the file is empty, or if it contains any data other than a sequence of PEM blocks.

func ReadCSR

func ReadCSR(filename string) (*x509.CertificateRequest, error)

ReadCSR reads a single PKCS#10 certificate signing request.

func ReadCert

func ReadCert(filename string) (*x509.Certificate, error)

ReadCert reads an X.509 certificate.

func ReadCerts

func ReadCerts(filename string) ([]*x509.Certificate, error)

ReadCerts reads one or more X.509 certificates.

func ReadPrivateKey

func ReadPrivateKey(filename string) (interface{}, error)

ReadPrivateKey reads a single private key. PKCS1 RSA private keys, SEC1 EC private keys, and PKCS8 RSA and EC private keys are supported.

func ReadPrivateKeyWithPasswordFunc

func ReadPrivateKeyWithPasswordFunc(filename string, pwfunc func(string, string) ([]byte, error)) (interface{}, error)

ReadPrivateKeyWithPasswordFunc reads a single private key which may be in an encrypted PEM block. If it is, decryption is attemped with a password returned by the provided function. The two arguments to the function are a description of the type of credential (e.g. "password", "PIN") and a description of the target of the credential (e.g. "private key", "HSM"). The function should return an error if the credential cannot be retrieved. If pwfunc is nil and the PEM block is encrypted, a password will be requested from the terminal.

func ReadPublicKey

func ReadPublicKey(filename string) (interface{}, error)

ReadPublicKey reads a single public key. PKCS1 RSA RSA public keys, and PKIX RSA and EC public keys are supported.

func WriteBlock

func WriteBlock(w io.Writer, block *pem.Block) error

WriteBlock writes a PEM block.

func WriteBlocks

func WriteBlocks(w io.Writer, blocks []*pem.Block) error

WriteBlocks writes a slice of PEM blocks.

func WriteCSR

func WriteCSR(w io.Writer, csr *x509.CertificateRequest) error

WriteCSR writes a PKCS#10 certificate signing request.

func WriteCert

func WriteCert(w io.Writer, cert *x509.Certificate) error

WriteCert writes an X.509 certificate.

func WriteCerts

func WriteCerts(w io.Writer, certs []*x509.Certificate) error

WriteCerts writes one or more X.509 certificates.

Types

This section is empty.

Jump to

Keyboard shortcuts

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