pem

Imports

Imports #

"bytes"
"encoding/base64"
"errors"
"io"
"slices"
"strings"

Constants & Variables

colon var #

var colon = *ast.CallExpr

nl var #

var nl = []byte{...}

pemEnd var #

var pemEnd = *ast.CallExpr

pemEndOfLine var #

var pemEndOfLine = *ast.CallExpr

pemLineLength const #

const pemLineLength = 64

pemStart var #

var pemStart = *ast.CallExpr

Structs

Block struct #

A Block represents a PEM encoded structure. The encoded form is: -----BEGIN Type----- Headers base64-encoded Bytes -----END Type----- where [Block.Headers] is a possibly empty sequence of Key: Value lines.

type Block struct {
Type string
Headers map[string]string
Bytes []byte
}

lineBreaker struct #

type lineBreaker struct {
line [pemLineLength]byte
used int
out io.Writer
}

Functions

Close method #

func (l *lineBreaker) Close() (err error)

Decode function #

Decode will find the next PEM formatted block (certificate, private key etc) in the input. It returns that block and the remainder of the input. If no PEM data is found, p is nil and the whole of the input is returned in rest.

func Decode(data []byte) (p *Block, rest []byte)

Encode function #

Encode writes the PEM encoding of b to out.

func Encode(out io.Writer, b *Block) error

EncodeToMemory function #

EncodeToMemory returns the PEM encoding of b. If b has invalid headers and cannot be encoded, EncodeToMemory returns nil. If it is important to report details about this error case, use [Encode] instead.

func EncodeToMemory(b *Block) []byte

Write method #

func (l *lineBreaker) Write(b []byte) (n int, err error)

getLine function #

getLine results the first \r\n or \n delineated line from the given byte array. The line does not include trailing whitespace or the trailing new line bytes. The remainder of the byte array (also not including the new line bytes) is also returned and this will always be smaller than the original argument.

func getLine(data []byte) (line []byte, rest []byte)

removeSpacesAndTabs function #

removeSpacesAndTabs returns a copy of its input with all spaces and tabs removed, if there were any. Otherwise, the input is returned unchanged. The base64 decoder already skips newline characters, so we don't need to filter them out here.

func removeSpacesAndTabs(data []byte) []byte

writeHeader function #

func writeHeader(out io.Writer, k string, v string) error

Generated with Arrow