datarhei / gosrt

Implementation of the SRT protocol in pure Go
https://datarhei.com
MIT License
114 stars 17 forks source link

remove redundant check in crypto #25

Closed aler9 closed 1 year ago

aler9 commented 1 year ago

Hello, rand.Read() is based on io.ReadFull, which already returns an error when n != len(p):

https://cs.opensource.google/go/go/+/refs/tags/go1.20.6:src/crypto/rand/rand.go;l=24

https://cs.opensource.google/go/go/+/refs/tags/go1.20.6:src/io/io.go;l=351

Furthermore, this is also written into the documentation:

Read is a helper function that calls Reader.Read using io.ReadFull. On return, n == len(b) if and only if err == nil.

Therefore, checking n != len(p) after rand.Read() is useless.