mirror of
https://github.com/labstack/echo.git
synced 2025-07-15 01:34:53 +02:00
@ -74,6 +74,12 @@ func randomString(length uint8) string {
|
|||||||
r := make([]byte, length+(length/4)) // perf: avoid read from rand.Reader many times
|
r := make([]byte, length+(length/4)) // perf: avoid read from rand.Reader many times
|
||||||
var i uint8 = 0
|
var i uint8 = 0
|
||||||
|
|
||||||
|
// security note:
|
||||||
|
// we can't just simply do b[i]=randomStringCharset[rb%len(randomStringCharset)],
|
||||||
|
// len(len(randomStringCharset)) is 52, and rb is [0, 255], 256 = 52 * 4 + 48.
|
||||||
|
// make the first 48 characters more possibly to be generated then others.
|
||||||
|
// So we have to skip bytes when rb > randomStringMaxByte
|
||||||
|
|
||||||
for {
|
for {
|
||||||
_, err := io.ReadFull(reader, r)
|
_, err := io.ReadFull(reader, r)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
Reference in New Issue
Block a user