Documentation ¶
Overview ¶
Package pemfile contains functions for reading/writing common PKI objects from/to PEM-encoded files.
Index ¶
- Variables
- func IsType(block *pem.Block, want ...string) error
- func ReadBlock(filename string) (*pem.Block, error)
- func ReadBlocks(filename string) ([]*pem.Block, error)
- func ReadCSR(filename string) (*x509.CertificateRequest, error)
- func ReadCert(filename string) (*x509.Certificate, error)
- func ReadCerts(filename string) ([]*x509.Certificate, error)
- func ReadPrivateKey(filename string) (interface{}, error)
- func ReadPrivateKeyWithPasswordFunc(filename string, pwfunc func(string, string) ([]byte, error)) (interface{}, error)
- func ReadPublicKey(filename string) (interface{}, error)
- func WriteBlock(w io.Writer, block *pem.Block) error
- func WriteBlocks(w io.Writer, blocks []*pem.Block) error
- func WriteCSR(w io.Writer, csr *x509.CertificateRequest) error
- func WriteCert(w io.Writer, cert *x509.Certificate) error
- func WriteCerts(w io.Writer, certs []*x509.Certificate) error
Constants ¶
This section is empty.
Variables ¶
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 ReadBlock ¶
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 ¶
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 ¶
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 ¶
ReadPublicKey reads a single public key. PKCS1 RSA RSA public keys, and PKIX RSA and EC public keys are supported.
func WriteBlock ¶
WriteBlock writes a PEM block.
func WriteBlocks ¶
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.