mirror of
https://github.com/golang/go
synced 2024-11-19 20:54:39 -07:00
encoding/pem: add Encode, EncodeToMemory docs
Included in a warning that EncodeToMemory may return an incomplete PEM encoded structure if invalid headers are supplied. Example: pem.EncodeToMemory(&pem.Block{ Headers: map[string]string{ "a": "test1", "b:c": "test2", }, }) Returns: -----BEGIN ----- a: test1 Change-Id: Ia9cf0202f985e3cf210aabb6f07667e581ff081f Reviewed-on: https://go-review.googlesource.com/77790 Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
This commit is contained in:
parent
8cdd999bf5
commit
f4f6018d38
@ -252,6 +252,7 @@ func writeHeader(out io.Writer, k, v string) error {
|
||||
return err
|
||||
}
|
||||
|
||||
// Encode writes the Block b to out.
|
||||
func Encode(out io.Writer, b *Block) error {
|
||||
if _, err := out.Write(pemStart[1:]); err != nil {
|
||||
return err
|
||||
@ -310,6 +311,10 @@ func Encode(out io.Writer, b *Block) error {
|
||||
return err
|
||||
}
|
||||
|
||||
// EncodeToMemory returns the Block b.
|
||||
//
|
||||
// EncodeToMemory will return an incomplete PEM encoded structure if an invalid block is given.
|
||||
// To catch errors, Blocks with user-supplied headers should use Encode.
|
||||
func EncodeToMemory(b *Block) []byte {
|
||||
var buf bytes.Buffer
|
||||
Encode(&buf, b)
|
||||
|
Loading…
Reference in New Issue
Block a user