go icon indicating copy to clipboard operation
go copied to clipboard

encoding/pem: Decode documentation misleading

Open eikenb opened this issue 2 years ago • 2 comments

What is the URL of the page with the issue?

https://pkg.go.dev/encoding/pem

What is your user agent?

Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101 Firefox/91.0

Screenshot

Screenshot_from_2022-06-23_18-32-30

What did you do?

Used pem.Decode() as described.

What did you expect to see?

To have it "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."

What did you see instead?

It only found PEM formatted blocks when preceded by a newline, with no characters on the line before the "-----BEGIN" nor on the line after the end's "-----". It wasn't clear until I read the code that it was line by line with these restrictions. The docs made it sound like it looked for the PEM blocks using bytes.Index(bytestream, "-----BEGIN") and like (what I ended up using locally).

IMO the documentation is misleading here and should be fixed.

Thanks!

eikenb avatar Jun 24 '22 01:06 eikenb

CC @FiloSottile

ianlancetaylor avatar Jun 24 '22 04:06 ianlancetaylor

Change https://go.dev/cl/421636 mentions this issue: encoding/pem: clarify Decode only works on lines

gopherbot avatar Aug 06 '22 13:08 gopherbot