go
go copied to clipboard
encoding/pem: Decode documentation misleading
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
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!
CC @FiloSottile
Change https://go.dev/cl/421636 mentions this issue: encoding/pem: clarify Decode only works on lines