type Block … // 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, rest []byte) { … } // 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 { … } var pemStart … var pemEnd … var pemEndOfLine … var colon … // 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) { … } const pemLineLength … type lineBreaker … var nl … func (l *lineBreaker) Write(b []byte) (n int, err error) { … } func (l *lineBreaker) Close() (err error) { … } func writeHeader(out io.Writer, k, v string) error { … } // Encode writes the PEM encoding of b to out. func Encode(out io.Writer, b *Block) error { … } // 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 { … }